libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

make DLL import library for an executable?


From: Bryce Denney
Subject: make DLL import library for an executable?
Date: Tue, 15 Oct 2002 00:19:07 -0400 (EDT)

Hi.  I'm trying to use libtool in cygwin to make plugins for the Bochs x86
Emulator project.  I want to build the executable with exported symbols,
and then build DLLs (plugins) that automatically import those symbols when
the plugin is loaded.  To do this, I plan to first build the executable
with an export table, and make a import library.  Then, plugin DLLs are
linked against the import library.  When the executable loads a plugin DLL
with LoadLibrary, all its references to symbols in the main executable are
resolved automatically.  The executable then uses GetProcAddress to find a
few symbols in the DLL, and it's ready to go.

I have tried lots of variations of libtool commands but I have not figured
out any way to accomplish this task using libtool.  I can get libtool to
make an import library for a DLL, but I can't get it to make an import
library for an executable.  However, I can do it using a special make
target that runs a few dlltool commands directly.  Is there any way to
write this using libtool, or must I use a special makefile target to build
the binary and plugin DLLs in cygwin?

Here is a tiny TAR file with sample code which builds and runs correctly
on my cygwin box.  It does not use libtool.
http://bochs.sf.net/tmp/test7-win32dll.tar.gz

It should build and run like this:

cygwin$ make
g++ -mno-cygwin -c -o main.o ./main.cc
In file included from ./main.cc:4:
main.h:3: warning: #warning I will export DLL symbols for MAIN
dlltool --export-all --output-def main.def main.o
dlltool --dllname main.exe --def main.def --output-lib main.a
dlltool --dllname main.exe --output-exp main.exp --def main.def
g++ -mno-cygwin -o main main.exp main.o
rm main.exp main.def
g++ -mno-cygwin -shared -o module1.dll ./module1.cc main.a
In file included from ./module1.cc:2:
main.h:6: warning: #warning I will import DLL symbols from MAIN
g++ -mno-cygwin -shared -o module2.dll ./module2.cc main.a
In file included from ./module2.cc:2:
main.h:6: warning: #warning I will import DLL symbols from MAIN
cygwin$ ./main
start
loading module1
loading module from module1.dll
handle is 0x10000000
module_init function is at 0x1000107C
Calling module_init
module1 init for main version uselib-test6-1.0
register_module was called by module 'module1'
loading module from module2.dll
handle is 0x00C60000
module_init function is at 0x00C6107C
Calling module_init
module2 init for main version uselib-test6-1.0
register_module was called by module 'module2'
stop


If there is a libtool syntax that would make it build the import library
and exports table for the executable, I would love to hear about it.  I
tried -export-dynamic, which sounds like the right choice, but it didn't
do anything.  I tried adding "main" or "main.exe" to the link line for the
modules, but it also made no difference.  Some of my attempts are included
below if you are interested.  Any suggestions?

Thanks,
Bryce Denney


--------------------------------------------
Build attempts using libtool 1.4.2:
libtool gcc -mno-cygwin -c main.cc
libtool gcc -mno-cygwin -export-dynamic -o main main.lo
libtool gcc -mno-cygwin -c module1.cc
libtool gcc -mno-cygwin -no-undefined -module -o libmodule1.la module1.lo
-rpath `pwd`/lib

The last line fails with module1.cc: undefined reference to
`_imp__version_string' and :module1.cc: undefined reference to `import
stub for register_module(char const *)'.  Try to link with main.exe, since
it exports the symbols that we need.

libtool gcc -mno-cygwin -no-undefined -module -o libmodule1.la module1.lo
-rpath `pwd`/lib main

Same error, try main.exe.

libtool gcc -mno-cygwin -no-undefined -module -o libmodule1.la module1.lo
-rpath `pwd`/lib main.exe

Same error, try main.la??

libtool gcc -mno-cygwin -no-undefined -module -o libmodule1.la module1.lo
-rpath `pwd`/lib main.la

libtool: link: cannot find the library `main.la'





reply via email to

[Prev in Thread] Current Thread [Next in Thread]