cmake 常见问题及解决

时间:2022-12-28 15:58:51

1. undefined reference to symbol ‘pthread_key_delete@@GLIBC_2.2.5

未定义对某符号的引用,该错误为链接时(linking)发生的错误。有如下方式的解决方案:

  • 修改 Makefile 文件,为变量 LDFLAGS加入,-L /lib64 -l pthread
    • 通过TARGET_LINK_LIBRARIES(... -lpthread -lm)-lpthread -lm添加进 CMakelists.txt文件;

2. 通过 cmake 的方式链接 google protobuf

How to link google protobuf libraries via cmake on linux?

include(FindProtobuf)
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIR})
...
target_link_libraries(complex
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${PROTOBUF_LIBRARY}
)