简体   繁体   中英

Undefined reference to `__gmpz and makefile

I can't figure out why I'm getting these compilation errors:

gcc -o Compil obj/MillerRabin.o obj/main.o -L. -L/usr/lib/ -Wl,-rpath=/home/---------/Documents/AC20_Cyrpto -lgmp  -lCommon  -ltest  -lprimeGen
./libtest.so: undefined reference to `__gmpz_set_str'
./libtest.so: undefined reference to `__gmpz_set_ui'
./libtest.so: undefined reference to `__gmpz_add_ui'
./libtest.so: undefined reference to `__gmpz_clear'
./libtest.so: undefined reference to `__gmpz_init'
./libtest.so: undefined reference to `mpzPrint'
collect2: error: ld returned 1 exit status
Makefile:61: recipe for target 'Compil' failed
make: *** [Compil] Error 1

These errors are coming from libs/test/test.c , I'm using a make file that a friend of mine made, and I haven't really looked into how they work yet.

So what's weird is that in my libs folder I have another .c file that's using gmp ( libs/Common/common.h and mpzfunctions.c ), and that one doesn't give me any errors. If I move my test function to the main the compilation works.

If anyone knows how to fix this, it would be great! Thanks.

Symbols from libraries are applied in order. So when you write:

-lgmp -ltest

It means that symbols used in libgmp will be looked up in libtest but not vice versa.

Apparently, your libtest requires functions from libgmp, so you need to apply them in the opposite order.

As a rule of thumb, external libraries should always go last because they do not generally require symbols from your libraries.

So without knowing too much, I 'd guess that the order should be:

 -lCommon -lprimeGen -ltest -lgmp

It looks to me like you will want to remove -lgmp from LINK_FLAGS and add it somehow to the end of the link command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM