Skip to the content.

Go to Top Page

Introduction

How to build an eapp with musl libc

1. Setup musl C compiler for RISC-V

curl -S https://more.musl.cc/10.2.1/x86_64-linux-musl/riscv64-linux-musl-cross.tgz
tar -zxf riscv64-linux-musl-cross.tgz

2. Configure keystone-sdk repository to use the musl toolchains

diff --git a/macros.cmake b/macros.cmake
index 34a53cd..a29a05f 100644
--- a/macros.cmake
+++ b/macros.cmake
@@ -7,7 +7,8 @@ macro(global_set Name Value)
 endmacro()
 
 macro(use_riscv_toolchain bits)
-  set(cross_compile riscv${bits}-unknown-linux-gnu-)
+  #set(cross_compile riscv${bits}-unknown-linux-gnu-)
+  set(cross_compile <riscv64-linux-musl-cross>/bin/riscv64-linux-musl-)
   execute_process(
     COMMAND which ${cross_compile}gcc
     OUTPUT_VARIABLE CROSSCOMPILE

3. Configure eapp compile settings

diff --git a/macros.cmake b/macros.cmake
index 34a53cd..a29a05f 100644
--- a/macros.cmake
+++ b/macros.cmake
@@ -28,7 +29,7 @@ macro(use_riscv_toolchain bits)
   set(AR              ${CROSSCOMPILE}ar)
   set(OBJCOPY         ${CROSSCOMPILE}objcopy)
   set(OBJDUMP         ${CROSSCOMPILE}objdump)
-  set(CFLAGS          "-Wall -Werror")
+  set(CFLAGS          "-Wall -Werror -static")
 
   global_set(CMAKE_C_COMPILER        ${CC}${EXT})
   global_set(CMAKE_ASM_COMPILER        ${CC}${EXT})
diff --git a/examples/hello/CMakeLists.txt b/examples/hello/CMakeLists.txt
index 9f5ee48..9e4c1b8 100644
--- a/examples/hello/CMakeLists.txt
+++ b/examples/hello/CMakeLists.txt
@@ -19,7 +19,7 @@ target_link_libraries(${eapp_bin} "-static")
 # host
 
 add_executable(${host_bin} ${host_src})
-target_link_libraries(${host_bin} ${KEYSTONE_LIB_HOST} ${KEYSTONE_LIB_EDGE})
+target_link_libraries(${host_bin} ${KEYSTONE_LIB_HOST} ${KEYSTONE_LIB_EDGE} "-static")
 
 # add target for Eyrie runtime (see keystone.cmake)
diff --git a/examples/tests/CMakeLists.txt b/examples/tests/CMakeLists.txt
index 837013f..3b22e8d 100644
--- a/examples/tests/CMakeLists.txt
+++ b/examples/tests/CMakeLists.txt
@@ -98,7 +98,7 @@ set_target_properties(${all_test_bins}
 # host
 
 add_executable(${host_bin} ${host_src})
-target_link_libraries(${host_bin} ${KEYSTONE_LIB_HOST} ${KEYSTONE_LIB_EDGE} ${KEYSTONE_LIB_VERIFIER})
+target_link_libraries(${host_bin} ${KEYSTONE_LIB_HOST} ${KEYSTONE_LIB_EDGE} ${KEYSTONE_LIB_VERIFIER} "-static")
 
 # add target for Eyrie runtime (see keystone.cmake)

4. Build keystone-sdk and examples

cd `keystone-sdk`
mkdir build
cd build
export KEYSTONE_SDK_DIR=<install_directory>
cmake ..
make
make install
make examples

5. Run the hello example