0

I made a working C++ project with boost and std on windows with visual studio. After some hours of coding I realise that was stupide of me to use a VS2017 since I will need to test the software on mac and linux. So I went on my mac, and now I am trying to just compile everything. I built boost on mac :

./bootstrap.sh && ./b2 threading=multi link=static runtime-link=static install

Then I took the lib I need (chrono, thread, regex, system, thread, date_time) and copy the libboost_xxx.a files into a folder of my project.

Now this is my current 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})

As you can see I don't have much going on but nonetheless it cannot be built :

/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

I've been working on windows only with C++ until now and so I might have made so giant mistake with the Cmake file but I don't know what.

The libs I look for are found and everything seems to work. I know the libs are the right ones since on the windows version, they are the one I use.

Down the line I want to make one makefile for windows and unix so I can stop working with the SLN.

rXp
  • 617
  • 2
  • 12
  • 25
  • 1
    `find_library` is used to search for one library, where `NAMES` is a list of possible names for that library. As such, you're likely finding the first (`libboost_atomic`), at which point `find_library` returns, and the rest of your libraries aren't linked – Steve Lorimer Nov 01 '17 at 19:10
  • 2
    consider using `find_package` instead of `find_library` (see [`FindBoost`](https://cmake.org/cmake/help/v3.0/module/FindBoost.html)) – Steve Lorimer Nov 01 '17 at 19:11
  • `include_directories` is considered a code smell these days, better to use `target_include_directories` – Steve Lorimer Nov 01 '17 at 19:11
  • @SteveLorimer what if I want to specify the path to the libs ? – rXp Nov 01 '17 at 19:33
  • What's your Boost version? For 1.65 or newer you need CMake 3.9.3, cf. https://stackoverflow.com/a/42124857/2799037 – usr1234567 Nov 01 '17 at 20:19

1 Answers1

0

I needed to use

find_package

for boost (FindBoost) or

find_library

for EACH file.

rXp
  • 617
  • 2
  • 12
  • 25