2017-07-10 9 views
0

Ich versuche Boost in meinem C++ Projekt in MacOS Sierra zu verwenden. Ich habe installiert Boost-Home-Gebräu mit, etwa so:boost + home-brew + macOS Sierra

Gebräu boost installieren

Meine CMakeLists.txt Datei sieht aus wie cmake_minimum_required (VERSION 3.8) Projekt (sr)

set(CMAKE_CXX_STANDARD 14) 

set(Boost_USE_STATIC_LIBS  OFF) # only find static libs 
set(Boost_USE_MULTITHREADED  ON) 
set(Boost_USE_STATIC_RUNTIME  OFF) 
find_package(Boost 1.64.0 COMPONENTS system log log_setup thread date_time filesystem regex chrono atomic REQUIRED) 

include_directories(src) 
include_directories(lib/easylogging++) 
include_directories(${Boost_INCLUDE_DIRS}) 

add_subdirectory(src) 
add_subdirectory(sr_tests) 

set(SOURCE_FILES main.cpp lib/easylogging++/easylogging++.cc) 

add_executable(sr_out ${SOURCE_FILES}) 
target_link_libraries(sr_out ${Boost_LIBRARIES} sr) 

Meine main.cpp ist einfach #include

int main() { 
    BOOST_LOG_TRIVIAL(info) << "hi"; 
    return 1; 
} 

In der Aufbauphase, die binäre mit Verbindung herstellen kann

