[英]Using shared_ptr and glutInit causes segmentation fault
Having asked this before I tried out a lot of things and found out that the problem has to do with glutInit. 在我尝试了很多事情之前问过这个问题并发现问题与glutInit有关。 Take the following code examples: main.cpp
请使用以下代码示例:main.cpp
#include <iostream>
#include <memory>
#include<GL/glut.h>
using namespace std;
int main(int argcp, char **argv)
{
shared_ptr<double> abc;
glutInit(&argcp,argv);
cout<<"Hello!"<<endl;
return 0;
}
compiled with: 编译:
g++ -std=c++11 -g -Wall -o appx main.cpp -lGL -lGLU -lglut
g ++ -std = c ++ 11 -g -Wall -o appx main.cpp -lGL -lGLU -lglut
cause the executable to instantly crash (no "Hello!" output) with segfault using g++ 5.2.1, ubuntu 15.10 导致可执行文件使用g ++ 5.2.1,ubuntu 15.10使用segfault立即崩溃(没有“Hello!”输出)
Just commenting out the line 只是评论出这条线
shared_ptr<double> abc;
will fix the crash. 将解决崩溃。
Since i want to use shared_ptr and glut in a project I would like to know how this can be fixed or what causes the crash. 由于我想在项目中使用shared_ptr和glut,我想知道如何解决这个问题或者导致崩溃的原因。
Edit 1: GDB trace: 编辑1: GDB跟踪:
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff33fb6fd in init () at dlerror.c:177
#2 _dlerror_run (operate=operate@entry=0x7ffff33fb0e0 <dlsym_doit>,args=args@entry=0x7fffffffde00) at dlerror.c:129
#3 0x00007ffff33fb148 in __dlsym (handle=<optimized out>, name=optimized out>) at dlsym.c:70
#4 0x00007ffff6fa2e1e in ?? () from /usr/lib/nvidia-352/libGL.so.1
#5 0x00007ffff6f4db47 in ?? () from /usr/lib/nvidia-352/libGL.so.1
#6 0x00007ffff7de957d in call_init (l=0x7ffff7fc59c8,argc=argc@entry=1, argv=argv@entry=0x7fffffffdf58, env=env@entry=0x7fffffffdf68)at dl-init.c:58
#7 0x00007ffff7de96cb in call_init (env=<optimized out>, argv=<optimized out>, argc=<optimized out>, l=<optimized out>) at dl-init.c:30
#8 _dl_init (main_map=0x7ffff7ffe188, argc=1, argv=0x7fffffffdf58, env=0x7fffffffdf68) at dl-init.c:120
#9 0x00007ffff7dd9d0a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#10 0x0000000000000001 in ?? ()
#11 0x00007fffffffe2c8 in ?? ()
#12 0x0000000000000000 in ?? ()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.