Thread: MingW and GNU MP?

  1. #16
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by Neo1 View Post
    First of all: Cactus_hugger mentioned copying the library files and headers to my compiler directory to make compiling easier, i put the "gmp.h" in there, but there is also a subdirectory called "C++". This contains all the c++ headers, like string and iostream, should i put the "gmpxx.h" file in there?
    Say your standard include path is /usr/include. That's where all of the standard C header files go, among other things. Standard C++ header files tend to go in /usr/include/c++ (or some other variation). Header files for libraries go in their own folder typically; for example, SDL includes go in /usr/include/SDL; ncurses includes go in /usr/include/curses; and some OpenGL includes go in /usr/include/GL. I would think that gmp header files should go in, say, /usr/include/gmp. You could put the C++ header files in the same place.

    If you did this, rather than going
    Code:
    #include <gmp/gmpxx.h>
    in your code, consider adding /usr/include/gmp to the include path and just using
    Code:
    #include "gmpxx.h"
    You can add a path to the search path for header files with the gcc/g++ option
    Code:
    g++ -I /usr/include/gmp
    The space between -I and the rest of the path is optional.

    Also, if i try to compile a simple program using the c++ gmp classes, g++ gives me an error in the header file gmpxx.h - "Calling fdopen: No such file or directory". This is the program i am trying to compile:
    Code:
    #include <gmp.h>
    #include <gmpxx.h>
    
    int main()
    {
    	mpz_class a, b, c;
    	
    	a = 1423354;
    	return 0;
    }
    This is getting to me, i've shown the compiler the way to both library files and header files, and i've added "-lgmp -lgmpxx" just as the GMP documentation states, so why on earth isn't it working?
    Sticking "fdopen" into google gives you this page:
    Code:
    NAME
        fdopen - associate a stream with a file descriptor 
    
    SYNOPSIS
        #include <stdio.h>
    
        FILE *fdopen(int fildes, const char *mode);
    Apparently you need <stdio.h>. gmpxx.h should include it, but perhaps they forgot to . . . .

    Or maybe it's a runtime error. In which case, it's probably not something you've done wrong, because all of fdopen()'s (likely) errors seem to be programmer-related:
    Code:
    ERRORS
        The fdopen() function may fail if: 
    
        [EBADF]
            The fildes argument is not a valid file descriptor. 
        [EINVAL]
            The mode argument is not a valid mode. 
        [EMFILE]
            {FOPEN_MAX} streams are currently open in the calling process. 
        [EMFILE]
            {STREAM_MAX} streams are currently open in the calling process. 
        [ENOMEM]
            Insufficient space to allocate a buffer.
    Unless you're using a lot of memory or opening a lot of streams, it's going to be either EBADF, in which case whatever file descriptor being passed to fdopen() is invalid, or the mode is invalid (which is really unlikely if they tested gmpxx even once!).

    So . . . maybe some file or another can't be opened. Does gmpxx have a runtime? Perhaps putting your header and library files in a standard place would help, although I don't see how it could . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #17
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by dwks View Post
    So . . . maybe some file or another can't be opened. Does gmpxx have a runtime? Perhaps putting your header and library files in a standard place would help, although I don't see how it could . . .
    Thanks alot for the lengthy reply - i tried putting the gmp header into its own folder and then compiling it with the -i flag. This got me a million errors, so i tried specifying the new location of the header files in the #include in my program, but still:

    "calling fdopen: no such file or directory"

    So what do i do?

    I'm not quite sure i understand what you mean by gmpxx having a runtime? Can you clarify ?

  3. #18
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by Neo1 View Post
    Thanks alot for the lengthy reply - i tried putting the gmp header into its own folder and then compiling it with the -i flag. This got me a million errors, so i tried specifying the new location of the header files in the #include in my program, but still:

    "calling fdopen: no such file or directory"

    So what do i do?
    After reading this page, I think I know what is happening. Perhaps g++ is spitting out that error because one of the paths in its search paths (for include files, or for libraries) doesn't exist.

    You could run "g++ -print-search-dirs" and make sure each of those directories exists, but beware that the list is going to be long. Besides, if your compiler compiles other programs than that's not going to be the problem.

    What is the exact -I option that you were passing to g++? If you put the GMP files in /usr/include/gmp (or c:\cygwin\usr\include\gmp) like I suggested, try
    Code:
    g++ -I /usr/include/gmp ...
    or
    Code:
    g++ -I c:/cygwin/usr/include/gmp ...
    Do you get that error whilst compiling, linking, or running your program?

    I'm not quite sure i understand what you mean by gmpxx having a runtime? Can you clarify ?
    Some libraries are dynamically linked. This means that much of the code in the library is in an external file, rather than becoming part of your executable, which is the case with static libraries (such as GMP). The nice thing about dynamic libraries is that you can load them into memory once, and use them with many different programs; whereas statically linked libraries have to be loaded into memory for each program along with the rest of the executable. A "runtime" is usually a dynamically linked library.

    But I'm pretty sure that GMP is statically linked.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #19
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by dwks View Post
    After reading this page, I think I know what is happening. Perhaps g++ is spitting out that error because one of the paths in its search paths (for include files, or for libraries) doesn't exist.

    You could run "g++ -print-search-dirs" and make sure each of those directories exists, but beware that the list is going to be long. Besides, if your compiler compiles other programs than that's not going to be the problem.

    What is the exact -I option that you were passing to g++? If you put the GMP files in /usr/include/gmp (or c:\cygwin\usr\include\gmp) like I suggested, try
    Code:
    g++ -I /usr/include/gmp ...
    or
    Code:
    g++ -I c:/cygwin/usr/include/gmp ...
    Do you get that error whilst compiling, linking, or running your program?


    Some libraries are dynamically linked. This means that much of the code in the library is in an external file, rather than becoming part of your executable, which is the case with static libraries (such as GMP). The nice thing about dynamic libraries is that you can load them into memory once, and use them with many different programs; whereas statically linked libraries have to be loaded into memory for each program along with the rest of the executable. A "runtime" is usually a dynamically linked library.

    But I'm pretty sure that GMP is statically linked.
    I tried compiling it with the following path: "-IC:/MINGW/include/gmp" - the gmp folder is where the 2 headers are located, but it just got me rather long "undefined reference" errors?

    Btw, the program i'm compiling now looks like this, just to clarify:

    Code:
    #include "gmpxx.h"
    #include "gmp.h"
    #include <stdio.h>
    
    int main()
    {
         mpz_class a, b, c;
    
         a = 14324234;
         return 0;
    }
    Oh and i get the errors while compiling...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GNU textinfo
    By Mario F. in forum Tech Board
    Replies: 0
    Last Post: 12-04-2006, 08:20 PM
  2. Can anyone using mingw compile this?
    By deoren in forum Linux Programming
    Replies: 4
    Last Post: 03-18-2003, 11:18 AM
  3. Gnu Gcc
    By JasonLikesJava in forum Windows Programming
    Replies: 2
    Last Post: 03-07-2002, 12:34 PM
  4. Gnu Gcc with Windows
    By JasonLikesJava in forum C++ Programming
    Replies: 0
    Last Post: 03-06-2002, 12:40 PM