➜ build git:(master) ✗ cmake .. 
-- The C compiler identification is AppleClang 8.1.0.8020042 
-- The CXX compiler identification is AppleClang 8.1.0.8020042 
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc 
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Detecting C compile features 
-- Detecting C compile features - done 
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Detecting CXX compile features 
-- Detecting CXX compile features - done 
-- Looking for pthread.h 
-- Looking for pthread.h - found 
-- Looking for pthread_create 
-- Looking for pthread_create - found 
-- Found Threads: TRUE 
-- Boost version: 1.64.0 
-- Found the following Boost libraries: 
-- system 
-- log 
-- log_setup 
-- thread 
-- date_time 
-- filesystem 
-- regex 
-- chrono 
-- atomic 
-- Configuring done 
-- Generating done 
-- Build files have been written to: /Volumes/sr/sr/build 
➜ build git:(master) ✗ make VERBOSE=1 
/usr/local/Cellar/cmake/3.8.2/bin/cmake -H/Volumes/sr/sr -B/Volumes/sr/sr/build --check-build-system CMakeFiles/Makefile.cmake 0 
/usr/local/Cellar/cmake/3.8.2/bin/cmake -E cmake_progress_start /Volumes/sr/sr/build/CMakeFiles /Volumes/sr/sr/build/CMakeFiles/progress.marks 
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/Makefile2 all 
/Library/Developer/CommandLineTools/usr/bin/make -f src/CMakeFiles/sr.dir/build.make src/CMakeFiles/sr.dir/depend 
cd /Volumes/sr/sr/build && /usr/local/Cellar/cmake/3.8.2/bin/cmake -E cmake_depends "Unix Makefiles" /Volumes/sr/sr /Volumes/sr/sr/src /Volumes/sr/sr/build /Volumes/sr/sr/build/src /Volumes/sr/sr/build/src/CMakeFiles/sr.dir/DependInfo.cmake --color= 
/Library/Developer/CommandLineTools/usr/bin/make -f src/CMakeFiles/sr.dir/build.make src/CMakeFiles/sr.dir/build 
make[2]: Nothing to be done for `src/CMakeFiles/sr.dir/build'. 
[ 30%] Built target sr 
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/sr_out.dir/build.make CMakeFiles/sr_out.dir/depend 
cd /Volumes/sr/sr/build && /usr/local/Cellar/cmake/3.8.2/bin/cmake -E cmake_depends "Unix Makefiles" /Volumes/sr/sr /Volumes/sr/sr /Volumes/sr/sr/build /Volumes/sr/sr/build /Volumes/sr/sr/build/CMakeFiles/sr_out.dir/DependInfo.cmake --color= 
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/sr_out.dir/build.make CMakeFiles/sr_out.dir/build 
[ 40%] Linking CXX executable sr_out 
/usr/local/Cellar/cmake/3.8.2/bin/cmake -E cmake_link_script CMakeFiles/sr_out.dir/link.txt --verbose=1 
/Library/Developer/CommandLineTools/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/sr_out.dir/main.cpp.o CMakeFiles/sr_out.dir/lib/easylogging++/easylogging++.cc.o -o sr_out /usr/local/lib/libboost_system-mt.dylib /usr/local/lib/libboost_log-mt.dylib /usr/local/lib/libboost_log_setup-mt.dylib /usr/local/lib/libboost_thread-mt.dylib /usr/local/lib/libboost_date_time-mt.dylib /usr/local/lib/libboost_filesystem-mt.dylib /usr/local/lib/libboost_regex-mt.dylib /usr/local/lib/libboost_chrono-mt.dylib /usr/local/lib/libboost_atomic-mt.dylib src/libsr.a 
Undefined symbols for architecture x86_64: 
    "boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)", referenced from: 
     boost::log::v2s_mt_posix::record::reset() in main.cpp.o 
    "boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)", referenced from: 
     boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::auto_release::~auto_release() in main.cpp.o 
    "boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)", referenced from: 
     boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>&, boost::log::v2s_mt_posix::record&) in main.cpp.o 
    "boost::log::v2s_mt_posix::aux::unhandled_exception_count()", referenced from: 
     boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>&, boost::log::v2s_mt_posix::record&) in main.cpp.o 
     boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::~record_pump() in main.cpp.o 
    "boost::log::v2s_mt_posix::core::open_record(boost::log::v2s_mt_posix::attribute_set const&)", referenced from: 
     boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> const&) in main.cpp.o 
    "boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)", referenced from: 
     boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex> >::push_record_unlocked(boost::log::v2s_mt_posix::record&&) in main.cpp.o 
    "boost::log::v2s_mt_posix::sources::aux::get_severity_level()", referenced from: 
     boost::log::v2s_mt_posix::sources::aux::severity_level<boost::log::v2s_mt_posix::trivial::severity_level>::set_value(boost::log::v2s_mt_posix::trivial::severity_level) in main.cpp.o 
    "boost::log::v2s_mt_posix::trivial::logger::get()", referenced from: 
     _main in main.cpp.o 
    "boost::log::v2s_mt_posix::core::get_logging_enabled() const", referenced from: 
     boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_composite_logger<char, boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex>, boost::log::v2s_mt_posix::sources::features<boost::log::v2s_mt_posix::sources::severity<boost::log::v2s_mt_posix::trivial::severity_level> > >::open_record<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> const&) in main.cpp.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make[2]: *** [sr_out] Error 1 
make[1]: *** [CMakeFiles/sr_out.dir/all] Error 2 
make: *** [all] Error 2 
➜ build git:(master) ✗ 

Ich würde wirklich jede Hilfe bei der Einrichtung dieser Einrichtung zu schätzen wissen.

+0

Sind Sie sicher, dass Sie den Aufbau einer 64-Bit-Programm? – tadman

+0

Ich denke, das ist, was meine CMake-Konfiguration standardmäßig tut. BTW, Boost von CMake entfernen und diese eine Zeile Code in main.cpp macht die gesamte Codebasis kompilieren eine 64-Bit-Binärdatei ganz gut. – gurjeet

+0

Welche Symbole werden nicht gefunden? – tadman

Antwort

2

Das Problem war, dass die Boost Logging-Bibliothek dynamisch verknüpft werden musste. Ich reparierte meine CMakeLists.txt Datei diese Zeile hinzufügen:

add_definitions(-DBOOST_LOG_DYN_LINK=1) 

Dies das Problem behoben

Verwandte Themen