“图书馆没有符号”是什么意思?

Wei*_* Hu 3 c++ linker compilation cmake

我正在使用 CMake 构建我的项目所需的一些依赖库。它们是 Boost_system、Boost_filesystem 和 Boost_program_options。我单独编译静态库,而不是编译整个 Boost 库。

一切正常,但我收到以下警告消息:

...
[ 67%] Building CXX object filesystem/CMakeFiles/filesystem.dir/src/utf8_codecvt_facet.cpp.o
[ 70%] Building CXX object filesystem/CMakeFiles/filesystem.dir/src/windows_file_codecvt.cpp.o
[ 74%] Linking CXX static library libfilesystem.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libfilesystem.a(windows_file_codecvt.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libfilesystem.a(windows_file_codecvt.cpp.o) has no symbols
[ 74%] Built target filesystem
[ 77%] Building CXX object CMakeFiles/canalogsmp.dir/src/Array2D.cpp.o
...
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  • 符号是什么?警告消息是什么意思?
  • 我怎样才能摆脱这个警告信息?

Wei*_* Hu 6

感谢nakiya,我找到了答案。

所以警告信息的解释就在这里。基本上没有找到可操作的代码ranlib。但就我而言,我只需要忽略这些警告。

此处提供了解决方案,也粘贴在下面。确保将标志传递给ranlib而不是编译器本身。

SET(CMAKE_C_ARCHIVE_FINISH   "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
Run Code Online (Sandbox Code Playgroud)

  • 请在这里重复解释和解决方案,而不仅仅是链接。 (7认同)