linking ghc object files with mingw-g++

Hi! I'm trying to link ghc object files with mingw's g++/ld... The following shows that linking ghc code with C code can be done very easily: $ cat > Test.hs module Test where foreign export ccall test :: IO () test = putStr "Hello from Haskell World!\n" $ cat > main.c #include "RtsApi.h" #include "Test_stub.h" #ifdef __cplusplus extern "C" #endif void __stginit_Test(void); int main(int argc, char *argv[]) { startupHaskell(argc, argv, __stginit_Test); test(); shutdownHaskell(); } $ ghc -ffi -c Test.hs -o Test.o $ gcc -c Test_stub.c -Ic:/ghc/ghc-5.04.3/include $ gcc -c main.c -Ic:/ghc/ghc-5.04.3/include $ ghc -no-hs-main main.o Test.o Test_stub.o $ ./a.out Hello from Haskell World! The procedure above works well with gcc; g++ object files seem to depend on a rt-lib or something, which ghc does not link into the executable by default. $ g++ -c main.cpp -Ic:/ghc/ghc-5.04.3/include $ ghc -no-hs-main main.o Test.o Test_stub.o main.o(.text+0x22):main.cpp: undefined reference to `__stginit_Test()' main.o(.eh_frame+0x11):main.cpp: undefined reference to `__gxx_personality_v0' The other way round, linking the files with gcc/ld, using $ gcc main.c Test_stub.c -Ic:/ghc/ghc-5.04.3/include \ c:/ghc/ghc-5.04.3/HSbase1.o \ c:/ghc/ghc-5.04.3/HSbase2.o \ c:/ghc/ghc-5.04.3/HSbase3.o \ c:/ghc/ghc-5.04.3/HSbase_cbits.o \ c:/ghc/ghc-5.04.3/HStext.o \ c:/ghc/ghc-5.04.3/HStext_cbits.o \ c:/ghc/ghc-5.04.3/HSlang.o \ c:/ghc/ghc-5.04.3/HSlang_cbits.o \ c:/ghc/ghc-5.04.3/HShaskell98.o \ c:/ghc/ghc-5.04.3/HSrts.o \ -lgmp Test.o -lwsock32 -lgmp -lwinmm results in c:/ghc/ghc-5.04.3/HSrts.o(.text+0x9ff8): multiple definition of `main' c:\DOKUME~1\jgoetz\LOKALE~1\Temp/ccWKaaaa.o(.text+0x0):main.c: first defined here c:/ghc/ghc-5.04.3/HSrts.o(.text+0xa00e): undefined reference to `__stginit_Main' c:/ghc/ghc-5.04.3/HSrts.o(.text+0xa01f): undefined reference to `Main_zdmain_closure' I'm stuck... Is there a way to merge ghc code with c++ code? What am I doing wrong? Do you think it's possible to link ghc object code with Metrowerks and MSVC? btw, I'm using ghc-5.04.3, windows binary distribution and current mingw g++ Thanks, Johannes johago@web.de

