c++上的链接器错误

Linker errors on c++

本文关键字:错误 链接 c++      更新时间:2023-10-16

我正在尝试编译最短路径问题的实现(代码:http://www.dis.uniroma1.it/challenge9/code/ch9-1.1.tar.gz)。然而,我得到了错误:

le@le-Extensa-4630:~/Desktop/code/ch9-1.1$ make
cd ./gens;    make
make[1]: Entering directory `/home/le/Desktop/code/ch9-1.1/gens'
cd ./grid;    make
make[2]: Entering directory `/home/le/Desktop/code/ch9-1.1/gens/grid'
gcc -O6 -DNDEBUG -DPERMUTE_NODES  -I ../../lib -I ../../lib/ll-core/include -o spgrid.exe spgrid.c -lm         -I../../lib/ ../../lib/ll-core/src/*.c
../../lib/ll-core/src/LConnectivity.c: In function ‘_visitaDSFRicorsiva’:
../../lib/ll-core/src/LConnectivity.c:114:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ui4’ [-Wformat]
../../lib/ll-core/src/LFile_posix.c: In function ‘LFile_GetTempName’:
../../lib/ll-core/src/LFile_posix.c:171:11: warning: ignoring return value of ‘tmpnam’, declared with attribute warn_unused_result [-Wunused-result]
../../lib/ll-core/src/LSystem.c: In function ‘LSystem_GetString’:
../../lib/ll-core/src/LSystem.c:47:10: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
/tmp/ccGnQJPS.o: In function `LArray_ResizeBy':
LArray.c:(.text+0x354): undefined reference to `log'
LArray.c:(.text+0x38e): undefined reference to `pow'
LArray.c:(.text+0x402): undefined reference to `log'
LArray.c:(.text+0x43c): undefined reference to `pow'
/tmp/ccVDr0iU.o: In function `LGraphUtil_RandomUNM':
LGraphUtil.c:(.text+0x988): undefined reference to `sqrt'
LGraphUtil.c:(.text+0x997): undefined reference to `sqrt'
LGraphUtil.c:(.text+0x9a6): undefined reference to `sqrt'
collect2: ld returned 1 exit status
make[2]: *** [spgrid.exe] Error 1
make[2]: Leaving directory `/home/le/Desktop/code/ch9-1.1/gens/grid'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/le/Desktop/code/ch9-1.1/gens'
make: *** [code] Error 2

编辑Makefile以更改-lm位置。将-lm放在命令行的末尾,因为顺序取决于gcc/binutils*。

[1] 库可能需要出现在需要它们的对象之后。

相关文章: