如何解决“架构x86_64的未定义符号:” Boost 1.73.0 Clion MacOS
我是C ++的超级新手,刚开始涉足Boost C ++库
我目前在MacOS Catalina上,并使用CLion作为我的c ++ IDE。
我使用自制软件brew install boost
我正在关注以下的一些教程:http://antonym.org/2009/05/threading-with-boost-part-i-creating-threads.html了解boost::thread
代码如下:
#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
void workerFunc()
{
boost::posix_time::seconds workTime(3);
std::cout << "Worker: running" << std::endl;
// Pretend to do something useful...
boost::this_thread::sleep(workTime);
std::cout << "Worker: finished" << std::endl;
}
int main(int argc,char* argv[])
{
std::cout << "main: startup" << std::endl;
boost::thread workerThread(workerFunc);
std::cout << "main: waiting for thread" << std::endl;
workerThread.join();
std::cout << "main: done" << std::endl;
return 0;
}
这是我的CMakeLists.txt
文件
cmake_minimum_required(VERSION 3.17)
project(cpp_boost)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost 1.73.0 COMPONENTS system filesystem required)
include_directories(${Boost_INCLUDE_Dirs})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
====================[ Build | cpp_boost | Debug ]===============================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/parvpatel/Desktop/development/dev-projects/lang-tutorials/cpp-tutorials/cpp-boost/cmake-build-debug --target cpp_boost -- -j 12
[ 50%] Building CXX object CMakeFiles/cpp_boost.dir/main.cpp.o
[100%] Linking CXX executable cpp_boost
Undefined symbols for architecture x86_64:
"boost::this_thread::interruption_point()",referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in main.cpp.o
boost::condition_variable::do_wait_until(boost::unique_lock<boost::mutex>&,boost::detail::real_platform_timepoint const&) in main.cpp.o
"boost::detail::thread_data_base::~thread_data_base()",referenced from:
boost::detail::thread_data<void (*)()>::~thread_data() in main.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 main.cpp.o
"boost::thread::join_noexcept()",referenced from:
boost::thread::join() in main.cpp.o
"boost::thread::native_handle()",referenced from:
boost::thread::get_id() const in main.cpp.o
"boost::thread::start_thread_noexcept()",referenced from:
boost::thread::start_thread() in main.cpp.o
"boost::thread::detach()",referenced from:
boost::thread::~thread() in main.cpp.o
"typeinfo for boost::detail::thread_data_base",referenced from:
typeinfo for boost::detail::thread_data<void (*)()> in main.cpp.o
"vtable for boost::detail::thread_data_base",referenced from:
boost::detail::thread_data_base::thread_data_base() in main.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]: *** [cpp_boost] Error 1
make[2]: *** [CMakeFiles/cpp_boost.dir/all] Error 2
make[1]: *** [CMakeFiles/cpp_boost.dir/rule] Error 2
make: *** [cpp_boost] Error 2
我试图浏览互联网,但找不到任何具体内容。我发现它对target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
很有用,但是将其添加到CMakeLists.txt
文件后,错误仍然存在。
任何帮助将不胜感激。
谢谢:)
解决方法
谢谢一些程序员花花公子
它只是向find_package添加thread
使其起作用
这是更新的CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
project(cpp_boost)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost 1.73.0 COMPONENTS system filesystem thread REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。