我遇到了CMake的问题。
我想编译一个文件,在链接时会收到一些错误。
这是我的错误日志:
[ 30%] Built target thecore
[ 37%] Built target sql
[ 44%] Built target poly
[ 50%] Built target game
Linking CXX executable db_32
CMakeFiles/db_32.dir/src/Main.cpp.o: In function `Start()':
/atharia_svn/server/db/src/Main.cpp:373: undefined reference to `PlayerHB::Initialize()'
CMakeFiles/db_32.dir/src/Main.cpp.o: In function `main':
/atharia_svn/server/db/src/Main.cpp:67: undefined reference to `PlayerHB::PlayerHB()'
/atharia_svn/server/db/src/Main.cpp:74: undefined reference to `CBlockCountry::CBlockCountry()'
/atharia_svn/server/db/src/Main.cpp:84: undefined reference to `CBlockCountry::Load()'
/atharia_svn/server/db/src/Main.cpp:74: undefined reference to `CBlockCountry::~CBlockCountry()'
/atharia_svn/server/db/src/Main.cpp:67: undefined reference to `PlayerHB::~PlayerHB()'
/atharia_svn/server/db/src/Main.cpp:74: undefined reference to `CBlockCountry::~CBlockCountry()'
/atharia_svn/server/db/src/Main.cpp:67: undefined reference to `PlayerHB::~PlayerHB()'
CMakeFiles/db_32.dir/src/ClientManager.cpp.o: In function `CClientManager::BlockException(tBlockException*)':
/atharia_svn/server/db/src/ClientManager.cpp:4248: undefined reference to `CBlockCountry::DelBlockException(char const*)'
/atharia_svn/server/db/src/ClientManager.cpp:4263: undefined reference to `CBlockCountry::SendBlockExceptionOne(CPeer*, char const*, unsigned char)'
/atharia_svn/server/db/src/ClientManager.cpp:4243: undefined reference to `CBlockCountry::AddBlockException(char const*)'
CMakeFiles/db_32.dir/src/ClientManager.cpp.o: In function `CClientManager::ProcessPackets(CPeer*)':
/atharia_svn/server/db/src/ClientManager.cpp:2636: undefined reference to `CBlockCountry::SendBlockedCountryIp(CPeer*)'
/atharia_svn/server/db/src/ClientManager.cpp:2637: undefined reference to `CBlockCountry::SendBlockException(CPeer*)'
CMakeFiles/db_32.dir/src/ClientManagerPlayer.cpp.o: In function `CClientManager::PutPlayerCache(SPlayerTable*)':
/atharia_svn/server/db/src/ClientManagerPlayer.cpp:193: undefined reference to `PlayerHB::Put(unsigned int)'
collect2: error: ld returned 1 exit status
*** [db/db_32] Error code 1
Stop in /atharia_svn/Build.
*** [db/CMakeFiles/db_32.dir/all] Error code 1
Stop in /atharia_svn/Build.
*** [all] Error code 1
Stop in /atharia_svn/Build.
我不明白为什么不运行,在gcc49下编译makefile时没有收到任何错误。
一切都很完美。
这是来自对象链接的CMakeLists.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
MESSAGE(STATUS "compilerVersion=${COMPILER}")
SET(CMAKE_CXX_COMPILER ${COMPILER})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${DB_OUTPUT_DIR})
set(exe db_32)
MESSAGE(STATUS "svnVersion=${svnVersion}")
include_directories("../../extern/boost-1.43.0") #Boost
include_directories("../../extern/mysql-5.6.23") #Mysql
link_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../Build/libthecore
${CMAKE_CURRENT_SOURCE_DIR}/../../Build/libsql
${CMAKE_CURRENT_SOURCE_DIR}/../../Build/libpoly
${CMAKE_CURRENT_SOURCE_DIR}/../../Build/libgame
${CMAKE_CURRENT_SOURCE_DIR}/../../extern/mysql-5.6.23
)
set(CMAKE_CXX_FLAGS "${ADDITIONAL_FLAGS_CXX}")
SET(CMAKE_EXE_LINKER_FLAGS "${ADDITIONAL_LINKER_FLAGS}")
add_executable (${exe}
src/Config.cpp
src/NetBase.cpp
src/Peer.cpp
src/PeerBase.cpp
src/Main.cpp
src/Lock.cpp
src/DBManager.cpp
src/Cache.cpp
src/LoginData.cpp
src/ClientManager.cpp
src/ClientManagerPlayer.cpp
src/ClientManagerLogin.cpp
src/ClientManagerBoot.cpp
src/ClientManagerParty.cpp
src/ClientManagerGuild.cpp
src/GuildManager.cpp
src/PrivManager.cpp
src/MoneyLog.cpp
src/ItemAwardManager.cpp
src/ClientManagerEventFlag.cpp
src/Marriage.cpp src/Monarch.cpp
src/ItemIDRangeManager.cpp
src/ClientManagerHorseName.cpp
src/version.cpp
src/AuctionManager.cpp
src/ProtoReader.cpp
src/CsvReader.cpp
)
add_definitions(${CMAKE_CXX_FLAGS} ${CMAKE_EXE_LINKER_FLAGS})
SET_TARGET_PROPERTIES(${exe} PROPERTIES LINK_SEARCH_END_STATIC 1)
set(CMAKE_EXE_LINKER_FLAGS -static)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_C_FLAGS) # remove -fPIC
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) # remove -rdynamic
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
TARGET_LINK_LIBRARIES(${exe} pthread libthecore.a libsql.a libmysqlclient.a libpoly.a libgame.a)
这是主要的CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(game)
enable_language(C)
set(COMPILER "g++49") #Required
set(ADDITIONAL_FLAGS_CXX "-O2 -pipe -mtune=i686 -g")
set(ADDITIONAL_LINKER_FLAGS "-O2 -pipe -mtune=i686 -g")
add_subdirectory(libthecore)
add_subdirectory(libsql)
add_subdirectory(libpoly)
add_subdirectory(libgame)
#add_subdirectory(liblua)
#add_subdirectory(game)
add_subdirectory(db)
set(GAME_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/Bin/freebsd_release)
set(DB_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/Bin/freebsd_release)
我试了24小时来解决这个错误,如果有人有想法,可以帮助我。
最诚挚的问候。
答案 0 :(得分:1)
解决了,有一个链接错误。我改变了CFLAGS witc -std = c ++ 14