【发布时间】:2014-11-02 21:04:24
【问题描述】:
TL;DR:
我如何从拥有 DerelictGL3 等的源代码到使用 GDC 链接到它?
详细投诉:
我有一个用 D 编写的小程序。(http://dlang.org)
module controller;
import std.stdio;
import std.conv;
import std.exception;
import derelict.opengl3.gl3;
import derelict.glfw3.glfw3;
void main()
{
DerelictGL3.load();
DerelictGLFW3.load();
if(!glfwInit())
throw new Exception("Failure");
scope(exit) glfwTerminate();
}
我正在尝试使用以下命令构建此程序。 (我在linux上。)
gdc -o "${BLD}controller" \
"/home/user/Source/d/controller.d" \
"-I/home/user/Source/DerelictOrg/DerelictUtil/source/" \
"-I/home/user/Source/DerelictOrg/DerelictGL3/source/" \
"-I/home/user/Source/DerelictOrg/DerelictGLFW3/source/" \
-I/usr/include/d2 \
-L -lDerelictUtil \
-L -lDerelictGL3 \
-L -lDerelictGLFW3 \
-L -ldl
我收到以下错误消息。
controller.d:(.text+0x3b): undefined reference to
`_D8derelict7opengl33gl311DerelictGL3C8derelict7opengl33gl317DerelictGL3Loader'
controller.d:(.text+0x4c): undefined reference to
`_D8derelict7opengl33gl311DerelictGL3C8derelict7opengl33gl317DerelictGL3Loader'
controller.d:(.text+0x58): undefined reference to
`_D8derelict5glfw35glfw313DerelictGLFW3C8derelict5glfw35glfw319DerelictGLFW3Loader'
controller.d:(.text+0x69): undefined reference to
`_D8derelict5glfw35glfw313DerelictGLFW3C8derelict5glfw35glfw319DerelictGLFW3Loader'
controller.d:(.text+0x75): undefined reference to
`_D8derelict5glfw35glfw38glfwInitPUNbZi'
controller.d:(.text+0xf7): undefined reference to
`_D8derelict5glfw35glfw313glfwTerminatePUNbZv'
/tmp/ccTqE9NN.o:(.data+0x28): undefined reference to
`_D8derelict7opengl33gl312__ModuleInfoZ'
/tmp/ccTqE9NN.o:(.data+0x30): undefined reference to
`_D8derelict5glfw35glfw312__ModuleInfoZ'
collect2: error: ld returned 1 exit status
我相当确定我传递给 GDC 的参数都不是正确的,除了我的源文件的名称。如果我注释掉所有 -L 行,行为是相同的。如果我注释掉 -I 行,我会得到以下信息。
controller.d:6: error: module gl3 is in file 'derelict/opengl3/gl3.d'
which cannot be read
但是,我希望可以通过放置良好的库来解决这个问题。
我如何从拥有 DerelictGL3 等的源代码到使用 GDC 链接到它?
编辑:我确信我已经在 /usr/bin/ 中安装了 libDerelictGL3.a、libDerelictGLFW3.a 和 libDerelictUtil.a。
更多想法: 我真的很困惑为什么我需要针对源代码进行编译。这不是 C++,也没有头文件。当我放弃 -I 行时,编译器不知道如何打开 gl3 模块。它不应该只是推断我使用的函数存在,然后如果/当它找不到它们时会出现链接器错误?既然我已经编译了库并在搜索路径中,为什么 GDC 不能找出其余的?
更多想法: 我最近发现Can't link GLFW3: undefined references 在这种情况下,OP 发现他们需要 .so 形式的库,而不是 .a 形式,因为他们正在尝试动态链接。我目前正在对此进行调查。
另一个难题: 我已将我的 gdc 调用的相关部分更改为
-I/usr/include/d2 \
-L -ldl \
-L/usr/bin \
-lDerelictUtil \
-lDerelictGL3 \
-lDerelictGLFW3
现在,我似乎在链接到 _d_runtime 本身时遇到了问题,而不是在链接到 Derelict 时遇到了问题。
输出类似于这些的数百行:
/usr/bin/libDerelictGL3.a(libDerelictGL3.o): In function
`_D3std5array18__T8AppenderTAPxaZ8Appender13ensureAddableMFNaNbNfmZv':
/home/user/Source/ldc-developers/ldc/runtime/phobos/std/array.d:2231:
undefined reference to `_d_allocmemoryT'
因此,我认为我的问题是 _d_runtime(如果名称错误,请原谅我)在 /usr/bin 以外的其他地方,并且当我将 -L 路径覆盖到 /usr/bin 时(因为那是我放的地方库)我找不到它。要么是这样,要么我只是首先安装了 D 错误。但无论哪种情况,它实际上都是在上述示例中找到 libDerelictGL3.a ! =)
【问题讨论】:
-
为了清楚起见,“忘记源代码并使用 apt-get”形式的答案也很受欢迎。那条路线我也不太走运。
-
尝试添加 -lphobos2 或 -lgphobos2 或类似的东西,看看会发生什么。
-
感谢您的评论,@AdamD.Ruppe;幸好我发现了我的(愚蠢的)错误。
-
很酷,当它允许时不要忘记接受你自己的答案
标签: d dynamic-linking opengl-3 gdc derelict3