使用shared_ptr和glutInit导致分段错误 [英] Using shared_ptr and glutInit causes segmentation fault

查看:287
本文介绍了使用shared_ptr和glutInit导致分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我尝试了很多事情之前,我问过这个这个问题与glutInit有关。请看下面的代码示例:
main.cpp

Having asked this before I tried out a lot of things and found out that the problem has to do with glutInit. Take the following code examples: 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;
}

编译:

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

导致可执行文件使用g ++ 5.2.1,ubuntu 15.10立即崩溃(没有Hello!输出)

cause the executable to instantly crash (no "Hello!" output) with segfault using g++ 5.2.1, ubuntu 15.10

只是注释掉行

shared_ptr<double> abc;

将修复崩溃。

我想在一个项目中使用shared_ptr和glut。我想知道如何解决这个问题或导致崩溃的原因。

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.

编辑1:
GDB trace:

Edit 1: GDB trace:

#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 ?? ()


推荐答案

对问题在这里

解决方案添加:

 -lpthread

到编译器标志!
非常感谢!

to the compiler flags! Thanks a lot!

这篇关于使用shared_ptr和glutInit导致分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