Bochs/bochs-testing/plugin-test/test7-win32dll
Bryce Denney dad1e7b3e9 - build the module symbol name myself instead of letting ltdl do it. On win32
I'm using ltdl even it considers my DLLs to NOT be a libtool archive, and
this is making the symbol name transformation mess up.  If I do it myself,
I can avoid this.
2002-10-17 06:49:44 +00:00
..
main.cc - build the module symbol name myself instead of letting ltdl do it. On win32 2002-10-17 06:49:44 +00:00
main.h
Makefile.in - move some makefile stuff that is common to all subdirs into 2002-10-16 04:09:24 +00:00
Makefile.vc - add makefile for VC++ 2002-10-14 20:44:02 +00:00
module1.cc
module2.cc
README - add notes about what works and what doesn't 2002-10-16 01:37:42 +00:00
uselib.out.expected - add expected output for test7 2002-10-16 13:10:31 +00:00

test7-win32dll

This is similar to test6, but Psyon helped me port the main.cc code to
use LoadLibrary/GetProcAddress and make a Makefile that actually works.






I found that even for a trivial example I cannot make a working executable
with main in a DLL.  Try making libmain a static library.  But then would
every module link in all the code, or still use an implementation lib?


Standard build:
/bin/sh.exe ../libtool g++ -mno-cygwin  -g -c main.cc
/bin/sh.exe ../libtool g++ -mno-cygwin -no-undefined -g -o libmain.la main.lo -rpath `pwd`/lib 
mkdir -p lib bin
/bin/sh.exe ../libtool cp libmain.la `pwd`/lib
/bin/sh.exe ../libtool g++ -mno-cygwin -no-undefined -g -o uselib libmain.la 
/bin/sh.exe ../libtool g++ -mno-cygwin  -g -c module1.cc
/bin/sh.exe ../libtool g++ -mno-cygwin -no-undefined -g -o libmodule1.la module1.lo -rpath `pwd`/lib libmain.la
mkdir -p lib bin
/bin/sh.exe ../libtool cp libmodule1.la `pwd`/lib
/bin/sh.exe ../libtool g++ -mno-cygwin  -g -c module2.cc
/bin/sh.exe ../libtool g++ -mno-cygwin -no-undefined -g -o libmodule2.la module2.lo -rpath `pwd`/lib libmain.la
mkdir -p lib bin
/bin/sh.exe ../libtool cp libmodule2.la `pwd`/lib

Try with libmain as a static lib.
/bin/sh.exe ../libtool g++ -ggdb -mno-cygwin  -g -c main.cc
/bin/sh.exe ../libtool g++ -ggdb -mno-cygwin -no-undefined -g -o libmain.la main.lo 
mkdir -p lib bin
/bin/sh.exe ../libtool cp libmain.la `pwd`/lib
/bin/sh.exe ../libtool g++ -ggdb -mno-cygwin -no-undefined -g -o uselib libmain.la 
/bin/sh.exe ../libtool g++ -ggdb -mno-cygwin  -g -c module1.cc
/bin/sh.exe ../libtool g++ -ggdb -mno-cygwin -no-undefined -g -o libmodule1.la module1.lo -rpath `pwd`/lib libmain.la
mkdir -p lib bin
/bin/sh.exe ../libtool cp libmodule1.la `pwd`/lib
/bin/sh.exe ../libtool g++ -ggdb -mno-cygwin  -g -c module2.cc
/bin/sh.exe ../libtool g++ -ggdb -mno-cygwin -no-undefined -g -o libmodule2.la module2.lo -rpath `pwd`/lib libmain.la
mkdir -p lib bin
/bin/sh.exe ../libtool cp libmodule2.la `pwd`/lib



How to make an import library for cygmodule2-0.dll
dlltool --as=as --dllname cygmodule2-0.dll --def .libs/cygmodule2-0.dll-def --output-lib .libs/libimp-cygmodule2-0.a

dll-def file is:
EXPORTS
 module_init @ 1 ; 
 n_operations @ 2 DATA ; 
 operate__Fii @ 3 ; 

