我使用boost文件系统库编写了一个简单的程序。我链接到libboost_filesystem
但是我得到了未定义的引用链接错误
这是我的CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(client)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")
add_executable(client main.cpp UploadWorker.cpp FileSystemWatcher.cpp)
target_link_libraries(client boost_filesystem boost_system pthread)
我尝试了其他主题中的所有解决方案,但没有一个是有帮助的。
这是我的错误:
-- The C compiler identification is GNU 5.4.1
-- The CXX compiler identification is GNU 4.9.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /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: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/saeed/projects/threads/Debug
Scanning dependencies of target client
Scanning dependencies of target server
[ 50%] Building CXX object server/CMakeFiles/server.dir/main.cpp.o
[ 50%] Building CXX object client/CMakeFiles/client.dir/main.cpp.o
[ 50%] Building CXX object client/CMakeFiles/client.dir/UploadWorker.cpp.o
[ 66%] Building CXX object client/CMakeFiles/client.dir/FileSystemWatcher.cpp.o
[ 83%] Linking CXX executable server
[ 83%] Built target server
[100%] Linking CXX executable client
CMakeFiles/client.dir/FileSystemWatcher.cpp.o: In function `boost::filesystem::path::path<boost::filesystem::directory_entry>(boost::filesystem::directory_entry const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>, void>::type*)':
/usr/include/boost/filesystem/path.hpp:140: undefined reference to `boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::string&)'
collect2: error: ld returned 1 exit status
client/CMakeFiles/client.dir/build.make:146: recipe for target 'client/client' failed
make[2]: *** [client/client] Error 1
CMakeFiles/Makefile2:85: recipe for target 'client/CMakeFiles/client.dir/all' failed
make[1]: *** [client/CMakeFiles/client.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
我的机器是Ubuntu 16.04,g ++ v4.9.4和boost v1.58。