导致此链接失败的原因(未定义的引用)?

时间:2011-09-09 17:47:27

标签: c linux linker ld

我刚刚将我的开发机器从Gentoo切换到Arch Linux,当我尝试编译我的项目的新版本时,链接失败:

clang -O0 -g -pipe -Wall -DDEBUG -o slug announce.o bitfield.o main.o metadata.o network.o parser.o peer.o piece.o scheduler.o torrent.o url.o util.o -I. -lssl -lm -lcurl -levent
/usr/bin/ld.gold: metadata.o: in function get_info_hash:metadata.c:186: error: undefined reference to 'SHA1_Init'
/usr/bin/ld.gold: metadata.o: in function get_info_hash:metadata.c:187: error: undefined reference to 'SHA1_Update'
/usr/bin/ld.gold: metadata.o: in function get_info_hash:metadata.c:188: error: undefined reference to 'SHA1_Final'
/usr/bin/ld.gold: piece.o: in function verify_piece:piece.c:40: error: undefined reference to 'SHA1_Init'
/usr/bin/ld.gold: piece.o: in function verify_piece:piece.c:41: error: undefined reference to 'SHA1_Update'
/usr/bin/ld.gold: piece.o: in function verify_piece:piece.c:42: error: undefined reference to 'SHA1_Final'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [slug] Error 1

整个来源都在GitHub上:https://github.com/robertseaton/slug

2 个答案:

答案 0 :(得分:8)

看起来你错过了-lcrypto

答案 1 :(得分:5)

根据我的经验,-lssl-lcrypto的位置可能是问题的根源。尝试将-lcrypto选项推送到gcc选项的末尾,或者在输入目标文件之前。