【问题标题】:OpenGL Link Error for GLFW DDS Load functionGLFW DDS 加载功能的 OpenGL 链接错误
【发布时间】:2020-01-25 16:47:55
【问题描述】:

我一直在学习 OpenGL-tutorial.org 教程系列。一切工作正常,但是我无法让教程 5 在我的操场可执行文件中工作,尽管从示例教程 5 可执行文件运行时它确实可以工作。即使我复制并粘贴示例代码也是如此。

我收到以下错误:

Undefined symbols for architecture x86_64:



"loadDDS(char const*)", referenced from:

_main in playground.o

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

以下是链接日志:

Ld playground/playground normal x86_64
cd /Users/RufusVijayaratnam/rufus/Coding/ogl-master
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.15 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground -F/Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground -filelist /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground_lto.o -Xlinker -no_deduplicate -Wl,-search_paths_first -Wl,-headerpad_max_install_names -framework OpenGL -framework OpenGL /Users/RufusVijayaratnam/rufus/Coding/OpenGL/external/glfw-3.1.2/src/Debug/libglfw3.a /Users/RufusVijayaratnam/rufus/Coding/OpenGL/external/Debug/libGLEW_1130.a -framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo -Xlinker -dependency_info -Xlinker /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground_dependency_info.dat -o /Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground/playground

所以错误似乎是在调用函数loadDDS()时找不到它。我不确定这是为什么。该函数与texture.hpp 一起在文件夹(称为“common”)中的texture.ccp 中声明。 texture.hpp 代码如下:

#ifndef TEXTURE_HPP
#define TEXTURE_HPP
// Load a .DDS file using GLFW's own loader
GLuint loadDDS(const char * imagepath);

#endif

playground.cpp 中有:

include<texture.hpp>

为什么找不到loadDDS(),即使我已经将playground函数的工作目录设置为和教程5一样,playground.ccp和'tutorial05.ccp'中的代码正是一样吗?

【问题讨论】:

  • “从尝试寻找解决方案来看,导致问题的原因似乎是未链接 GLFW 库。”你是怎么得出这样的结论的? GLuint loadDDS(const char * imagepath)是教程自己提供的功能。
  • @derhass 是的,确实如此,我无法为这种情况找到解决方案,但是正是“未定义的建筑符号”部分让我能够找到有类似问题的人,常见的建议解决方案是未链接的库。
  • 错误信息明确指出您的main 函数调用了一个找不到的名为loadDDS 的函数。而且该函数根本不是任何库的一部分,它在教程中作为源代码提供,应该复制到您的代码中。
  • @derhass 哦,谢谢。我不知道错误是什么意思。虽然在代码中它包含与教程 5 中完全相同的头文件,并且我已经正确设置了工作目录,所以我不确定它是如何找不到函数的。

标签: c++ xcode opengl linker glfw


【解决方案1】:

对于操场可执行文件(不起作用)

# User playground add_executable(playground 
    playground/playground.cpp
    common/shader.cpp
    common/shader.hpp )

最后是教程 5(确实有效)

# Tutorial 5
add_executable(tutorial05_textured_cube
    tutorial05_textured_cube/tutorial05.cpp
    common/shader.cpp
    common/shader.hpp
    common/texture.cpp
    common/texture.hpp

所以我有根据地猜测loadDDS() 是在texture.cpp 中实现的,并且由于您没有添加此文件,因此不会编译它,并且不会链接生成的目标文件,并且只是找不到符号。

【讨论】:

  • 非常感谢,您说得对。更新 CMakeLists.txt 以在 Playground 可执行文件生成中包含 common/texture.cpp 和 common/texture.hpp 解决了该问题。
猜你喜欢
  • 1970-01-01
  • 2014-03-27
  • 1970-01-01
  • 2010-12-15
  • 1970-01-01
  • 2013-07-20
  • 1970-01-01
  • 2014-08-12
  • 2018-07-26
相关资源
最近更新 更多