keystone-enclave / keystone-sdk

SDK for Keystone Enclave - ABI/SBI libraries and sample apps
Other
44 stars 22 forks source link

Doubt regarding making changes to the CMakeLists.txt file. #81

Closed ESaiDheeraj closed 2 years ago

ESaiDheeraj commented 2 years ago

I want to add some code on top of hello-native example. Basically I have 3 files - rsa.c, bignum.c and types.h. I want to use the functions from these 3 files and use them in the eapp_native.c file and host_native.cpp file. I included "types.h" as #include file in both eapp/eapp_native.c and host/host_native.cpp. And then Inorder to include rsa.c and bignum.c, I added both these files to /eapp and /host directories and then made changes to CMakeLists.txt file. The first 4 lines of CMakeLists.txt look like this before I made the changes

set(eapp_bin hello-native) 
set(eapp_src eapp/eapp_native.c) 
set(host_bin hello-native-runner) 
set(host_src host/host_native.cpp)

I changed the 2nd and 4th lines, they now look like

set(eapp_bin hello-native)
set(eapp_src eapp/eapp_native.c eapp/rsa.c eapp/bignum.c)
set(host_bin hello-native-runner)
set(host_src host/host_native.cpp host/rsa.c host/bignum.c)

When I tried running the code, I am still getting some errors. My Question is - What more changes should I make in the CMakeLists.txt to get this running without any errors?

ESaiDheeraj commented 2 years ago

This is how the error looks like,

.........
[ 26%] Building C object examples/hello-native/CMakeFiles/hello-native-runner.dir/host/bignum.c.o
cd /home/saidheeraj/keystone/build-directory/examples/hello-native && /home/saidheeraj/keystone/riscv64/bin/riscv64-unknown-linux-gnu-gcc  -I/home/saidheeraj/keystone/sdk/build64/include -I/home/saidheeraj/keystone/sdk/build64/include/host -I/home/saidheeraj/keystone/sdk/build64/include/edge  -Wall -Werror   -o CMakeFiles/hello-native-runner.dir/host/bignum.c.o   -c /home/saidheeraj/keystone/sdk/examples/hello-native/host/bignum.c
[ 31%] Linking CXX executable hello-native-runner
cd /home/saidheeraj/keystone/build-directory/examples/hello-native && /usr/bin/cmake -E cmake_link_script CMakeFiles/hello-native-runner.dir/link.txt --verbose=1
/home/saidheeraj/keystone/riscv64/bin/riscv64-unknown-linux-gnu-g++     CMakeFiles/hello-native-runner.dir/host/host_native.cpp.o CMakeFiles/hello-native-runner.dir/host/rsa.c.o CMakeFiles/hello-native-runner.dir/host/bignum.c.o  -o hello-native-runner ../../../sdk/build64/lib/libkeystone-host.a ../../../sdk/build64/lib/libkeystone-edge.a 
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/hello-native-runner.dir/host/host_native.cpp.o: in function `.L21':
host_native.cpp:(.text+0x2ee): undefined reference to `BN_init(bignum_t*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/hello-native-runner.dir/host/host_native.cpp.o: in function `.L0 ':
host_native.cpp:(.text+0x378): undefined reference to `BN_init(bignum_t*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: host_native.cpp:(.text+0x386): undefined reference to `BN_init(bignum_t*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: host_native.cpp:(.text+0x394): undefined reference to `BN_init(bignum_t*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: host_native.cpp:(.text+0x3a2): undefined reference to `BN_init(bignum_t*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: host_native.cpp:(.text+0x3b6): undefined reference to `BN_hex2bn(bignum_t*, char*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: host_native.cpp:(.text+0x3ca): undefined reference to `BN_hex2bn(bignum_t*, char*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: host_native.cpp:(.text+0x3de): undefined reference to `BN_hex2bn(bignum_t*, char*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: host_native.cpp:(.text+0x3f2): undefined reference to `BN_hex2bn(bignum_t*, char*)'
/home/saidheeraj/keystone/riscv64/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: host_native.cpp:(.text+0x430): undefined reference to `rsaEncrypt(bignum_t*, bignum_t*, bignum_t*, bignum_t*, bignum_t)'
collect2: error: ld returned 1 exit status
examples/hello-native/CMakeFiles/hello-native-runner.dir/build.make:151: recipe for target 'examples/hello-native/hello-native-runner' failed
make[3]: *** [examples/hello-native/hello-native-runner] Error 1
make[3]: Leaving directory '/home/saidheeraj/keystone/build-directory'
CMakeFiles/Makefile2:906: recipe for target 'examples/hello-native/CMakeFiles/hello-native-runner.dir/all' failed
make[2]: *** [examples/hello-native/CMakeFiles/hello-native-runner.dir/all] Error 2
make[2]: Leaving directory '/home/saidheeraj/keystone/build-directory'
CMakeFiles/Makefile2:1059: recipe for target 'examples/hello-native/CMakeFiles/hello-native-package.dir/rule' failed
make[1]: *** [examples/hello-native/CMakeFiles/hello-native-package.dir/rule] Error 2
make[1]: Leaving directory '/home/saidheeraj/keystone/build-directory'
Makefile:459: recipe for target 'hello-native-package' failed
make: *** [hello-native-package] Error 2
ESaiDheeraj commented 2 years ago

As the host directory initially had a CPP file, I changed the remaining files that I added to it into CPP files (previously, they were just C files).

Previously the 4th line as shown above looks like set(host_src host/host_native.cpp host/rsa.c host/bignum.c)

Now the 4th line looks like set(host_src host/host_native.cpp host/rsa.cpp host/bignum.cpp)

After doing this change, my code started working without any error.