r/programminghelp • u/itsfakenoone • 2d ago
C Compiling gcc: Undefined references
I am trying to compile gcc from source. I have the source, I got the prerequisites (had to separately install some stuff: gmp, mpfr, mpc), and then I go into the gcc build folder and configure using the command
../gcc-16.2.0-source/configure --prefix="$HOME/downloads/gcc-16.2.0-install" LDFLAGS="-L$HOME/downloads/mpfr-4.2.2-install/lib -t -lm" --disable-multilib(Without the LDFLAGS thing it would complain it couldn't find the gmp/mpfr/mpc libraries)
And then I run "make", and after a long time it shows
fold-const-call.o: In function `fold_const_call_sss(real_value*, combined_fn, real_value const*, real_value const*, real_format const*)':
fold-const-call.cc:(.text+0x624): undefined reference to `mpfr_atan2pi'
fold-const-call.o: In function `fold_const_call_1(combined_fn, tree_node*, tree_node*)':
fold-const-call.cc:(.text+0x2c55): undefined reference to `mpfr_cospi'
fold-const-call.cc:(.text+0x2c72): undefined reference to `mpfr_atanpi'
fold-const-call.cc:(.text+0x2cc8): undefined reference to `mpfr_asinpi'
fold-const-call.cc:(.text+0x2ced): undefined reference to `mpfr_sinpi'
fold-const-call.cc:(.text+0x2d0a): undefined reference to `mpfr_tanpi'
fold-const-call.cc:(.text+0x377b): undefined reference to `mpfr_acospi'
fold-const-call.o: In function `fold_const_call_sss(real_value*, combined_fn, real_value const*, real_value const*, real_format const*)':
fold-const-call.cc:(.text+0x624): undefined reference to `mpfr_atan2pi'
fold-const-call.o: In function `fold_const_call_1(combined_fn, tree_node*, tree_node*)':
fold-const-call.cc:(.text+0x2c55): undefined reference to `mpfr_cospi'
fold-const-call.cc:(.text+0x2c72): undefined reference to `mpfr_atanpi'
fold-const-call.cc:(.text+0x2cc8): undefined reference to `mpfr_asinpi'
fold-const-call.cc:(.text+0x2ced): undefined reference to `mpfr_sinpi'
fold-const-call.cc:(.text+0x2d0a): undefined reference to `mpfr_tanpi'
fold-const-call.cc:(.text+0x377b): undefined reference to `mpfr_acospi'
fortran/simplify.o: In function `gfc_simplify_acosd(gfc_expr*)':
simplify.cc:(.text+0x5cda): undefined reference to `mpfr_acosu'
fortran/simplify.o: In function `gfc_simplify_asind(gfc_expr*)':
simplify.cc:(.text+0x5dca): undefined reference to `mpfr_asinu'
fortran/simplify.o: In function `gfc_simplify_atand(gfc_expr*)':
simplify.cc:(.text+0x5e80): undefined reference to `mpfr_atanu'
fortran/simplify.o: In function `gfc_simplify_atan2d(gfc_expr*, gfc_expr*)':
simplify.cc:(.text+0x6c4f): undefined reference to `mpfr_atan2u'
fortran/simplify.o: In function `gfc_simplify_cosd(gfc_expr*)':
simplify.cc:(.text+0x6de0): undefined reference to `mpfr_cosu'
fortran/simplify.o: In function `gfc_simplify_sind(gfc_expr*)':
simplify.cc:(.text+0x6e70): undefined reference to `mpfr_sinu'
fortran/simplify.o: In function `gfc_simplify_tand(gfc_expr*)':
simplify.cc:(.text+0x6f00): undefined reference to `mpfr_tanu'
fortran/simplify.o: In function `gfc_simplify_cotand(gfc_expr*)':
simplify.cc:(.text+0x6fbe): undefined reference to `mpfr_tanu'
fortran/simplify.o: In function `gfc_simplify_acospi(gfc_expr*)':
simplify.cc:(.text+0x7163): undefined reference to `mpfr_acospi'
fortran/simplify.o: In function `gfc_simplify_asinpi(gfc_expr*)':
simplify.cc:(.text+0x7223): undefined reference to `mpfr_asinpi'
fortran/simplify.o: In function `gfc_simplify_atanpi(gfc_expr*)':
simplify.cc:(.text+0x72ab): undefined reference to `mpfr_atanpi'
fortran/simplify.o: In function `gfc_simplify_atan2pi(gfc_expr*, gfc_expr*)':
simplify.cc:(.text+0x7375): undefined reference to `mpfr_atan2pi'
fortran/simplify.o: In function `gfc_simplify_cospi(gfc_expr*)':
simplify.cc:(.text+0x740b): undefined reference to `mpfr_cospi'
fortran/simplify.o: In function `gfc_simplify_sinpi(gfc_expr*)':
simplify.cc:(.text+0x749b): undefined reference to `mpfr_sinpi'
fortran/simplify.o: In function `gfc_simplify_tanpi(gfc_expr*)':
simplify.cc:(.text+0x752b): undefined reference to `mpfr_tanpi'
fold-const-call.o: In function `fold_const_call_sss(real_value*, combined_fn, real_value const*, real_value const*, real_format const*)':
fold-const-call.cc:(.text+0x624): undefined reference to `mpfr_atan2pi'
fold-const-call.o: In function `fold_const_call_1(combined_fn, tree_node*, tree_node*)':
fold-const-call.cc:(.text+0x2c55): undefined reference to `mpfr_cospi'
fold-const-call.cc:(.text+0x2c72): undefined reference to `mpfr_atanpi'
fold-const-call.cc:(.text+0x2cc8): undefined reference to `mpfr_asinpi'
fold-const-call.cc:(.text+0x2ced): undefined reference to `mpfr_sinpi'
fold-const-call.cc:(.text+0x2d0a): undefined reference to `mpfr_tanpi'
fold-const-call.cc:(.text+0x377b): undefined reference to `mpfr_acospi'
/home/CENSORED/downloads/mpc-1.3.1-install/lib/libmpc.so: undefined reference to `mpfr_fmma'
/home/CENSORED/downloads/mpc-1.3.1-install/lib/libmpc.so: undefined reference to `mpfr_fmms'
collect2: error: ld returned 1 exit status
make[3]: *** [lto1] Error 1
make[3]: *** Waiting for unfinished jobs....
/home/CENSORED/downloads/mpc-1.3.1-install/lib/libmpc.so: undefined reference to `mpfr_fmma'
/home/CENSORED/downloads/mpc-1.3.1-install/lib/libmpc.so: undefined reference to `mpfr_fmms'
/home/CENSORED/downloads/mpc-1.3.1-install/lib/libmpc.so: undefined reference to `mpfr_fmma'
/home/CENSORED/downloads/mpc-1.3.1-install/lib/libmpc.so: undefined reference to `mpfr_fmms'
collect2: error: ld returned 1 exit status
make[3]: *** [lto-dump] Error 1
collect2: error: ld returned 1 exit status
make[3]: *** [f951] Error 1
make[3]: Leaving directory `/home/CENSORED/downloads/gcc-16.2.0-build/gcc'
make[2]: *** [all-stage2-gcc] Error 2
make[2]: Leaving directory `/home/CENSORED/downloads/gcc-16.2.0-build'
make[1]: *** [stage2-bubble] Error 2
make[1]: Leaving directory `/home/CENSORED/downloads/gcc-16.2.0-build'
make: *** [all] Error 2I have no idea what to do, I'm not a programmer, I just need this to work so I can move on and use certain programs (like geant4). What do I do? How do I fix this? I am literally genuinely rolling on the floor sobbing right now
2
u/Lewinator56 2d ago
Why are you compiling GCC if you already have a working build of GCC that can compile GCC?
You shouldn't need a special build of GCC to compile geant4
1
u/gmes78 2d ago
I don't think you're specifying your dependencies correctly. However, there's a much easier way. Get rid of your
LDFLAGSand follow what the prerequisites page describes: you can just put the dependency source code inside the gcc tree, and it'll be built alongside it.(Same for the other dependencies.)
There's a helper script,
contrib/download_prerequisites, that does this for you.1
u/dfx_dj 1d ago
These are errors from the linker, telling you that not all object files that are required to make the final target file are present.
My first guess would be that you manually overriding the
LDFLAGSis what causes this. The-Loption only tells the build scripts and the linker where the find libraries, but it doesn't actually link any of them. You need additional-loptions (lower case) to do that, similar to how the math lib (-lm) is linked in. These may be given in other variables, but may also be in theLDFLAGSthat you've overridden.So, try to figure out which libraries are needed and add them into the
LDFLAGS, for example add-lmpfr(assuming that's what the file is called).(This is just a wild shot in the dark since I'm not familiar with how the gcc build process actually works.)
1
u/Classic-Rate-5104 1d ago
Seriously, you aren't a programmer and you try to build gcc. Why?