0

I wrote a public-private key generator using mpir(on windows) and it works fine.

When I try to compile it on a linux machine using gmp library, it throws a whole bunch of linker errors.

/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invali
d symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invali
d symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invali
d symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invali
d symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invali
d symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invali
d symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invali
d symbol index 13
...
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start'
:
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

I'm using g++ -lgmp prime.cpp. I haven't used any non-gmp function. Any idea? I'm not adding code as there's a lot of it.

questions
  • 2,337
  • 4
  • 24
  • 39

1 Answers1

1

I'm using g++ -lgmp prime.cpp

This command line is broken in two ways:

  1. You neglected to provide definiton of main
  2. You specified library before source that references it. Should be:

    g++ main.cpp prime.cpp -lgmp

    The order of libraries and sources/objects on command line matters.

Update:

There are several files.. main file depends on them, so before building it.. I was trying to build the other files.

In that case, correct command is:

# Compile, but don't link, prime.cpp
g++ -c prime.cpp
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • There are several files.. main file depends on them, so before building it.. I was trying to build the other files. – questions Apr 22 '12 at 18:10
  • Yay.. that works. Thanks!! But in one other file, gmp doesn't identify `mp_bitcnt_t` type.. says `mp_bitcnt_t has not been declared` – questions Apr 22 '12 at 18:17
  • What version of GMP are you using? IIRC, mp_bitcnt_t was introduced in 5.0. – casevh Apr 22 '12 at 20:39