- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我试图为 Boost 库编译以下简单的线程示例:
#include <iostream>
#include <boost/thread.hpp>
#include <boost/chrono.hpp>
using namespace std;
void thread()
{
for (int i = 0; i < 5; ++i)
{
cout << i << '\n';
}
}
int main()
{
boost::thread t{thread};
t.join();
}
使用
g++ -std=c++11 -I /usr/local/boost_1_57_0 simpleThreadExample.cpp
然后编译器把这个还给我:
Undefined symbols for architecture x86_64:
"boost::detail::thread_data_base::~thread_data_base()", referenced from:
boost::detail::thread_data<void (*)()>::~thread_data() in simpleThreadExample-7cec5e.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in simpleThreadExample-7cec5e.o
boost::thread_exception::thread_exception(int, char const*) in simpleThreadExample-7cec5e.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in simpleThreadExample-7cec5e.o
___cxx_global_var_init1 in simpleThreadExample-7cec5e.o
"boost::thread::join_noexcept()", referenced from:
boost::thread::join() in simpleThreadExample-7cec5e.o
"boost::thread::native_handle()", referenced from:
boost::thread::get_id() const in simpleThreadExample-7cec5e.o
"boost::thread::start_thread_noexcept()", referenced from:
boost::thread::start_thread() in simpleThreadExample-7cec5e.o
"boost::thread::detach()", referenced from:
boost::thread::~thread() in simpleThreadExample-7cec5e.o
"typeinfo for boost::detail::thread_data_base", referenced from:
typeinfo for boost::detail::thread_data<void (*)()> in simpleThreadExample-7cec5e.o
"vtable for boost::detail::thread_data_base", referenced from:
boost::detail::thread_data_base::thread_data_base() in simpleThreadExample-7cec5e.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)
现在,下面两个程序可以正常编译和运行:
#include <locale>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace std;
using namespace boost::gregorian;
using namespace boost::posix_time;
int main()
{
date today = day_clock::local_day();
cout << today << endl;
}
和
#include <iostream>
#include <iomanip>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
using namespace std;
int main()
{
//point_type p = boost::geometry::make<point_type>(1, 2, 3);
//std::cout << boost::geometry::dsv(p) << std::endl;
//return 0;
boost::geometry::model::point<int, 3, boost::geometry::cs::cartesian> p;
boost::geometry::assign_values(p,1, 2, 3);
boost::geometry::model::point<int, 3, boost::geometry::cs::cartesian> p2;
p2 = p;
cout << boost::geometry::dsv(p) << endl;
cout << boost::geometry::dsv(p2) << endl;
return 0;
}
而且,当我编译时,我会:
g++ -std=c++11 -I /usr/local/boost_1_57_0 <nameOfProgram.cpp>
所以,我想知道为什么线程程序无法编译而其他两个程序可以编译,而我唯一要更改的是程序的名称?
如果有帮助,我正在使用 Boost 1.57,它的路径是:
/usr/local/Cellar/boost/1.57.0
头文件的路径是:
/usr/local/Cellar/boost/1.57.0/include/boost
如果有人能提供一些见解,那就太好了。谢谢!
最佳答案
你也必须链接到 boost 库:
-lboost_thread
可能有额外的 -L
路径参数,也可能是标准的 -lpthread
。
关于c++ - Boost C++ 架构 x86_64 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29542337/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!