我正在爲CMake配置我的項目,並且有鏈接問題 - 項目文件全部編譯成功,然後它說它正在鏈接並報告找不到的各種符號。CMake鏈接失敗
這些符號大部分由我自己的代碼提供,而其中一些代碼由BerkeleyDB提供,它們的位置和位置正確。
這裏是我的頂層的CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
project(rpdb C)
# add local modules path for project
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# where to look for source files (headers and source)
include_directories(include src)
# define sub-directories of source that cmake knows about as well a where their output will be put
add_subdirectory(src bin)
# compiler-dependent flags:
if(CMAKE_COMPILER_IS_GNUCC)
# gcc
add_definitions(-ggdb -fsigned-char -freg-struct-return -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)
else(CMAKE_COMPILER_IS_GNUCC)
# non-gcc (intended for clang)
add_definitions(-ggdb -fsigned-char -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror)
endif(CMAKE_COMPILER_IS_GNUCC)
# distribution configuration
set(CMAKE_C_FLAGS_DISTRIBUTION "-O3")
set(CMAKE_CXX_FLAGS_DISTRIBUTION "-O3")
這裏是我的SRC級的CMakeLists.txt:
# make sure we have libdb
find_package(BerkeleyDB REQUIRED)
include_directories(${libdb_INCLUDE_DIRS})
target_link_libraries(rpdb ${libdb_LIBRARIES})
# define variable specifying included source files - all .c files below this directory
file(GLOB rpdb_src "**/*.c")
# define shared library with sources
add_library(rpdb SHARED ${rpdb_src})
輸出(部分):
...
[100%] Building C object bin/CMakeFiles/rpdb.dir/RPDB_TransactionController/RPDB_TransactionController.c.o
Linking C shared library librpdb.dylib
Undefined symbols:
"_RPDB_ReplicationVerbositySettingsController_displayMessageProcessingInformation", referenced from:
_RPDB_SettingsController_internal_setVerbosity in RPDB_SettingsController.c.o
...
所有符號確實存在。結果似乎發生在目標文件以外的目標文件中的符號上。
從輸出 「的cmake ../」(從安裝,在頂級目錄):
=> cmake ..
-- Found BerkeleyDB: /usr/local/lib/libdb.dylib
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/ahaig/Projects/RPDB/RPDB_C/install
任何幫助非常讚賞。
我意識到$ {libdb_INCLUDE_DIRS}和$ {libdb_INCLUDE_LIBRARIES}是錯誤的,我需要$ {BerkeleyDB_INCLUDE_DIRS}和$ {BerkeleyDB_LIBRARIES},但是修正了我仍然存在的問題。 – Asher 2010-07-22 05:44:15
基於另一篇文章(http://stackoverflow.com/questions/1962453/cmake-finds-boost-but-nmake-fails-to-link)我添加了一行:MESSAGE(STATUS「libs:$ {BerkeleyDB_LIBRARIES} 「); $ {BerkeleyDB_LIBRARIES}和$ {LIBS}都不會打印任何內容。這似乎是我的問題 - 但爲什麼? – Asher 2010-07-22 05:45:33
之前的評論其實是不正確的;我需要使用$ {DB_LIBRARIES};現在我得到的輸出爲$ {LIBS},但我仍然有相同的鏈接問題。我已經開始使用全新的安裝目錄來測試它。嘗試了VERBOSE = 1並沒有看到任何不同;現在我將更仔細地檢查CMakeCache.txt。 – Asher 2010-07-22 18:06:18