链接OpenCL会导致Segfault

时间:2016-05-14 19:02:38

标签: c++ gcc segmentation-fault opencl nvidia

在尝试运行一个简单的opencl程序时,我在链接opencl时遇到了段错误。我设法将源减少到:

#include <string>
#include <iostream>
int main() {
    const std::string str = "this causes a segfault\n";
    return 0;
}

使用此命令进行编译:

g++ -g -std=c++14 -I/opt/cuda/include reduced.c++ -L/opt/cuda/lib64 -o reduced -lOpenCL

使用此编译器:

g++ (Funtoo 4.9.3-r3) 4.9.3

关于funtoo。这是回溯:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff793acf1 in std::locale::_S_initialize() () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6
#2  0x00007ffff793ad33 in std::locale::locale() () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6
#3  0x00007ffff7937b44 in std::ios_base::Init::Init() () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6
#4  0x00000000004009e9 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/iostream:74
#5  0x0000000000400a12 in _GLOBAL__sub_I_main () at reduced.c++:6
#6  0x0000000000400a65 in __libc_csu_init ()
#7  0x00007ffff703df3f in __libc_start_main () from /lib64/libc.so.6
#8  0x0000000000400889 in _start ()

使用g++ -g -std=c++14 reduced.c++ -o reduce进行编译会导致程序停止segfaulting。我的显卡是一个nvidia 560 Ti,我在gentoo-sources的4.5.2内核上运行专有nvidia驱动程序的版本364.19

我最初认为这是一个abi问题但据我所知,std::string abi在5.0.0处发生了变化。使用clang进行编译可以防止这个简化示例中的segfaulting,但不能在我的原始程序中进行。

为什么会发生这种情况,我该如何解决?

编辑:我尝试过像这样重新生成语言环境:

elliot@funbox ~> sudo locale-gen
 * Generating locale-archive: forcing # of jobs to 1
 * Generating 2 locales (this might take a while) with 1 jobs
 *  (1/2) Generating en_GB.UTF-8 ...                                                                                                 [ ok ]
 *  (2/2) Generating en_US.UTF-8 ...                                                                                                 [ ok ]
 * Generation complete
elliot@funbox ~

它不会阻止段错误的发生。

0 个答案:

没有答案