Menu

Creating lib file from dll file

Eric T
2008-05-07
2012-09-26
  • Eric T

    Eric T - 2008-05-07

    Hi all,

    I'm using Dev-C++ 4.9.9.2 on Windows XP, and I have a 3rd-party dll file, along with a header file (.h) and .def file, but no library file (either .lib or .a).

    So, I would like to create one, using dlltool, which is in the /bin directory of the Dev-C++ distribution.

    But, I don't think I'm doing it right, because the man pages for dlltool seem to suggest that all that is needed to create the lib file is the def file? But the def file is just a list of the routines in the dll file, i.e. it's a small file. Without reference to the dll file, how can the library file contain any programs, i.e. executable code?

    Could someone who has done this before please tell me what the dlltool command should look like, to create a library file?

    Also, once the .a library file is created, I should place it in the Dev-C++ /lib directory, and should also place the .h file in the /include directory, but what about the .def and .dll files, do they go anywhere? I noticed that in the Dev-C++ distribution, there is a dll file libmySQL.dll in the /dll directory, as well as a library libmySQL.a and def file libmySQL.def in the /lib directory. Is that required, then?

    Thanks for your help!

     
    • Eric T

      Eric T - 2008-05-12

      Just to follow up, I've written a short program that, according to the designers of the code, should work. Here it is:

      include <fftw3.h>

      int main()
      {
      int N = 1024;

      fftw_complex in out;

      in = (fftw_complex) fftw_malloc(sizeof(fftw_complex)N);
      out = (fftw_complex) fftw_malloc(sizeof(fftw_complex)N);

      fftw_free(in);
      fftw_free(out);

      system("PAUSE");
      return 0;
      }

      I link with -lfftw3-3, where libfftw3-3.a is the import library I created with dlltool, and placed in the /lib subdirectory of MinGW/Dev-C++. I tried placing libfftw3-3.dll, the dll file that was provided by distribution, in various places (see previous message), but keep having the compilation fail. In fact, the linking stage is never reached, it can't even compile this code. I looked in the file fftw3.h (included with distribution, and placed in /include subdirectory of MinGW/Dev-C++), and it does not have the phrase "fftw_complex" in it. Does that mean I'm missing a header file? Must the header file define this phrase for the code to compile? Or, can it be gotten from the dll file somehow? But since it doesn't get to the linking stage, I'm not sure what to do. Here's the compilation log:

      Executing make...
      make.exe -f "C:\Documents and Settings\Owner\My Documents\FFTW\Makefile.win" all
      gcc.exe -c test_fftw.c -o test_fftw.o -I"C:/Dev-Cpp/include"

      test_fftw.c: In function main': test_fftw.c:7: error: syntax error before '*' token test_fftw.c:9: error:in' undeclared (first use in this function)
      test_fftw.c:9: error: (Each undeclared identifier is reported only once
      test_fftw.c:9: error: for each function it appears in.)

      test_fftw.c:10: error: `out' undeclared (first use in this function)

      make.exe: *** [test_fftw.o] Error 1

      Execution terminated

       
    • Eric T

      Eric T - 2008-05-13

      Final Wrap-Up:

      Silly me, there was an error in the above code (should be comma between in and out). Now the test program compiles fine. This allowed me by process of trial and error to figure out where one places the dll file. The answer:
      In the /bin directory!

      If anyone is following this with a similar problem, I hope this will be of help to you.

       
      • cpns

        cpns - 2008-05-14

        > This allowed me by process of trial and error to figure
        > out where one places the dll file. The answer:
        > In the /bin directory!

        Uh!? Why was it a process of trial and error when I told you the answer!?

        Your answer is wrong. Or rather not a good idea. What happens when you deploy this on a machine that does not have Dev-C++ installed!? It only works because on your machine c:\dev-cpp\bin is defined in the PATH environment variable. The key is the PATH environment variable!

        Clifford

         
    • cpns

      cpns - 2008-05-07

      >> Without reference to the dll file, how can
      >> the library file contain any programs,

      There are two kinds of library file, a static library, and an export library. Export libraries contain little more that symbols and a reference to the DLL file that will resolve them at run-time. That is what dynamic-linking means, linking your code to the library code at runtime rather than compile time.

      dlltool can create an export library without a DEF file. It will extract the symbols from the DLL itself if necessary.

      You can also load the DLL without an export library at runtime using LoadLibrary(). You then have to obtain the necessary entry points using GetProcAddress().

      Clifford

       
    • Eric T

      Eric T - 2008-05-08

      Thanks, Clifford, I really appreciate your help.

      I think I've now successfully created the .a library file, using dlltool.
      I know it goes in the /lib directory. But where does the .dll file go?
      Does it also go in the /lib directory, or in my local working directory, or in the /dll directory, or in some Windows system directory?

      I've tried the LoadLibrary thing in the past (with a different dll), but got flaky results, so I'd like to get the export-library thing to work.

      Thanks again!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.