0

My program uses the GNU Multiple Precision Arithmetic Library to deal with numbers of an arbitrary size. I successfully compile it using GCC with:

gcc main.c -o diff -g -lgmp 

However, when I try to use the MinGW crosscompiler compiler, I get the following error:

i686-w64-mingw32-gcc main.c -o diff.exe -g -lgmp main.c:3:46: fatal error: gmp.h: No such file or directory #include <gmp.h>//For files of arbitrary size 

I then tried to tell it exactly where the header file was:

 i686-w64-mingw32-gcc main.c -o diff.exe -I/usr/include -g -lgmp /usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld: cannot find -lgmp collect2: error: ld returned 1 exit status 

Ok, so I figure now it successfully found the header, but cant find the library. So I tried again:

i686-w64-mingw32-gcc main.c -o diff.exe -I/usr/include -g -L/usr/lib -lgmp /usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld: cannot find -lgmp collect2: error: ld returned 1 exit status 

I guess I need to specify the exact files to use, so I tried this:

i686-w64-mingw32-gcc main.c -o diff.exe -I/usr/include -g /usr/lib/libgmp.so /usr/lib/libgmp.so: file not recognized: File format not recognized collect2: error: ld returned 1 exit status 

So, I honestly don't know what to do and I'd really really appreciate your help.

2
  • 1
    You need to cross-compile the library, too! Commented Apr 13, 2015 at 0:04
  • You don't. It won't work. Commented May 1, 2021 at 23:18

1 Answer 1

3

First, a disclaimer: the cross-compiler you are using is neither distributed by, nor supported by MinGW.org, whom I represent; if you are looking for a pre-compiled solution, you should seek it from the distributor of the specific cross-compiler itself.

That said, I can offer the following insight, (which will apply, in general, to any cross-compiler): the headers you find in /usr/include, or in /usr/local/include, and the libgmp.so which you find in /usr/lib, or in /usr/local/lib, are intended for use with your native platform compiler. They are not suitable for, and cannot be used with your MinGW cross-compiler; attempting to do so will surely never work. Thus, you have two options:

  1. Ask your cross-compiler distributor to provide a pre-compiled copy of gmp.dll, (or at the very least, a compatible import library, although you may need the gmp.dll to distribute with your own application anyway), and any associated header files, and/or equivalent statically linkable library, for use with your cross-compiler.

  2. Use your cross-compiler to build gmp.dll yourself, then install it, its associated headers, and perhaps also its associated import library and/or equivalent statically linkable library, into the same prefix-path as the cross-compiler itself.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.