【发布时间】:2016-04-11 23:07:48
【问题描述】:
我注意到我无法在命令末尾使用 cpp 文件编译我的代码:
ars@Arsmint$ g++ -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -lXcursor main.cpp
/tmp/ccxlyIri.o: In function `main':
main.cpp:(.text+0x10c): undefined reference to `createDevice'
collect2: error: ld returned 1 exit status
如果我把它们放在链接指令之前,它编译得很好:
ars@Arsmint$ g++ main.cpp -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -lXcursor
ars@Arsmint$
我已经阅读了一些解释 here 和 there,但是当涉及到编译源时,我仍然不太明白,而不是库依赖。我原以为编译器总是先编译代码,然后才调用链接器。在这种情况下,它应该知道从 main.cpp 构建的目标文件甚至在链接过程开始之前就需要 createDevice 函数。我的错在哪里?
附: This问题,作为重复提出,根本不解释。
【问题讨论】:
标签: gcc linker static-linking