最近向工程添加了SOIL2靜態(tài)庫,執(zhí)行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一番囚灼,發(fā)現(xiàn)如下一個解決方法:
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