Multithreading OpenBSD eg++;4.9.3:启用多线程以使用std::thread:不允许操作

Multithreading OpenBSD eg++;4.9.3:启用多线程以使用std::thread:不允许操作,multithreading,c++11,g++,pthreads,openbsd,Multithreading,C++11,G++,Pthreads,Openbsd,当尝试在OpenBSD上用端口树中的g++(例如++)编译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=/u

当尝试在OpenBSD上用端口树中的g++(例如++)编译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
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 ?? ()
然后我得到:

terminate called after throwing an instance of 'std::system_error'
what():  Enable multithreading to use std::thread: Operation not permitted
Abort trap (core dumped)
这似乎只有在使用g++4.9.3的OpenBSD6.0上才能从端口复制。不能使用内置的g++编译代码,因为代码需要C++11

回溯如下所示:

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
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)下也可以正确编译和工作


我读过一些类似的问题,说这是一个编译器错误,但他们为它提供的黑客“修复”似乎对这种情况没有帮助(使用
-Wl,--no-as-needed
)。

您将代码链接到
libstdc++
。您应该改用
libestdc++

AFAIK GCC的4版默认使用旧的C++98标准(带有GCC扩展)
std::thread
是C++11的一个特性(正如您正确地说的)。这意味着您需要使用
-std=c++11
标志进行构建。你是用那面旗子建造的吗?在编译和链接时,您可能还需要使用
-pthread
标志,以确保启用POSIX线程。您也使用该标志进行构建吗?是的,我正在使用Makefile.am中的
ansvif\u LDFLAGS=-I./include/gzstream-I./include/xml\u writer-I./src/linux-pthread
和configure.ac文件中的
AX\u CXX\u COMPILE\u STDCXX\u 11
进行构建。在编译时,您可以看到它正在使用-pthread和-std=c++11。谢谢,这似乎是可行的,尽管我在修改Makefile.am时也发现了另一个错误。一个
else
没有达到预期的目的,因此一些代码根本没有传递给编译器。你把我引向正确的方向!由于您的帮助,您在ansvif Wiki上获得了荣誉称号!