problem with using gnu mp on ubuntu 7.04

*reposted here (also posted in 'general c++ programming') due to confusion

My system has:
- ubuntu 7.04
- code::blocks IDE w/ gcc compiler
- gmp-4.2.2.tar.gz which is downloaded here >>

I installed ubuntu (and has been using this for just a week) for the sake of using the library on a Linux-based system after seeing all the necessary files are built to be used on Linux-based systems (correct me if I'm wrong).

I followed the instructions on this page > < on the Konsole and no errors were found.

The header (gmp.h) is then installed in /usr/local/include/gmp.h.

I then assumed that the library was installed successfully, but after I compiled the code below, an error had occurred (error msg is below the code).

#include <gmp.h>
#include <iostream>

using namespace std;

int main()
    mpz_t gmpInt;
    mpz_init(gmpInt); //This is line 9.
    return 0;

- line 9 -- undefined reference to '__gmpz_init'

I re-ran the installation commands on the manual but the error has not been fixed.

Is it a problem with these commands (not updated files for 'make' or something else)?


// I ran make check before make install and the output tells me that
// it had passed all tests.
make install

What does the error mean? Was the library miscompiled? If so, why was it miscompiled and what are the proper procedures?

A helpful reply would be VERY much appreciated because I am stuck with this problem for about 4 days now.
Last edited on
I have never used GMP however,
The function you are calling on line 9 will almost certainly be a preprocessor macro for __gmpz_init buried somewhere in the header files. I suspect you are missing some of these header files or more likely the compiler doesn't know where to look for them.

Check to make sure you are passing all the necessary search directories to the compiler (-I option)
Thanks for the reply, bnbertha. Would you kindly show me how it is done because I am not yet familiar with...

Check to make sure you are passing all the necessary search directories to the compiler (-I option)

On which of these will I use the -l option?
make check
make install
Last edited on
No, in won't be in any of them, it's when you compile your own code.

Part of the compile command will have one or more -I<some directory> in it. These directories tell the compiler where it can look for header files. If your GMP headers are not in one of the listed directories then you need to add more -I's
When you type g++ -v -c <your-program-name.cpp>. The output will also display the directory which will be searched for the header files.
Here is the output I got on my Linux machine.
$ gcc -v -c test.cpp

#include "..." search starts here:
#include <...> search starts here:
End of search list.
so you can check if the header file gmp.h is there in any of the listed directories.
Alternately you can search your PC for gmp.h file and copy the entire header files to /usr/include as this directory will be used almost all the times by the complier.

Hope this helps.
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:

Take care.
+1 for modal's answer. It's a linker problem.
Topic archived. No new replies allowed.