微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

“架构x86_64的未定义符号:” Boost 1.73.0 Clion MacOS

如何解决“架构x86_64的未定义符号:” Boost 1.73.0 Clion MacOS

我是C ++的超级新手,刚开始涉足Boost C ++库

我目前在MacOS Catalina上,并使用CLion作为我的c ++ IDE。

我使用自制软件brew install boost

安装了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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?