我必须编写一个 C 程序来解决hungarian method
分配问题。因此,我从网上下载了一个参考资料,其中有 ( makefile,test.c,hungarian.c,hangarian.h,readme ,
) ,,现在我成功地test.c
通过运行了$ make test
,,但是我在运行时遇到了麻烦hangarian.c
,当我尝试在终端上编译它时,我得到了::
anupam@JAZZ:~/Downloads/hungarian$ make hungarian
gcc -L. -lhungarian hungarian.o -o hungarian
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [hungarian] Error 1
我不明白这个错误是什么意思??
答案1
我的 Google-fu 找到了您正在尝试编译的源文件:
http://robotics.stanford.edu/~gerkey/tools/hungarian.html
尤其是:
http://robotics.stanford.edu/~gerkey/tools/libhungarian-0.3.tar.gz
只需运行make
即可构建全部必须编译的东西(make hungarian
是错误的命令)。
过程输出make
:
gcc -O3 -Wall -I. -c hungarian.c
hungarian.c: In function ‘hungarian_routine_two’:
hungarian.c:432:14: warning: variable ‘newsum’ set but not used [-Wunused-but-set-variable]
int oldsum,newsum;
^
gcc -O3 -Wall -I. -c -o makeprob.o makeprob.c
ar cr libhungarian.a hungarian.o makeprob.o
gcc -O3 -Wall -I. -o test test.c -L. -lhungarian
gcc -O3 -Wall -I. -o timetest timetest.c -L. -lhungarian -lm
现在您有两个可执行文件(test
和timetest
)和一个静态库文件(libhungarian.a
)。
运行测试程序:
./test
./runtest
如果您想编写一个使用该库的程序,您需要#include "hungarian.h"
在您的myprogram.c
文件中,并使用类似于测试程序的命令来编译它:
gcc -O3 -Wall -I. -o myprogram myprogram.c -L. -lhungarian
我建议您复制test.c
(cp test.c myprogram.c
)并进行修改以满足您的需要。
正如您所见,这里发生了一些神奇的事情:man
几页纸make
应该gcc
会为它带来一些启示。