CMAKE,我是否链接了错误的lib?

时间:2017-11-01 19:04:36

标签: c++ macos cmake

我使用visual studio在windows上创建了一个带有boost和std的C ++项目。 经过几个小时的编码后,我意识到使用VS2017是我的愚蠢,因为我需要在mac和linux上测试软件。 所以我继续我的Mac,现在我正在尝试编译所有内容。 我在mac上构建了boost:

  

./ bootstrap.sh&& ./b2 threading = multi link = static   runtime-link =静态安装

然后我拿了我需要的lib(chrono,thread,regex,system,thread,date_time)并将libboost_xxx.a文件复制到我项目的文件夹中。

现在这是我当前的makefile:

cmake_minimum_required(VERSION 3.8)
project(AuthServer)

include_directories(${CMAKE_SOURCE_DIR}/Include)

set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES
        AuthServer/Client.cpp
        AuthServer/Client.h
        AuthServer/main.cpp
        AuthServer/NetworkManager.cpp
        AuthServer/NetworkManager.h)

find_library(BOOST_LIBRARY
        NAMES libboost_atomic boost_chrono boost_date_time boost_regex boost_thread boost_system
        PATHS ${CMAKE_SOURCE_DIR}/Lib/mac/x64
        NO_DEFAULT_PATH)

add_executable(AuthServer ${SOURCE_FILES})

target_link_libraries(AuthServer ${BOOST_LIBRARY})

正如你所看到的,我没有太多进展,但仍无法建造:

/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug"
--target AuthServer -- -j 4 /Applications/CLion.app/Contents/bin/cmake/bin/cmake
-H"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer" -B"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug"
--check-build-system CMakeFiles/Makefile.cmake 0 /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 AuthServer /Applications/CLion.app/Contents/bin/cmake/bin/cmake
-H"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer" -B"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug"
--check-build-system CMakeFiles/Makefile.cmake 0 /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug/CMakeFiles" 4 /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/AuthServer.dir/all /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/AuthServer.dir/build.make CMakeFiles/AuthServer.dir/depend cd "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug" && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug/CMakeFiles/AuthServer.dir/DependInfo.cmake"
--color= /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/AuthServer.dir/build.make CMakeFiles/AuthServer.dir/build [ 25%] Building CXX object CMakeFiles/AuthServer.dir/AuthServer/Client.cpp.o [ 50%] Building CXX object CMakeFiles/AuthServer.dir/AuthServer/main.cpp.o /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-I"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/Include"  -g -arch x86_64
-mmacosx-version-min=10.12   -std=gnu++11 -o CMakeFiles/AuthServer.dir/AuthServer/Client.cpp.o -c "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/AuthServer/Client.cpp" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-I"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/Include"  -g -arch x86_64
-mmacosx-version-min=10.12   -std=gnu++11 -o CMakeFiles/AuthServer.dir/AuthServer/main.cpp.o -c "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/AuthServer/main.cpp" [ 75%] Building CXX object CMakeFiles/AuthServer.dir/AuthServer/NetworkManager.cpp.o /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-I"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/Include"  -g -arch x86_64
-mmacosx-version-min=10.12   -std=gnu++11 -o CMakeFiles/AuthServer.dir/AuthServer/NetworkManager.cpp.o -c "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/AuthServer/NetworkManager.cpp" [100%] Linking CXX executable AuthServer /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/AuthServer.dir/link.txt --verbose=1 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-g -arch x86_64 -mmacosx-version-min=10.12 -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/AuthServer.dir/AuthServer/Client.cpp.o CMakeFiles/AuthServer.dir/AuthServer/main.cpp.o CMakeFiles/AuthServer.dir/AuthServer/NetworkManager.cpp.o  -o AuthServer ../Lib/mac/x64/libboost_chrono.a  Undefined symbols for architecture x86_64:   "boost::this_thread::interruption_point()", referenced from:
      boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in NetworkManager.cpp.o   "boost::this_thread::disable_interruption::disable_interruption()", referenced from:
      boost::shared_mutex::lock_shared() in NetworkManager.cpp.o
      boost::shared_mutex::lock() in NetworkManager.cpp.o   "boost::this_thread::disable_interruption::~disable_interruption()", referenced from:
      boost::shared_mutex::lock_shared() in NetworkManager.cpp.o
      boost::shared_mutex::lock() in NetworkManager.cpp.o   "boost::detail::thread_data_base::~thread_data_base()", referenced from:
      boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf1<void, NetworkManager, boost::shared_ptr<boost::asio::io_service> >, boost::_bi::list2<boost::_bi::value<NetworkManager*>, boost::_bi::value<boost::shared_ptr<boost::asio::io_service> > > >
>::~thread_data() in NetworkManager.cpp.o   "boost::detail::get_current_thread_data()", referenced from:
      boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*,
_opaque_pthread_cond_t*) in NetworkManager.cpp.o   "boost::system::system_category()", referenced from:
      boost::asio::error::get_system_category() in Client.cpp.o
      boost::system::error_code::error_code() in Client.cpp.o
      ___cxx_global_var_init.2 in Client.cpp.o
      boost::asio::error::get_system_category() in main.cpp.o
      ___cxx_global_var_init.2 in main.cpp.o
      boost::asio::error::get_system_category() in NetworkManager.cpp.o
      boost::system::error_code::error_code() in NetworkManager.cpp.o
      ...   "boost::system::generic_category()", referenced from:
      boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const in Client.cpp.o
      boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const in Client.cpp.o
      boost::thread_exception::thread_exception(int, char const*) in Client.cpp.o
      ___cxx_global_var_init in Client.cpp.o
      ___cxx_global_var_init.1 in Client.cpp.o
      boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const in main.cpp.o
      boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const in main.cpp.o
      ...   "boost::thread::join_noexcept()", referenced from:
      boost::thread::join() in NetworkManager.cpp.o   "boost::thread::native_handle()", referenced from:
      boost::thread::get_id() const in NetworkManager.cpp.o   "boost::thread::hardware_concurrency()", referenced from:
      _main in main.cpp.o   "boost::thread::start_thread_noexcept()", referenced from:
      boost::thread::start_thread() in NetworkManager.cpp.o   "boost::thread::detach()", referenced from:
      boost::thread::~thread() in NetworkManager.cpp.o   "boost::thread::joinable() const", referenced from:
      boost::thread_group::join_all() in NetworkManager.cpp.o   "typeinfo for boost::detail::thread_data_base", referenced from:
      typeinfo for boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf1<void, NetworkManager, boost::shared_ptr<boost::asio::io_service> >, boost::_bi::list2<boost::_bi::value<NetworkManager*>, boost::_bi::value<boost::shared_ptr<boost::asio::io_service> > > > > in NetworkManager.cpp.o   "vtable for boost::detail::thread_data_base", referenced from:
      boost::detail::thread_data_base::thread_data_base() in NetworkManager.cpp.o   NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: *** [AuthServer] Error 1 make[2]: *** [CMakeFiles/AuthServer.dir/all] Error 2 make[1]:
*** [CMakeFiles/AuthServer.dir/rule] Error 2 make: *** [AuthServer] Error 2

到目前为止,我一直在使用C ++工作,所以我可能在Cmake文件中犯了这么大的错误,但我不知道是什么。

找到了我寻找的库,一切似乎都有效。我知道libs是正确的,因为在Windows版本中,它们是我使用的。

在线下我想为windows和unix创建一个makefile,这样我就可以停止使用SLN了。

1 个答案:

答案 0 :(得分:0)

我需要使用

  

find_package

for boost(FindBoost)或

  

find_library

表示每个文件。