2016-10-11 101 views
0

我一直試圖在過去的兩天裏在CLion中設置boost 1.62。我已經看到幾乎所有的堆棧問題,但仍然無法完成。在CLion窗口中設置Boost 1.62

我CMakeList.txt看起來是這樣的:

cmake_minimum_required(VERSION 3.6) 
project(DeSNN_CPP) 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 

SET (BOOST_ROOT "C:/Program Files/boost/boost_1_62_0") 
SET (BOOST_INCLUDEDIR "/opt/boost/boost-1.57.0/boost") 
SET (BOOST_LIBRARYDIR "/opt/boost/boost-1.57.0/boost") 

SET (BOOST_MIN_VERSION "1.62.0") 
set (Boost_NO_BOOST_CMAKE ON) 
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED) 
if (NOT Boost_FOUND) 
    message(FATAL_ERROR "Fatal error: Boost (version >= 1.62) required.") 
else() 
    message(WARNING "Setting up BOOST") 
    message(WARNING " Includes - ${Boost_INCLUDE_DIRS}") 
    message(WARNING " Library - ${Boost_LIBRARY_DIRS}") 
    include_directories(${Boost_INCLUDE_DIRS}) 
    link_directories(${Boost_LIBRARY_DIRS}) 
endif (NOT Boost_FOUND) 

set(SOURCE_FILES main.cpp) 
add_executable(DeSNN_CPP ${SOURCE_FILES}) 

警告,因爲我的cmake不給予STATUS輸出。

這似乎找到boost目錄,我可以導入所有的頭文件。 CMAKE輸出如下

Warning:start running cmake... 
Warning:Setting up BOOST 
Warning:Includes - C:/Program Files/boost/boost_1_62_0 
Warning:Library - 

Warning:Library似乎沒有顯示出來。當我輸入FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED filesystem)我收到以下錯誤

Error:Unable to find the requested Boost libraries. 
Boost version: 1.62.0 
Boost include path: C:/Program Files/boost/boost_1_62_0 
Could not find the following Boost libraries: 
     boost_filesystem 
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost. 

如果我試圖包含頭文件並運行它,我得到一個非常大的錯誤。

C:\Users\aksha\.CLion2016.2\system\cygwin_cmake\bin\cmake.exe --build "C:\Users\aksha\.CLion2016.2\system\cmake\generated\DeSNN CPP-4334ec6a\4334ec6a\Debug" --target DeSNN_CPP -- -j 4 
[ 25%] Linking CXX executable DeSNN_CPP.exe 
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `__static_initialization_and_destruction_0': 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()' 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:221:(.text+0x1ba): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()' 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()' 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:222:(.text+0x1c6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()' 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()' 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:223:(.text+0x1d2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()' 
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::string&)': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:938: undefined reference to `boost::filesystem::path::codecvt()' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:938:(.text$_ZN5boost10filesystem11path_traits7convertEPKwS3_RSs[_ZN5boost10filesystem11path_traits7convertEPKwS3_RSs]+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path::codecvt()' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:938: undefined reference to `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::string&, std::codecvt<wchar_t, char, _mbstate_t> const&)' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:938:(.text$_ZN5boost10filesystem11path_traits7convertEPKwS3_RSs[_ZN5boost10filesystem11path_traits7convertEPKwS3_RSs]+0x32): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::string&, std::codecvt<wchar_t, char, _mbstate_t> const&)' 
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::path_traits::convert(char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:946: undefined reference to `boost::filesystem::path::codecvt()' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:946:(.text$_ZN5boost10filesystem11path_traits7convertEPKcRSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcRSbIwSt11char_traitsIwESaIwEE]+0x37): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path::codecvt()' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:946: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:946:(.text$_ZN5boost10filesystem11path_traits7convertEPKcRSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcRSbIwSt11char_traitsIwESaIwEE]+0x52): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)' 
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::exists(boost::filesystem::path const&)': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:446: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:446:(.text$_ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' 
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::is_directory(boost::filesystem::path const&)': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:451: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:451:(.text$_ZN5boost10filesystem12is_directoryERKNS0_4pathE[_ZN5boost10filesystem12is_directoryERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' 
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::is_regular_file(boost::filesystem::path const&)': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:456: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:456:(.text$_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' 
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:614: undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:614:(.text$_ZN5boost10filesystem9file_sizeERKNS0_4pathE[_ZN5boost10filesystem9file_sizeERKNS0_4pathE]+0x16): additional relocation overflows omitted from the output 
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `FileReader::list_dir()': 
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/DeSNN CPP/FileReader.cpp:41: undefined reference to `boost::filesystem::path::filename() const' 
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `__static_initialization_and_destruction_0': 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()' 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()' 
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()' 
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:930: undefined reference to `boost::filesystem::path::codecvt()' 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:930: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)' 
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `boost::filesystem::detail::dir_itr_imp::~dir_itr_imp()': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:872: undefined reference to `boost::filesystem::detail::dir_itr_close(void*&)' 
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `boost::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const&)': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:903: undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)' 
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `boost::filesystem::directory_iterator::increment()': 
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:939: undefined reference to `boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)' 
collect2: error: ld returned 1 exit status 
make[3]: *** [CMakeFiles/DeSNN_CPP.dir/build.make:147: DeSNN_CPP.exe] Error 1 
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/DeSNN_CPP.dir/all] Error 2 
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/DeSNN_CPP.dir/rule] Error 2 
make: *** [Makefile:118: DeSNN_CPP] Error 2 

我不知道這裏發生了什麼。有關如何克服這個問題的任何想法?

更新

我設法得到以下完成,但仍然無法找到庫

Warning:start running cmake... 
Warning:Setting up BOOST 
Warning:Includes - C:/Users/aksha/Desktop/boost_1_62_0 
Warning:Library - C:/Users/aksha/Desktop/boost_1_62_0/stage/lib 
+0

你沒加編譯Boost庫到項目庫來鏈接的列表。你在哪裏pu他們? – xaxxon

+0

@xaxxon我加了,請看我的更新。 – Akshay

回答

0

你告訴它到哪裏尋找庫文件,但沒有告訴它哪些是要尋找的。

您需要

target_link_libraries(DeSNN_CPP ...list of boost libraries...) 

添加到您的CMakeLists.txt文件

+0

所以我只是鍵入,例如'target_link_libraries(DeSNN_CPP文件系統)'? – Akshay

+0

它可能是boost_filesystem,但是。你可以根據需要連續分隔空間。你可能也需要boost_system,看看你的錯誤信息。 – xaxxon

+0

沒有不工作。我得到這個錯誤 - '/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld:找不到-lboost_system /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld:can not find -lboost_filesystem' – Akshay