Neutree / c_cpp_project_framework

CMake build system( framework) with kconfig support for C/CPP projects
https://neucrack.com/p/276
MIT License
157 stars 38 forks source link

Building a dynamic library using libmaix #10

Closed pauceano closed 3 months ago

pauceano commented 3 months ago

I am trying to build a dynamic library using libmaix but I cannot. I want to build libZMQ library,

I copied the hello_world example in libmaix, I have put all sources in main/src and includes in main/include

I have added to /libmaix/examples/libzmq/main/CMakeLists.txt list(APPEND ADD_DEFINITIONS -fPIC) and register_component(SHARED) I see in the logs that compile.cmake has activated to_dynamic_lib flag. But, after compiling everything, it ends with the following error: ..... [ 95%] Building CXX object main/CMakeFiles/main.dir/src/zmq_utils.cpp.o [ 96%] Building CXX object main/CMakeFiles/main.dir/src/zmtp_engine.cpp.o [ 97%] Linking CXX shared library libmain.so [ 97%] Built target main Scanning dependencies of target libzmq [ 98%] Building C object CMakeFiles/libzmq.dir/exe_src.c.o [ 99%] Linking C executable libzmq /opt/toolchain-sunxi-musl/toolchain/bin/../lib/gcc/arm-openwrt-linux-muslgnueabi/6.4.1/../../../../arm-openwrt-linux-muslgnueabi/lib/crt1.o: In function _start_c': /home/caiyongheng/tina/out/astar-parrot/compile_dir/toolchain/musl-1.1.16/crt/crt1.c:17: undefined reference tomain' collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/libzmq.dir/build.make:89: libzmq] Error 1 make[1]: [CMakeFiles/Makefile2:301: CMakeFiles/libzmq.dir/all] Error 2 make: *** [Makefile:84: all] Error 2 ....

Neutree commented 3 months ago

seems not suport set main component as dynamic, you can create new component set to dynamic, and the so file will be in build dir.

This is a new feature request: Compile project to dynamic lib, I can support it later, but now you can resolve it by the upper method.

pauceano commented 3 months ago

Thank you for your rapid answer. Sorry, I do not understand how "create new component set to dynamic" Can you please detail?

skb666 commented 3 months ago

/libmaix/examples/libzmq/main 重命名这个文件夹(比如 libzmq) 再建一个 /libmaix/examples/libzmq/main main 文件夹里搞一个 .c 再随便写个 main 函数 改 /libmaix/examples/libzmq/compile/priority 让 main 依赖 libzmq

pauceano commented 3 months ago

Working, thanks.