---------------------------------------------
Here is what works:
g++ -mno-cygwin -c -o main.o ./main.cc
dlltool --export-all --output-def uselib.def main.o
dlltool --dllname uselib.exe --def uselib.def --output-lib uselib.a
dlltool --dllname uselib.exe --output-exp uselib.exp --def uselib.def
g++ -mno-cygwin -o uselib uselib.exp main.o 
rm uselib.exp uselib.def
g++ -mno-cygwin -shared -o module1.dll ./module1.cc uselib.a
g++ -mno-cygwin -shared -o module2.dll ./module2.cc uselib.a

What I wish would work:

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

That 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

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

Same error

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'

Try building import lib manually
libtool g++ -mno-cygwin -c main.cc
dlltool --export-all --output-def  main.def main.lo 
dlltool --dllname main.exe --def main.def --output-lib libmainimport.a
dlltool --dllname main.exe --def main.def --output-exp main.exp
libtool g++ -mno-cygwin -o main.exe main.lo main.exp

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






The important part is that module1 and module2 are linked with "main", 
the executable.  This would tell libtool that it should generate an
import library corresponding to main, relink main 


cygwin$ libtool gcc -mno-cygwin -c main.cc
mkdir .libs
gcc -mno-cygwin -c main.cc  -DDLL_EXPORT -DPIC -o .libs/main.lo
In file included from main.cc:4:
main.h:3: warning: #warning I will export DLL symbols for MAIN
gcc -mno-cygwin -c main.cc -o main.o >/dev/null 2>&1
mv -f .libs/main.lo main.lo
cygwin$ libtool gcc -mno-cygwin -export-dynamic -o main main.lo -rpath `pwd`/lib
gcc -mno-cygwin -o main.exe main.o -Wl,--export-dynamic   -Wl,--rpath -Wl,/home/bryce/bochs-testing/plugin-test/tmp/test7-win32dll/lib
cygwin$ libtool gcc -mno-cygwin -c module1.cc 
rm -f .libs/module1.lo
gcc -mno-cygwin -c module1.cc  -DDLL_EXPORT -DPIC -o .libs/module1.lo
In file included from module1.cc:2:
main.h:6: warning: #warning I will import DLL symbols from MAIN
gcc -mno-cygwin -c module1.cc -o module1.o >/dev/null 2>&1
mv -f .libs/module1.lo module1.lo
cygwin$ libtool gcc -mno-cygwin -no-undefined -module -o libmodule1.la module1.lo main -rpath `pwd`/lib
rm -fr .libs/libmodule1.la .libs/libmodule1.* .libs/libmodule1.*
generating symbol list for `libmodule1.la'
 dlltool --export-all --exclude-symbols DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12,DllMainCRTStartup@12,DllEntryPoint@12 --output-def .libs/cygmodule1-0.dll-def  module1.lo 
 sed -e "1,/EXPORTS/d" -e "s/ @ [0-9]*//" -e "s/ *;.*$//" < .libs/cygmodule1-0.dll-def > .libs/libmodule1.exp
if test "x`head -1 .libs/libmodule1.exp`" = xEXPORTS; then cp .libs/libmodule1.exp .libs/cygmodule1-0.dll-def; else echo EXPORTS > .libs/cygmodule1-0.dll-def; _lt_hint=1; cat .libs/libmodule1.exp | while read symbol; do set dummy $symbol; case $# in 2) echo " $2 @ $_lt_hint ; " >> .libs/cygmodule1-0.dll-def;; *) echo " $2 @ $_lt_hint $3 ; " >> .libs/cygmodule1-0.dll-def;; esac; _lt_hint=`expr 1 + $_lt_hint`; done; fi
 gcc -Wl,--base-file,.libs/cygmodule1-0.dll-base -Wl,--dll -nostartfiles -Wl,-e,__cygwin_dll_entry@12 -o .libs/cygmodule1-0.dll  module1.lo  
module1.lo(.text+0x37):module1.cc: undefined reference to `_imp__version_string'
module1.lo(.text+0x55):module1.cc: undefined reference to `import stub for register_module(char const *)'
collect2: ld returned 1 exit status