使用SOIL2加载贴图报错 undefined referenc

2021-09-09  本文已影响0人  playboy

最近向工程添加了SOIL2静态库,执行make命令的时候报如下链接错误:

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1474: undefined reference to `glGetIntegerv'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1656: undefined reference to `glGenTextures'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1711: undefined reference to `glBindTexture'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1715: undefined reference to `glGetIntegerv'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1718: undefined reference to `glPixelStorei'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1748: undefined reference to `glTexImage2D'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1758: undefined reference to `glTexImage2D'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1773: undefined reference to `glTexParameteri'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1774: undefined reference to `glTexParameteri'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1779: undefined reference to `glTexParameteri'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1780: undefined reference to `glTexParameteri'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1787: undefined reference to `glPixelStorei'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1793: undefined reference to `glTexParameteri'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1794: undefined reference to `glTexParameteri'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1798: undefined reference to `glTexParameteri'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1805: undefined reference to `glTexParameteri'

/home/sin/workspace/fairy/SOIL2/make/linux/../../src/SOIL2/SOIL2.c:1806: undefined reference to `glTexParameteri'

百度、google一番,发现如下一个解决方法:

You need to link to the GL library. What you need is to add the -lGL in your linker options. Likewise if you need glut or glu library functions you want -lglut -lglu respectively.

The trick is to remember that if you use any functions from included header files that come from other sources you need to link to the library containing the function definition. This excludes the C++ standard library as this is done automatically by your compiler.

EDIT: and ensure these libraries exist, likely in /usr/lib

参考链接:c++ - Undefined Reference to OpenGL functions! [SOLVED] | DaniWeb

于是在CMakeLists文件中的target_link_libraries中添加GL,就可以成功链接了。

project(test_texture)

file(

        GLOB_RECURSE TEST_TEXTURE_SRCS

        test_texture.cpp

)

add_executable(test_texture ${TEST_TEXTURE_SRCS})

target_link_libraries(test_texture render glfw ${SOIL2_PATH} GL)

注意:就是最后这个GL

上一篇 下一篇

猜你喜欢

热点阅读