Problem using gmp

I want to use gmp from the standard library and try this program:

1
2
3
4
5
6
7
8
9
10
using namespace std;
#include <gmp.h>
	
int main() {

	mpf_t x;
	mpf_init(x);

	return 0;
}


but I get this error when compiling with g++:

/tmp/ccc3vb2X.o:gmptest.cpp(.text+0x1d): undefined reference to '__imp____gmpf_init'

(gmptest.cpp is the name of my program)

I suspect the problem is connected to linking (whatever that is) cf. this answer to a similar problem, from http://www.cplusplus.com/forum/unices/2457/ :


rnodal (1)

You problem is not with compiling but linking. You need to tell g++ where to find also the library. You can configure codeblocks to do that for you. The weird things in front the function name is due to C++ code. C++ compilers put things in front of functions names. See this link for more:http://en.wikipedia.org/wiki/Name_mangling

Take care.


But this seems to imply that g++ can't find the library at all, which it can since lots of other stuff works fine. Suggestions?



gmp is not part of the standard library and so it will not be linked automatically.
Invoke g++ with the parameter -lgmp to link the gmp library.

See here for a short text about linking:
http://www.sethi.org/classes/cet375/lab_notes/lab_04_makefile_and_compilation.html
Works like a charm, thanks!
Topic archived. No new replies allowed.