我在试着做一个像“!Remindme”reddit bot和我发现这个用C编写的Web Scrapper,但我不明白为什么它不能编译。编译器抛出了这个:
gcc -o crawler src/crawler.o src/html.o src/http.o src/list.o src/queue.o src/url.o -g -Wall -fPIE -lpthread lib/liburiparser.a
/usr/bin/ld: src/crawler.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: src/html.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: src/http.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: src/url.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: lib/liburiparser.a(UriNormalizeBase.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: lib/liburiparser.a(UriParse.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: lib/liburiparser.a(UriCommon.o): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: lib/liburiparser.a(UriIp4.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
make: *** [Makefile:20: crawler] Error 1
即使有了flag -fPIE,它也不起作用,我很困惑为什么。
**编辑:**我试图编译this repo
2条答案
按热度按时间8wtpewkr1#
你不是在编译,你是在链接。linker
/usr/bin/ld
是指一些对象文件(直接的和来自存档的)必须事先用-fPIE
编译才能工作。4ioopgfo2#
你需要安装
liburiparser
(在ubuntu上是liburiparser-dev
),然后运行以下命令:我建议您不要使用在其他系统上编译的.o文件,这些系统很可能具有不同的CPU架构。
旁注:我发现你使用的是https://github.com/iceman201/Web_Scraper,他们似乎没有配置.gitignore来忽略这些.o文件,这是这里混淆的根源。