Hello again! This is gvc -v output: Hsc static flags: -static -fignore-interface-pragmas -fomit-interface-pragmas -f do-lambda-eta-expansion -flet-no-escape *** Linker c:\ghc\ghc-5.04.3\gcc -B"c:\ghc\ghc-5.04.3\gcc-lib/" "-v" "-o" "a.out" "-DDONT_W ANT_WIN32_DLL_SUPPORT" "main.o" "Test.o" "Test_stub.o" "-Lc:/ghc/ghc-5.04.3" "-L c:/ghc/ghc-5.04.3/gcc-lib" "-lHShaskell98" "-lHSbase" "-lHSbase_cbits" "-lwsock3 2" "-lmsvcrt" "-lkernel32" "-luser32" "-lHSrts" "-lm" "-lgmp" "-lwinmm" "-lwsock 32" "-u" "_GHCziBase_Izh_static_info" "-u" "_GHCziBase_Czh_static_info" "-u" "_G HCziFloat_Fzh_static_info" "-u" "_GHCziFloat_Dzh_static_info" "-u" "_GHCziPtr_Pt r_static_info" "-u" "_GHCziWord_Wzh_static_info" "-u" "_GHCziInt_I8zh_static_inf o" "-u" "_GHCziInt_I16zh_static_info" "-u" "_GHCziInt_I32zh_static_info" "-u" "_ GHCziInt_I64zh_static_info" "-u" "_GHCziWord_W8zh_static_info" "-u" "_GHCziWord_ W16zh_static_info" "-u" "_GHCziWord_W32zh_static_info" "-u" "_GHCziWord_W64zh_st atic_info" "-u" "_GHCziStable_StablePtr_static_info" "-u" "_GHCziBase_Izh_con_in fo" "-u" "_GHCziBase_Czh_con_info" "-u" "_GHCziFloat_Fzh_con_info" "-u" "_GHCziF loat_Dzh_con_info" "-u" "_GHCziPtr_Ptr_con_info" "-u" "_GHCziPtr_FunPtr_con_info " "-u" "_GHCziStable_StablePtr_con_info" "-u" "_GHCziBase_False_closure" "-u" "_ GHCziBase_True_closure" "-u" "_GHCziPack_unpackCString_closure" "-u" "_GHCziIOBa se_stackOverflow_closure" "-u" "_GHCziIOBase_heapOverflow_closure" "-u" "_GHCziI OBase_NonTermination_closure" "-u" "_GHCziIOBase_BlockedOnDeadMVar_closure" "-u" "_GHCziIOBase_Deadlock_closure" "-u" "_GHCziWeak_runFinalizzerBatch_closure" "- u" "___stginit_Prelude" Reading specs from c:/ghc/ghc-5.04.3/gcc-lib/specs gcc version 2.95.3-6 (mingw special) $ c:/ghc/ghc-5.04.3/gcc-lib/ld.exe -Bdynamic -o a.out -u _GHCziBase_Izh_static_ info -u _GHCziBase_Czh_static_info -u _GHCziFloat_Fzh_static_info -u _GHCziFloa t_Dzh_static_info -u _GHCziPtr_Ptr_static_info -u _GHCziWord_Wzh_static_info -u _GHCziInt_I8zh_static_info -u _GHCziInt_I16zh_static_info -u _GHCziInt_I32zh_s tatic_info -u _GHCziInt_I64zh_static_info -u _GHCziWord_W8zh_static_info -u _GH CziWord_W16zh_static_info -u _GHCziWord_W32zh_static_info -u _GHCziWord_W64zh_s tatic_info -u _GHCziStable_StablePtr_static_info -u _GHCziBase_Izh_con_info -u _GHCziBase_Czh_con_info -u _GHCziFloat_Fzh_con_info -u _GHCziFloat_Dzh_con_info -u _GHCziPtr_Ptr_con_info -u _GHCziPtr_FunPtr_con_info -u _GHCziStable_StableP tr_con_info -u _GHCziBase_False_closure -u _GHCziBase_True_closure -u _GHCziPac k_unpackCString_closure -u _GHCziIOBase_stackOverflow_closure -u _GHCziIOBase_h eapOverflow_closure -u _GHCziIOBase_NonTermination_closure -u _GHCziIOBase_Bloc kedOnDeadMVar_closure -u _GHCziIOBase_Deadlock_closure -u _GHCziWeak_runFinaliz zerBatch_closure -u ___stginit_Prelude c:/ghc/ghc-5.04.3/gcc-lib/crt2.o -Lc:/gh c/ghc-5.04.3 -Lc:/ghc/ghc-5.04.3/gcc-lib -Lc:/ghc/ghc-5.04.3/gcc-lib -L/ming w/l ib/gcc-lib/mingw32/2.95.3-6/../../../../mingw32/lib -L/mingw/lib/gcc-lib/min gw3 2/2.95.3-6/../../.. main.o Test.o Test_stub.o -lHShaskell98 -lHSbase -lHSbase_c bits -lwsock32 -lmsvcrt -lkernel32 -luser32 -lHSrts -lm -lgmp -lwinmm -lwsoc k32 -lmingw32 -lgcc -lmoldname -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell3 2 - lmingw32 -lgcc -lmoldname -lmsvcrt main.o(.eh_frame+0x11):main.cpp: undefined reference to `__gxx_personality_v0' Any hint what this __gxx_personality_v0 means? Johannes johago@web.de

| I'm trying to link ghc object files with mingw's | g++/ld... We have used the g++-2 compiler that you can get with Cygwin and it seems to work fine. (mingw-g++ and the normal g++ did not work for us.) Another hint: maybe you should give "-lstdc++" as a flag to the final linking fase. A final hint: I have heard rumours of people changing the linker that GHC uses to be g++'s linker, maybe that helps in your case. Apparently, some C++ code requires special treatment at linking time, something that normal ld does not do. /Koen

Good morning! Thanks very much for your help... Compiling everything with cygwin c++-2 / gcc-2 works fine for me.
| I'm trying to link ghc object files with mingw's | g++/ld...
We have used the g++-2 compiler that you can get with Cygwin and it seems to work fine. (mingw-g++ and the normal g++ did not work for us.)
Another hint: maybe you should give "-lstdc++" as a flag to the final linking fase.
A final hint: I have heard rumours of people changing the linker that GHC uses to be g++'s linker, maybe that helps in your case. Apparently, some C++ code requires special treatment at linking time, something that normal ld does not do.
Johannes johago@web.de
participants (2)
-
johago@web.de
-
Koen Claessen