How to set CMAKE static linking ( undefined reference to `dlopen' )?

岁酱吖の 提交于 2020-01-07 05:10:29

问题


I need to set static linking for my project.

Current state is :

target_link_libraries(armd
  ${SQLITE3_LIBRARY}
  ${CMAKE_THREAD_LIBS_INIT}
  rt)

if(CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_CXX_FLAGS "-O0 -Wall -fmessage-length=0")

doesn't work on device, I need to link statically (add -static for device) but when I do

set(CMAKE_CXX_FLAGS "-O0 -Wall -fmessage-length=0 -static")

I'm getting:

/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libsqlite3.a(sqlite3.o): In function `unixDlOpen':
sqlite3.c:(.text+0x3e5d4): undefined reference to `dlopen'

How do I set static linking for sqlite without getting this error? Or maybe my root system is missing something?


回答1:


When statically linking some archives, you need to specify its dependencies (in this case libdl) yourself. Be aware of that the order in which you specify the archive files on the linker command line is more important than for linking shared objects.



来源:https://stackoverflow.com/questions/13009261/how-to-set-cmake-static-linking-undefined-reference-to-dlopen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!