[Solved] gcc: cannot compile a program with a custom GMP library

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
Hadi_Lovelorn
Posts: 121
Joined: 2022-05-02 23:12
Been thanked: 1 time

[Solved] gcc: cannot compile a program with a custom GMP library

#1 Post by Hadi_Lovelorn »

I purged libgmp10-dev from Debian 12 Bookworm and then installed GMP 6.3.0 from source with debug options :

Code: Select all

./configure --disable-shared --enable-assert --enable-alloca=debug --host=none CFLAGS=-g
I want to compile my program as :

Code: Select all

gcc -o -g ~/program ~/program.c -lgmp -L/usr/local/lib/libgmp.a
but GCC gives error :

Code: Select all

/usr/bin/ld: /home/lovelorn/program: stderr: invalid version 2 (max 0)
/usr/bin/ld: /home/lovelorn/program: error adding symbols: bad value
collect2: error: ld returned 1 exit status
How should I compile it ? and then debug it ?

Before these options my program got compiled successfully but didn't run and give : segfault error .....
Last edited by Hadi_Lovelorn on 2024-08-08 13:09, edited 2 times in total.

User avatar
ruwolf
Posts: 876
Joined: 2008-02-18 05:04
Location: Banovce nad Bebravou
Has thanked: 78 times
Been thanked: 62 times

Re: How use GDB for debugging GMP library-used program ?

#2 Post by ruwolf »

I think you should also add -I (with apropriate path of directory with header files) in command-line of gcc (but I am not sure).

Aki
Global Moderator
Global Moderator
Posts: 3698
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 100 times
Been thanked: 486 times

Re: How use GDB for debugging GMP library-used program ?

#3 Post by Aki »

Hello @Hadi_Lovelorn,
Hadi_Lovelorn wrote: 2024-08-07 13:14 I purged libgmp10-dev from Debian 12 Bookworm and then installed GMP 6.3.0 from source with debug options :

Code: Select all

./configure --disable-shared --enable-assert --enable-alloca=debug --host=none CFLAGS=-g
I want to compile my program as :

Code: Select all

gcc -o -g ~/program ~/program.c -lgmp -L/usr/local/lib/libgmp.a
but GCC gives error :

Code: Select all

/usr/bin/ld: /home/lovelorn/program: stderr: invalid version 2 (max 0)
/usr/bin/ld: /home/lovelorn/program: error adding symbols: bad value
collect2: error: ld returned 1 exit status
How should I compile it ? and then debug it ?
Please focus on one topic at a time.

You cannot debug a program that does not yet exist as a binary file.

Please change the subject of the first post from "How to use GDB for debugging GMP library-used program" to "gcc: cannot compile a program with a custom GMP library".

Thanks.
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

User avatar
Hadi_Lovelorn
Posts: 121
Joined: 2022-05-02 23:12
Been thanked: 1 time

Re: gcc: cannot compile a program with a custom GMP library

#4 Post by Hadi_Lovelorn »

ruwolf

Thank You , I will check it

Aki

Done ... Thank You

Aki
Global Moderator
Global Moderator
Posts: 3698
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 100 times
Been thanked: 486 times

Re: gcc: cannot compile a program with a custom GMP library

#5 Post by Aki »

Hadi_Lovelorn wrote: 2024-08-07 13:14 I purged libgmp10-dev from Debian 12 Bookworm and then installed GMP 6.3.0 from source with debug options :

Code: Select all

./configure --disable-shared --enable-assert --enable-alloca=debug --host=none CFLAGS=-g
I want to compile my program as :

Code: Select all

gcc -o -g ~/program ~/program.c -lgmp -L/usr/local/lib/libgmp.a
but GCC gives error :

Code: Select all

/usr/bin/ld: /home/lovelorn/program: stderr: invalid version 2 (max 0)
/usr/bin/ld: /home/lovelorn/program: error adding symbols: bad value
collect2: error: ld returned 1 exit status
The errors are printed by the linker (ld).

It is only possible to guess why without the working full source code of your program called "program.c" (and the same for the library).

Just a wild guess: you probably did something strange when building libgmp.a.

Why don't you use the libgmp.a available in the Debian repositories?

Code: Select all

$ apt-file search libgmp.a
libgmp-dev: /usr/lib/x86_64-linux-gnu/libgmp.a
Debugging symbols are available for Debian packages in a dedicated repository and they can be installed using apt, e.g.:

Code: Select all

# Bookworm debug symbols
deb http://deb.debian.org/debian-debug/ bookworm-debug main contrib
Therefore, there's no need to build a custom library to get debug symbols.

Anyway, you probably don't need to debug the library, since you need to find bugs in your program first (to find general errors and errors in using the library functions).

Assuming, of course, that the gmp library is the right choice for your purpose.
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

User avatar
blackbird
Posts: 41
Joined: 2023-08-17 04:42
Has thanked: 1 time
Been thanked: 9 times

Re: gcc: cannot compile a program with a custom GMP library

#6 Post by blackbird »

Hadi_Lovelorn wrote: 2024-08-07 13:14

Code: Select all

gcc -o -g ~/program ~/program.c -lgmp -L/usr/local/lib/libgmp.a
You should review how the "-o" option works and correct the order of your arguments. Currently you try to link together your old program with program.c and gmp.

User avatar
Hadi_Lovelorn
Posts: 121
Joined: 2022-05-02 23:12
Been thanked: 1 time

Re: gcc: cannot compile a program with a custom GMP library

#7 Post by Hadi_Lovelorn »

blackbird

You are right , I should write -g before -o ... Thank You .......

Post Reply