简体   繁体   中英

Linking cabalized Haskell package to C program (undefined reference linker error)

My link command is:

gcc -O2 -m32 -o ParseInt.exe ParseInt.o hsbracket.o \
    -L../../dist/ia32/build -lffi -lHSarray-0.5.0.0-ghc7.8.3 \
    -lHSbin-package-db-0.0.0.0-ghc7.8.3 -lHSbinary-0.7.1.0-ghc7.8.3 \
    -lHSbytestring-0.10.4.0-ghc7.8.3 -lHSCabal-1.18.1.3-ghc7.8.3 \
    -lHScontainers-0.5.5.1-ghc7.8.3 -lHSdeepseq-1.3.0.2-ghc7.8.3 \
    -lHSdirectory-1.2.1.0-ghc7.8.3 -lHSfilepath-1.3.0.2-ghc7.8.3 \
    -lHSghc-7.8.3-ghc7.8.3 -lHSghc-prim-0.3.1.0-ghc7.8.3 \
    -lHShaskeline-0.7.1.2-ghc7.8.3 -lHShaskell2010-1.1.2.0-ghc7.8.3 \
    -lHShaskell98-2.0.0.3-ghc7.8.3 -lHShoopl-3.10.0.1-ghc7.8.3 \
    -lHShpc-0.6.0.1-ghc7.8.3 -lHSinteger-gmp-0.5.1.0-ghc7.8.3 \
    -lHSold-locale-1.0.0.6-ghc7.8.3 -lHSold-time-1.1.0.2-ghc7.8.3 \
    -lHSpads-haskell-1.1-ghc7.8.3 -lHSpretty-1.1.1.1-ghc7.8.3 \
    -lHSprocess-1.2.0.0-ghc7.8.3 -lHSrts-ghc7.8.3 \
    -lHSrts_debug-ghc7.8.3 -lHSrts_l-ghc7.8.3 -lHSrts_thr-ghc7.8.3 \
    -lHSrts_thr_debug-ghc7.8.3 -lHSrts_thr_l-ghc7.8.3 \
    -lHStemplate-haskell-2.9.0.0-ghc7.8.3 -lHSterminfo-0.4.0.0-ghc7.8.3 \
    -lHStime-1.4.2-ghc7.8.3 -lHStransformers-0.3.0.0-ghc7.8.3 \
    -lHSunix-2.7.0.1-ghc7.8.3 -lHSxhtml-3000.2.1-ghc7.8.3 \
    -lHSbase-4.7.0.1-ghc7.8.3  -Wl,-melf_i386

and I'm getting a bunch of errors like:

ParseInt.o: In function `main':
ParseInt.c:(.text.startup+0x16): undefined reference to `test'
../../dist/ia32/build/libHSrts-ghc7.8.3.so: undefined reference to `base_GHCziWord_W16zh_con_info'
../../dist/ia32/build/libHSrts-ghc7.8.3.so: undefined reference to `base_GHCziConcziSync_runSparks_closure'
../../dist/ia32/build/libHSrts-ghc7.8.3.so: undefined reference to `base_ControlziExceptionziBase_nonTermination_closure'

but the undefined references are defined in the base .so I linked against:

$ nm ../../dist/ia32/build/libHSbase-4.7.0.1-ghc7.8.3.so | grep base_GHCziWord_W16zh_con_info
26690:00550884 T base_GHCziWord_W16zh_con_info
$ nm ../../dist/ia32/build/libHSrts-ghc7.8.3.so | grep base_GHCziWord_W16zh_con_info
104:         U base_GHCziWord_W16zh_con_info

So why doesn't libHSrts see things defined in libHSbase ? I was following the directions here: http://www.vex.net/~trebla/haskell/so.xhtml , and had ParseInt.exe correctly linking at one point but then I added some libraries to the cabal package / wrote a bunch more Haskell code ( ParseInt.c and hsbracket.c did not change).

I've read about linking order ( https://stackoverflow.com/a/409470/1542000 ), and rts is earlier in the link command than the base library it depends on, so I'm not sure why I'm getting undefined references.

I was dumb and missed the obvious: try to fix the first error gcc printed.

I managed to get the test function removed from the exported modules in my cabal package. Upon re-building the cabal package with test added to the .so , all the linking errors went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM