2012-02-13 12 views
5

मैंने खोज की और पाया कि बहुत से लोगों को एक ही समस्या है, लेकिन कोई समाधान मौजूद नहीं है।सीएमके और बूस्ट

मैं CMake उपयोग कर रहा हूँ MinGW के लिए Makefiles उत्पन्न करने के लिए और जब संकलन मैं एक त्रुटि हो रही है:

CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x5e): undefined reference to `_imp___ZN5boost6thread4joinEv' 
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x71): undefined reference to `_imp___ZN5boost6threadD1Ev' 
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x88): undefined reference to `_imp___ZN5boost6threadD1Ev' 

यह एक जोड़ने समस्या लगती है, मैं समझ गया। मेरे CMake विन्यास है:

project(boosttest) 
cmake_minimum_required(VERSION 2.6) 

include_directories(${boosttest_SOURCE_DIR}/include c:/boost_1_48_0/) 
link_directories(c:/boost_1_48_0/lib) 

file(GLOB_RECURSE cppFiles src/*.cpp) 

add_executable(boosttest ${cppFiles}) 

target_link_libraries(boosttest libboost_thread-mgw46-mt-1_48.a) 

सबसे पहले मैं find_package(Boost COMPONENTS thread) उपयोग करने की कोशिश है और यह उसी तरह काम कर रहा था, इसलिए मैं इस मैन्युअल रूप से करने की कोशिश करने के लिए सोचा और मैं अभी भी एक ही त्रुटि मिलती है।

इस पर कोई अंतर्दृष्टि?

मैंने इसे bjam का उपयोग करके और एक स्थिर लिंक के रूप में mingw के लिए संकलित किया है। यह भी करने की कोशिश की:

add_library(imp_libboost_thread STATIC IMPORTED) 
set_property(TARGET imp_libboost_thread PROPERTY IMPORTED_LOCATION c:/boost_1_48_0/lib/libboost_thread-mgw46-mt-1_48.a) 
target_link_libraries(boosttest imp_libboost_thread) 

और मुझे अभी भी वही त्रुटि संदेश मिलते हैं।

उत्तर

10

mingw32 के लिए आप परिभाषा BOOST_THREAD_USE_LIB जोड़ सकते हैं। और बूस्ट :: थ्रेड के साथ लिंक काम करेगा। इसके अलावा आपको Threads पैकेज की आवश्यकता हो सकती है (लेकिन मुझे यकीन नहीं है, इसे केवल * निक्स प्लेटफ़ॉर्म के लिए ही आवश्यक हो सकता है)।

यहां मेरे सीएमकेलिस्ट का हिस्सा है। मैं यह परियोजना, को बढ़ावा देने :: धागा का उपयोग करता है जो से नकल, और MinGW-जीसीसी (और अन्य compilers) के तहत संकलित:

set(Boost_USE_STATIC_LIBS ON) 
    set(Boost_USE_MULTITHREADED ON) 
    set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0") 
    find_package(Boost COMPONENTS thread date_time program_options filesystem system REQUIRED) 
    include_directories(${Boost_INCLUDE_DIRS}) 

    find_package(Threads REQUIRED) 

    #... 

    if (WIN32 AND __COMPILER_GNU) 
     # mingw-gcc fails to link boost::thread 
     add_definitions(-DBOOST_THREAD_USE_LIB) 
    endif (WIN32 AND __COMPILER_GNU) 

    #... 

    target_link_libraries(my_exe 
      ${CMAKE_THREAD_LIBS_INIT} 
      #... 
     ${Boost_LIBRARIES} 
    ) 
+0

BOOST_THREAD_USE_LIB को जोड़ने के लिए यह मेरे लिए तय किया गया है। मैं इस समय अपने सिर को आखिरी घंटे या उससे भी ज्यादा समय तक खरोंच कर रहा हूं। – CadentOrange

3

मेरी राय में, यह प्रश्न this question और this one के समान है। मेरा सबसे अच्छा अनुमान यह होगा कि आपको first question के उत्तर में उसी रिज़ॉल्यूशन की आवश्यकता है।

मैं दृढ़ता से find_package (बूस्ट) के उपयोग की सिफारिश करेंगे और ऑटो जोड़ने के साथ ध्यान रखना:

project(boosttest) 
cmake_minimum_required(VERSION 2.6) 

# Play with the following defines 
# Disable auto-linking. 
add_definition(-DBOOST_ALL_NO_LIB) 
# In case of a Shared Boost install (dlls), you should then enable this 
# add_definitions(-DBOOST_ALL_DYN_LINK) 

# Explicitly tell find-package to search for Static Boost libs (if needed) 
set(Boost_USE_STATIC_LIBS ON) 
find_package(Boost REQUIRED COMPONENTS thread) 

include_directories(${Boost_INCLUDE_DIRS}) 

file(GLOB_RECURSE cppFiles src/*.cpp) 

add_executable(boosttest ${cppFiles}) 

target_link_libraries(boosttest ${Boost_LIBRARIES}) 
+0

मैं पहले से ही उन पदों से सब कुछ कोशिश की है, लेकिन यह भी अब सब कुछ फिर से जांचा और सभी समय मुझे समान त्रुटि मिली। यह लाइब्रेरी पाता है और पूरी तरह से सेट करता है, लेकिन किसी भी तरह से यह लिंक नहीं करेगा ... मैंने '--build-type = full' का उपयोग करके भी बढ़ावा दिया है और गतिशील लिंक करने की कोशिश की है, और यह अभी भी जीता है काम नहीं कर रहा है ... –

+0

मेरे मामले में मुझे 'find_package (घटक थ्रेड सिस्टम की आवश्यकता है) और 'target_link_libraries ( $ {Boost_LIBRARIES}) जोड़ना था! – Tanasis