【发布时间】:2017-03-24 12:10:29
【问题描述】:
当尝试使用端口树中的 g++(例如 ++)在 OpenBSD 上编译 ansvif(模糊器)时,一切都可以正常配置和编译,直到我在需要线程的地方实际运行程序。
我尝试这样编译:
AUTOCONF_VERSION=2.69 AUTOMAKE_VERSION=1.15 aclocal
AUTOCONF_VERSION=2.69 AUTOMAKE_VERSION=1.15 autoconf
AUTOCONF_VERSION=2.69 AUTOMAKE_VERSION=1.15 automake -a
CXX=/usr/ports/pobj/gcc-4.9.3/bin/eg++ ./configure
make
然后我得到:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Abort trap (core dumped)
这似乎只能在 ports 使用 g++ 4.9.3 的 OpenBSD 6.0 上重现。您无法使用内置 g++ 编译代码,因为代码需要 C++11。
回溯如下所示:
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-unknown-openbsd6.0".
Core was generated by `ansvif'.
Program terminated with signal 6, Aborted.
#0 0x00000a5d2326029a in ?? ()
(gdb) bt
#0 0x00000a5d2326029a in ?? ()
#1 0x00000a5d23274039 in ?? ()
#2 0x00000a5d23280c0a in ?? ()
#3 0x00000a5a441cea80 in ?? ()
#4 0xffffffdf00000202 in ?? ()
#5 0xf296d56c8d2c4acf in ?? ()
#6 0x00000a5c54dc0198 in ?? ()
#7 0x00000a5a43d8b165 in ?? ()
#8 0x0000000000000000 in ?? ()
在 Linux 和 Windows(使用 MinGW)下,相同的编译和工作正常。
我读过一些类似的问题,说它是一个编译器错误,但在这种情况下,他们在 SO 上为其提供的骇人听闻的“修复”似乎没有帮助(使用 -Wl,--no-as-needed)。
【问题讨论】:
-
AFAIK GCC 4 版本默认使用旧的 C++98 标准(带有 GCC 扩展)。
std::thread是一个 C++11 特性(正如你所说的那样)。这意味着您需要使用-std=c++11标志进行构建。你用那面旗帜建造吗?您可能还需要在编译和链接时都使用-pthread标志,以确保启用 POSIX 线程。你也用那个标志建造吗? -
是的,我正在使用 Makefile.am 中的
ansvif_LDFLAGS = -I./include/gzstream -I./include/xml_writer -I./src/linux -pthread和 configure.ac 文件中的AX_CXX_COMPILE_STDCXX_11构建。在编译时,您可以看到它正在使用 -pthread 和 -std=c++11。
标签: multithreading c++11 g++ pthreads openbsd