简体   繁体   English

GLEW + cmake链接失败“未定义引用符号glDrawElements”+“DSO从命令行中丢失”

[英]GLEW + cmake linking fails “undefined reference to symbol glDrawElements” + “DSO missing from command line”

I'm linking GLEW, SDL2 and Assimp with Cmake. 我将GLEW,SDL2和Assimp与Cmake联系起来。 It seems to be working fine while building the .o files, however when linking them I get these errors 它在构建.o文件时似乎工作正常,但是当链接它们时,我得到了这些错误

:-1: error: CMakeFiles/"Projectpath".cpp.o: undefined reference to symbol 'glDrawElements'
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1:-1: error: error adding symbols: DSO missing from command line
:-1: error: collect2: error: ld returned 1 exit status

Here's the part of the Cmakefile that links the libraries 这是链接库的Cmakefile的一部分

find_package(OpenGL)
find_package(GLEW)
find_package(SDL2)
find_package(Assimp)
#Include(FindPkgConfig)
#PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
set(INCLUDE_DIRS ${OpenGL_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS} ${Assimp_INCLUDE_DIRS})
set(LIBS ${LIBS} ${OpenGL_LIBRARIES} ${SDL2_LIBRARIES} ${GLEW_LIBRARIES} ${Assimp_LIBRARIES} )
include_directories(${INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME} ${LIBS})

I tried changing the linking order as I read that could be a problem. 当我读到这可能是一个问题时,我尝试更改链接顺序。 I also added the OpenGL thing because of the libGL thing in the error, it doesn't seem to work. 我还添加了OpenGL的东西因为错误中的libGL事情,它似乎不起作用。 I also read about checking dependencies using pkg-config --print-requires --print-requires-private glew , but the problem is that it has like 20 different libraries it depends on. 我还读到了使用pkg-config --print-requires --print-requires-private glew检查依赖关系,但问题是它有20个不同的库依赖它。 Would I need to link all of them? 我需要链接所有这些吗?

It's not that I don't have the correct libraries, I created a basic OpenGL program on this computer last week and that worked fine (I used another way of linking my libraries and also used Code::Blocks instead of Qt-Creator) 这不是我没有正确的库,我上周在这台计算机上创建了一个基本的OpenGL程序,并且运行正常(我使用了另一种链接我的库的方法,也使用了Code :: Blocks而不是Qt-Creator)

I assume that the DSO thing is the problem after reading the answer to this question . 我认为在阅读了这个问题的答案后,DSO就是问题所在 But shouldn't that mean that doing the OpenGL thing in the cmakefile fix it? 但是,这不应该意味着在cmakefile中执行OpenGL操作会修复它吗?

Thanks! 谢谢!

EDIT: I can create VertexArrays, VertexBuffers etc. But as soon as I add in calls to either. 编辑:我可以创建VertexArrays,VertexBuffers等。但是只要我添加调用。 glDrawElements(...) or glDrawArrays(...) I get that error. glDrawElements(...)glDrawArrays(...)我得到了那个错误。 (I might get that error on some other functions as well, but those are the only ones I get that error on when I try to render a basic mesh) (我可能会在其他一些函数上得到错误,但是当我尝试渲染基本网格时,这些是我唯一得到的错误)

The problem was that in OpenGL_INCLUDE_DIRS and OpenGL_LIRARIES is actually OPENGL_INCLUDE_DIRS (<-- not quite sure I need that one, I probably don't) and OPENGL_LIBRARY So the CmakeFile snippet I had in my question should actually look like this 问题是在OpenGL_INCLUDE_DIRS和OpenGL_LIRARIES实际上是OPENGL_INCLUDE_DIRS(< - 不太确定我需要那个,我可能不会)和OPENGL_LIBRARY所以我在我的问题中的CmakeFile片段应该看起来像这样

find_package(OpenGL)
find_package(GLEW)
find_package(SDL2)
find_package(Assimp)
#Include(FindPkgConfig)
#PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS} ${Assimp_INCLUDE_DIRS}) #<--- Changed this from ${OpenGL_INCLUDE_DIRS} to ${OPENGL_INCLUDE_DIRS} (Again not sure I need that variable)
set(LIBS ${LIBS} ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${GLEW_LIBRARIES} ${Assimp_LIBRARIES} ) #<---(Changed this from ${OpenGL_LIBRARIES} to ${OPENGL_LIBRARY}
include_directories(${INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME} ${LIBS})

And that fixed it! 那就解决了! :) :)

I got a similar issue configuring GLEW, with CMake, applying to the basic tutorial #2 from http://www.opengl-tutorial.org for testing purpose. 我在使用CMake配置GLEW时遇到了类似的问题,应用http://www.opengl-tutorial.org的基础教程#2进行测试。

I am using GLFW instead of SDL, but the root cause is the same. 我使用的是GLFW而不是SDL,但根本原因是一样的。

With recent CMake (>= 3.1), we simply need: 最近的CMake(> = 3.1),我们只需要:

find_package(OpenGL REQUIRED)
target_link_libraries( myApp OpenGL::GL )

find_package ( GLEW REQUIRED )
target_link_libraries( myApp GLEW::GLEW )   

As you pointed out, we got an "undefined reference" issue if not looking for openGL. 正如您所指出的,如果不寻找openGL,我们会遇到“未定义的引用”问题。

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

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