I don't understand why this program don't compile - c

I'm trying to make a bot like the "!Remindme" reddit bot and i found this Web Scrapper written in C but i don't understand why it don't compile. Can someone help me ? The compiler throw me this :
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
Even with the flag -fPIE it doesn't work and i'm confuse why. Any help ? :)

You are not compiling you are linking. The linker /usr/bin/ld is talking about that some of the objects files (both direct and from the archive) have to be compiled previously with the -fPIE to work.

You will need to install liburiparser (liburiparser-dev on ubuntu), and run the following command:
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
I suggest you do not use those .o files compiled on other systems, most likely with different CPU architectures.
Side note: I found that you are using https://github.com/iceman201/Web_Scraper, and it seems that they don't have a configured .gitignore to ignore these .o files which are the source of confusion here.

Related

using .rodata and -fPIE in compliation [duplicate]

This question already has an answer here:
32-bit absolute addresses no longer allowed in x86-64 Linux?
(1 answer)
Closed last month.
I'm a student currently taking a computer structures course and I have an assignement for writing in aseembly and C. I've found an issue I don't quite understand. We were given a makefile for running the program, and when connecting to our school's servers it works as intended. The issue arises when trying to use the same makefile on my personal machine. One of the assembly files (and likely more as I continue working) utilizes a .rodata section. Attempting to use the makefile as it was given results in the following error:
gcc -g -o a.out main.o run_main.o func_select.o pstring.o
/usr/bin/ld: func_select.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make: *** [makefile:2: a.out] Error 1
attempting to add one of the following
-fpie -fPIE or -no-pie
in between
-o
and a.out
results in the following error
gcc -g -o -fPIE a.out main.o run_main.o func_select.o pstring.o
/usr/bin/ld: cannot find a.out: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [makefile:2: a.out] Error 1
I'm sorry if this is considered a silly question however I can't figuere it out.
The expectation was for the makefile to create all of the .o files and a.out, however the a.out file never works.
In addition writing the following: gcc -g -fPIE -o a.out main.o run_main.o func_select.o pstring.o still creates an error, specifically
gcc -g -fPIE -o a.out main.o run_main.o func_select.o pstring.o
/usr/bin/ld: func_select.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make: *** [makefile:2: a.out] Error 1
As per man gcc:
gcc [-c|-S|-E] [-std=standard]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-Wpedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...] [-mmachine-option...]
[-o outfile] [#file] infile...
-o requires outfile parameter. This should work:
gcc -g -fPIE -o a.out main.o run_main.o func_select.o pstring.o

gcc compile error: /usr/bin/ld: gfx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE

Error is as follows:
/usr/bin/ld: gfx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:4: project] Error 1
and when I add -fPIC or -fPIE, nothing changes. I know that the gfx.o library works, since it was working previously and still works when I ssh on my server.
Make file is as follows:
project: project.c
gcc project.c gfx.o -lx11 -lm -fPIE -o -project
clean:
rm project
I tried to use -fPIE and -fPIC in the makefile. I also treid uninstalling and reinstalling gcc and binutills, but nothing worked.
I figured out that putting -no-pie in the Makefile solves the issue. I don't know if there is a more permanent and widespread fix, but it works.

Error: relocation R_X86_64_32 against `.rodata' when build AV1 AOM project

When I compile my aom project in my VMWare(Ubuntu), host PC is using AMD ryzen 1600.
It comes to this Error:
[ 63%] Built target yuv
[ 64%] Linking CXX executable examples/decode_with_drops
/usr/bin/ld: libaom.a(fwd_txfm_ssse3_x86_64.asm.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: libaom.a(quantize_ssse3_x86_64.asm.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: libaom.a(subpel_variance_sse2.asm.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: libaom.a(highbd_subpel_variance_impl_sse2.asm.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
CMakeFiles/decode_with_drops.dir/build.make:144: recipe for target 'examples/decode_with_drops' failed
make[2]: *** [examples/decode_with_drops] Error 1
CMakeFiles/Makefile2:304: recipe for target 'CMakeFiles/decode_with_drops.dir/all' failed
make[1]: *** [CMakeFiles/decode_with_drops.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

Compile FFTW with pgcc, undefined reference

For other software I need fftw-2.1.5 with --enable-mpi --enable-type-prefix --enable-float installed. It should be compiled with pgcc
PGCC, etc. are installed under the /home directory. For this post I have shortend it with path-to.
I do:
./configure --prefix=/path-to/fftw --enable-mpi --enable-type-prefix --enable-float CC=path-to/pgcc CXX=path-to/pgc++ F77=path-to/pgf77 FC=path-to/pgfortran
make`
./configure finishes successful, during make I get this error message:
/usr/bin/ld: ../fftw/.libs/libsfftw.a(malloc.o): relocation R_X86_64_32 against .rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ../fftw/.libs/libsfftw.a(putils.o): relocation R_X86_64_32 against .rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ../fftw/.libs/libsfftw.a(twiddle.o): relocation R_X86_64_32 against .data' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
I tried to recompile with the -fPIC flag:
make clean
make CFLAGS="-fPIC"
Then I get:
../fftw/.libs/libsfftw.a(twiddle.o): In function `fftw_compute_twiddle':
/home/daniel/fftw-test/fftw-2.1.5/fftw/./twiddle.c:92: undefined reference to `__fd_sincos_1'
/home/daniel/fftw-test/fftw-2.1.5/fftw/./twiddle.c:126: undefined reference to `__fd_sincos_1'
../fftw/.libs/libsfftw.a(twiddle.o): In function `fftw_compute_rader_twiddle':
/home/daniel/fftw-test/fftw-2.1.5/fftw/./twiddle.c:65: undefined reference to `__fd_sincos_1'
collect2: error: ld returned 1 exit status
I've now tried to find a solution to why this happens for hours but I cannot figure it out.
When I configure it to use the gcc compiler (system default) everything works perfectly:
./configure --prefix=/fftw --enable-mpi --enable-type-prefix --enable-float
make
make install
EDIT, more information:
The program for which I need fftw, needs pgcc. I though it would be best if I compile everything with it as it was recommended on some forum sites.
In twiddle.c there is not a single mention of __fd_sincos_1. For example line 92 is simply
for (i = 0; i < n; ++i) {
When I drop the --enable-type-prefix nothing changes. Still the same error.

ld: linker error

ld: foo.o: relocation R_X86_64_PC32 against undefined symbol `bar' can not be used when making a shared object; recompile with -fPIC
I recompile with -fPIC and it still produces this error.
Versions of your compiler and linker? Perhaps your problem is related to this bug, that seems to be fixed now: http://sources.redhat.com/bugzilla/show_bug.cgi?id=584?

Resources