【问题标题】:I don't understand why this program don't compile我不明白为什么这个程序不能编译
【发布时间】:2022-01-22 08:10:59
【问题描述】:

我正在尝试制作一个像“!Remindme”reddit 机器人这样的机器人,我发现这个 Web Scrapper 是用 C 语言编写的,但我不明白为什么它不能编译。有人能帮我吗 ?编译器向我抛出这个:

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

即使使用标志 -fPIE 它也不起作用,我很困惑为什么。有什么帮助吗? :)

【问题讨论】:

  • -fPIE编译会抛出什么问题?

标签: c linux gcc compiler-errors web-crawler


【解决方案1】:

你没有编译你正在链接。 链接器 /usr/bin/ld 正在谈论一些对象文件(直接和来自存档)必须先用-fPIE 编译才能工作。

【讨论】:

    【解决方案2】:

    您需要安装liburiparser(在ubuntu 上为liburiparser-dev),然后运行以下命令:

    gcc -o crawler src/crawler.c src/html.c src/http.c src/list.c src/queue.c src/url.c -g -Wall -lpthread -luriparser -I./include
    

    我建议你不要使用那些在其他系统上编译的 .o 文件,很可能是使用不同的 CPU 架构。

    旁注:我发现您使用的是https://github.com/iceman201/Web_Scraper,而且他们似乎没有配置 .gitignore 来忽略这些 .o 文件,这是造成混乱的根源。

    【讨论】:

      猜你喜欢
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      相关资源
      最近更新 更多