Hi,
I have been trying to run a simple calculation with MPIR on my Windows 7 machines for several days now. My only sources so far are the manual from version 2.6.0 (since 2.7.0 would not load from the mpir site) and some Google search results.
I managed to do the following via MinGW:
- run ./configure --disable-static --enable-shared
- make
- make check
On one of my machines, everything went through, on the other, almost, there was one error during "make check": "FAIL: t-io_raw.exe", but it then went on.
(Is this all and now I can start using it or is a step missing?...)
Now I want to compile the following program called "mytest.cpp" with gcc; I tried typing "g++ mytest.cpp -o mytest" :
//-----------------------------------------------
#include "mpir.h"
#include "gmp.h"
#include "gmp-impl.h"
using namespace std;
int main ()
{
mpz_t z;
mpz_init(z);
return (0);
}
//-----------------------------------------------
The answer from the MinGW command line was
"C:\Users\....\...\Local\Temp\ccD1pbG8.o:mytest.cpp:(.text+0x20): undefined reference to '_imp____gmpz_init' "
and some further lines with similar content.
The program sits in the top folder of MPIR (C:/MPIR/mpir-2.7.0/), I have added this folder to the Windows PATH environment variable.
I can see the mpir.h file in this folder...(?...)
What is missing? I read in the MPIR documentation chapter 3.1 that "All programs using MPIR must link against the 'libmpir' library..." I then tried to compile via
g++ mytest.cpp -lmpir -o mytest
which resulted in
"C:/mingw/bin/ld.exe: cannot find -lmpir"
Are the links to the mpz libraries missing (if so, do I have to use some -I flag? Or - where are they)?
My next question (once this works) would be how (if) I can use MPIR in C code being called by Matlab (via mex-files).
I am relatively new to C Programming and would appreciate any hints. Thanks.
--
You received this message because you are subscribed to the Google Groups "mpir-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpir-devel+...@googlegroups.com.
To post to this group, send email to mpir-...@googlegroups.com.
Visit this group at http://groups.google.com/group/mpir-devel.
For more options, visit https://groups.google.com/d/optout.
From: Bill Hart
In general we are not able to provide assistance with using the gcc compiler and linker. For this, perhaps you can refer to one of the many websites about compiling and linking using gcc, since it is not at all specific to MPIR.
He's trying to use g++, which is the C++ compiler.
Should his configure flags therefore have included "--enable-cxx" (or something similar) ?
Cheers,
Rob
--
You received this message because you are subscribed to the Google Groups "mpir-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mailto:mpir-devel%2Bunsu...@googlegroups.com.
To post to this group, send email to mpir-...@googlegroups.com.
Visit this group at http://groups.google.com/group/mpir-devel.
For more options, visit https://groups.google.com/d/optout.
"C:/mingw/ [...] /bin/ld.exe: cannot find -lmpir"
where "[...]" stands for some directory up-and-down-climbs inside the "minGW" directory. However, I am with the shell currently in the C:/MPIR/mpir-2.7.0/ directory. I tried the "-v" option, and it gave, among other information which indicated that it did not really leave the "MinGW" directory:
#include "..." search starts here:Dear All,
Now the doc mpir-2.7.0.pdf is loading (Firefox); turning off the virus scanner was not changing anything.
One further question: As I wrote, the gcc compilation now works fine for me; however, I would like to call it from Matlab using mex files, and there, the compiler complains that it does not see any ".lib" files (when compiling with "mex ... -lmpir" it looks for a file "libmpir.lib") . Neither do I see any in the MPIR directories.
Should such files be there after a successful installation? Or do I have to set build options differently? Thank you.
From: highcal...@gmail.com
Sent: Friday, June 19, 2015 8:06 PM
To: mpir-...@googlegroups.com
Subject: Re: [mpir-devel] Re: MPIR MinGW installation - "undefined reference to '_imp____gmpz_init'
I would like to call it from Matlab using mex files, and there, the compiler complains that it does not see any ".lib" files (when compiling with "mex ... -lmpir" it looks for a file "libmpir.lib") .[snip]
Compiler answer:
"myfile.obj : error LNK2019: unresolved external symbol __imp___gmpf_init referenced in function "void __cdecl myfile(double)" "
That's interesting ... you've given the directive to link to "-lmpir", no such library is found, but instead of croaking then and there the process continues anyway ? (I don't know Matlab at all.)
Does it work if you rename libmpir.a (or whatever your existing mingw import library is called) to libmpir.lib ?
It's a while since I've tried to use mingw-built libraries with a Microsoft compiler and I'm not sure whether that simplistic approach works.
The fact that your object file is ".obj" instead of ".o" would indicate that it's built with a Microsoft Compiler - so, if need be, you should be able to build the requisite ".lib" file from the dll using your Microsoft Compiler installation's lib tool (as Bill has hinted).
Cheers,
Rob
Dear All,
Thanks for your help. I do not see a file exactly called "libmpir.dll", so if I really need to have "libmpir.lib" sitting in the .libs folder, how would I get the former to convert it via the MS lib tool to the latter?
I tried to convert the two existing ".dll" files in the .libs folder, namely "libmpir-3.dll" and "libmpir-16.dll" via the MS lib tool (accessed via cmd) to their respective ".lib" counterparts (eg. using this description).
Then I used "-lmpir-3" resp. "-lmpir-16" in the mex command, which again returned the
"...unresolved external symbol __imp___gmpf_init ..." message. Specifically, I used the command
mex -IC:/MPIR/mpir-2.7.0/ -LC:/MPIR/mpir-2.7.0/.libs/ -LC:/MPIR/mpir-2.7.0/mpf/.libs -LC:/MPIR/mpir-2.7.0/printf/.libs mexlib.c
I also tried to add the MPIR root and .libs directories to the LIB and INCLUDE variables in the mexopts.bat settings file, which did not help anything.
Rob: The above message, for each mpf_... function, appear if I set the -lmpir or -lmpir-16 flag, but also if I don't.
Just changing the extension of "libmpir.la" to "libmpir.lib" did result in a "file corrupt" message after mex, as Bill conjectured.
Brian: How would I build an MPIR DLL using the native Microsoft and Intel compilers? Is this here a necessary extra step?
So, is the file "libmpir.lib" (or "libmpir.lib") needed and missing?
Since the doc states that "-lmpir" needs to be set as a flag in the compile command.
Or - I think I ran ./configure with --disable-static --enable-shared; if so, was that wrong?
Cheers,
Rob
Brian
> directory where the dll file is.
On Windows it is possible to link directly to a DLL but this is more
normally done through a stub-library.
So on a native build on Windows the mpir.dll is accompanied by the stub
library mpir.lib. So an app links to the stub library which then links
to the DLL itself. IIRC a symbol 'sym' in the DLL becomes '__imp__sym'
in the stub library so it seems to me that the mingw/GCC build system is
not producing a stub library.That sounds right to me. The mingw build doesn't produce a .lib file (stub library). You have to create one if you want to use the dll produced by mingw.In fact, the stub library is apparently not required to use the dll with mingw, which I guess is why it doesn't create one. Internally, it uses the Microsoft linker, but I don't completely understand the precise mechanism.Bill.Brian
> This could be because your system PATH is not set to include the> directory where the dll file is.
On Windows it is possible to link directly to a DLL but this is more
normally done through a stub-library.
So on a native build on Windows the mpir.dll is accompanied by the stub
library mpir.lib. So an app links to the stub library which then links
to the DLL itself. IIRC a symbol 'sym' in the DLL becomes '__imp__sym'
in the stub library so it seems to me that the mingw/GCC build system is
not producing a stub library.That sounds right to me. The mingw build doesn't produce a .lib file (stub library). You have to create one if you want to use the dll produced by mingw.In fact, the stub library is apparently not required to use the dll with mingw, which I guess is why it doesn't create one. Internally, it uses the Microsoft linker, but I don't completely understand the precise mechanism.Bill.Brian
Ok I have tried building stub libraries (containing only one column with the names "__gmp_init" etc. of the functions used in the code, using the MS lib tool. Now using "-lmpir" or "-lmpir-16" in the mex command should find the libmpir-16.dll, which, I suppose, contains the addresses (locations) of the various function definitions, via the stub library?
It does not yet the job. I will try to read more mex documentation.
Is there anything like a MinGW path variable I would be able to set?
Thanks.--
Cheers,
Rob
So on a native build on Windows the mpir.dll is accompanied by the stub
library mpir.lib. So an app links to the stub library which then links
to the DLL itself. IIRC a symbol 'sym' in the DLL becomes '__imp__sym'
in the stub library so it seems to me that the mingw/GCC build system is
not producing a stub library.That sounds right to me. The mingw build doesn't produce a .lib file (stub library). You have to create one if you want to use the dll produced by mingw.In fact, the stub library is apparently not required to use the dll with mingw, which I guess is why it doesn't create one. Internally, it uses the Microsoft linker, but I don't completely understand the precise mechanism.Bill.Brian
Ok I have tried building stub libraries (containing only one column with the names "__gmp_init" etc. of the functions used in the code, using the MS lib tool. Now using "-lmpir" or "-lmpir-16" in the mex command should find the libmpir-16.dll, which, I suppose, contains the addresses (locations) of the various function definitions, via the stub library?I guess that is the idea. Is your stub library named correctly now?