简体   繁体   English

OpenGL编译错误Ubuntu

[英]OpenGL Compilation Errors Ubuntu

I'm trying to set up the code from http://www.openglsuperbible.com/example-code/ 我正在尝试从http://www.openglsuperbible.com/example-code/设置代码

with command: 使用命令:

$ cmake -G "Unix Makefiles" ; make clean ; make all

I've installed the following packages in order to prepare the system: 我已经安装了以下软件包以准备系统:

xrandr libxrandr x11-xserver-utils libxrandr-dev libglfw2 libglfw-dev xorg-dev libx11-dev libgl-dev libglu-dev libgl1-mesa-dev freeglut3 freeglut3-dev mesa-common-dev freeglut3-dev build-essential libx11-dev libx11-*

I may have missed some of the packages I've installed in this list, I apologize. 抱歉,我可能错过了此列表中安装的某些软件包。

Then I've modified the CMakeList.txt in order to add to the linking phase the following things: 然后,我修改了CMakeList.txt,以将以下内容添加到链接阶段:

glfw GL rt glut X11 dl Xrandr Xext GLEW GLU

Then I try to compile, but it fails at the linking phase: 然后,我尝试进行编译,但是在链接阶段失败:

/opt/sb6code/src/xraw/xraw.c: In function ‘CreateWindow’:
/opt/sb6code/src/xraw/xraw.c:106:14: warning: assignment makes pointer from integer without a cast [enabled by default]
Linking C executable bin/xraw
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XOpenDisplay'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCloseDisplay'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCreateColormap'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCreateWindow'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XMapWindow'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'glXCreateContextAttribsARB'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function Cleanup: error: undefined reference to 'XDestroyWindow'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function Cleanup: error: undefined reference to 'XCloseDisplay'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function main: error: undefined reference to 'XNextEvent'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function main: error: undefined reference to 'XGetWindowAttributes'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/xraw] Errore 1
make[1]: *** [CMakeFiles/xraw.dir/all] Errore 2
make: *** [all] Errore 2

Now, I've tried to search the web and even here on SO.com for solutions, but they keep telling me to link the libraries I've already added to the linking phase.. so I can't seem to make any more progress. 现在,我试图在网上甚至在SO.com上搜索解决方案,但它们一直告诉我链接我已经添加到链接阶段的库。.所以我似乎再也做不了了。进展。

Do you happen to have some knowledge or hint that could help me? 您碰巧有一些可以帮助我的知识或提示吗?


Ok, stimulated by answers I've gone into CMakeFiles directory and looked for the configuration file that manages the compilation. 好的,受答案的刺激,我进入了CMakeFiles目录,并寻找管理编译的配置文件。 I've found out that for some reasons it did miss some of the flags stated into the CMakeLists despite of my update. 我发现由于某些原因,尽管我进行了更新,但它确实错过了CMakeLists中声明的一些标志。

So now the compilation line looks like: 现在,编译行如下所示:

/usr/bin/cc      CMakeFiles/xraw.dir/src/xraw/xraw.c.o  -o bin/xraw  -L/opt/sb6code/lib -rdynamic -lGL -lglut -lGLU -lm -lX11 -ldl -lGLEW -lXrandr -lXext -lrt -lglfw -Wl,-rpath,/opt/sb6code/lib 

And the errors have reduced to : 并且错误已减少为:

CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'glXCreateContextAttribsARB'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/xraw] Errore 1
make[1]: *** [CMakeFiles/xraw.dir/all] Errore 2
make: *** [all] Errore 2

Other hints? 其他提示? :) :)

Side Note: I've also installed CUDA libraries and under path 旁注:我还安装了CUDA库,并在路径下

/usr/lib/nvidia-304/

I happen to have 我碰巧有

alt_ld.so.conf                libnvidia-ml.so.1
bin/                          libnvidia-ml.so.304.88
ld.so.conf                    libnvidia-opencl.so.1
libcuda.so                    libnvidia-opencl.so.304.88
libcuda.so.1                  libnvidia-tls.so.304.88
libcuda.so.304.88             libnvidia-wfb.so.1
libGL.so                      libnvidia-wfb.so.304.88
libGL.so.1                    libOpenCL.so
libGL.so.304.88               libOpenCL.so.1
libnvcuvid.so                 libOpenCL.so.1.0
libnvcuvid.so.1               libOpenCL.so.1.0.0
libnvcuvid.so.304.88          libXvMCNVIDIA_dynamic.so.1
libnvidia-cfg.so              libXvMCNVIDIA.so
libnvidia-cfg.so.1            libXvMCNVIDIA.so.1
libnvidia-cfg.so.304.88       libXvMCNVIDIA.so.304.88
libnvidia-compiler.so         tls/
libnvidia-compiler.so.1       vdpau/
libnvidia-compiler.so.304.88  xorg/
libnvidia-glcore.so.304.88    XvMCConfig
libnvidia-ml.so  

Which I would like to use since I'm not sure that my intel graphic card supports OpenGl 4.* which I shall use with the book, while the nvidia one supports 4.2. 我想使用它,因为我不确定我的英特尔图形卡是否支持OpenGl 4。*(我将在本书中使用),而nvidia则支持4.2。

I really can't find any good how to on the matter, the Book conveniently avoids to give installation instructions. 关于此事,我真的找不到任何好方法,该书方便地避免给出安装说明。


Temporary Solution: I've found out that this is the only source file that does not work. 临时解决方案:我发现这是唯一不起作用的源文件。 Removing its files and CMakeList.txt configuration seems to be wise until someone finds out another solution. 除非有人找到其他解决方案,否则删除其文件和CMakeList.txt配置似乎是明智的。

Also, i had to use optirun to run the executables, in case other people with bumblebee/nvidia are wondering why their programs do not work. 另外,如果其他有大黄蜂/ nvidia的人想知道为什么他们的程序不起作用,我必须使用optirun运行可执行文件。

You probably link the libraries in wrong order; 您可能以错误的顺序链接库; all these symbols are defined in libX11.a ; 所有这些符号libX11.a 定义; you should want to see what is the actual linking command line fed to GCC, and post it here. 您应该要查看输入到GCC的实际链接命令行是什么,并将其发布在此处。

Update now it means that you are statically trying to link against an API function that is not available in your libs (it is an optional extension and should be queried dynamically). 立即更新,这意味着您正在静态尝试链接您的库中不可用的API函数(它是可选扩展,应动态查询)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM