首页 > 解决方案 > Haskell / cabal:可以链接到macos上的.so文件吗?

问题描述

在 Mac 上,我已经完成了brew install freetds,这给了我一个文件libtdsodbc.so。现在我尝试通过将路径放在我的.cabal中来链接到它extra-lib-dirs,但我得到了

* Missing (or bad) C library: tdsodbc
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.

这样做stack build --verbose向我展示了失败的命令是 cabal configure,所以我再次运行它并-v3附加,它告诉我:

/usr/bin/gcc -fno-stack-protector /var/folders/bq/4xy9knvx413dwltf9c6ngvvm0000gt/T/29185-4.c -o /var/folders/bq/4xy9knvx413dwltf9c6ngvvm
0000gt/T/29185-5 '-D__GLASGOW_HASKELL__=804' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' '-Ddarwin_HOST_OS=1' '-Dx86_64_HOST_ARCH=1' -
I.stack-work/dist/x86_64-osx/Cabal-2.2.0.1/build/autogen -I. -I/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/base-4
.11.1.0/include -I/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0/include -I/Users/unhammer/.stac
k/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/include -ltdsodbc -L/Users/unhammer/src/tds/lib -L/Users/unhammer/.stack/programs/x86_64-o
sx/ghc-8.4.3/lib/ghc-8.4.3/base-4.11.1.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0 -L/Use
rs/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/ghc-prim-0.5.2.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/l
ib/ghc-8.4.3/rts                                                                                                   
/usr/bin/gcc returned ExitFailure 1 with error message:
ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file
'/Users/unhammer/src/tds/lib/libtdsodbc.so' for architecture x86_64                                                                     
clang: error: linker command failed with exit code 1 (use -v to see                                                                     
invocation)                                                                                                                             
/usr/bin/gcc -fno-stack-protector /var/folders/bq/4xy9knvx413dwltf9c6ngvvm0000gt/T/29185-6.c -o /var/folders/bq/4xy9knvx413dwltf9c6ngvvm
0000gt/T/29185-7 -ltdsodbc -L/Users/unhammer/src/tds/lib -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/base-4.11.1.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/ghc-prim-0.5.2.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/rts             
/usr/bin/gcc returned ExitFailure 254 with error message:
ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file
'/Users/unhammer/src/tds/lib/libtdsodbc.so' for architecture x86_64
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
/usr/bin/gcc -fno-stack-protector /var/folders/bq/4xy9knvx413dwltf9c6ngvvm0000gt/T/29185-8.c -o /var/folders/bq/4xy9knvx413dwltf9c6ngvvm
0000gt/T/29185-9 -ltdsodbc -L/Users/unhammer/src/tds/lib -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/base-4.11.
1.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0 -L/Users/unhammer/.stack/programs/x86_64-os
x/ghc-8.4.3/lib/ghc-8.4.3/ghc-prim-0.5.2.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/rts
/usr/bin/gcc returned ExitFailure 1 with error message:
ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file
'/Users/unhammer/src/tds/lib/libtdsodbc.so' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
/usr/bin/gcc -fno-stack-protector /var/folders/bq/4xy9knvx413dwltf9c6ngvvm0000gt/T/29185-10.c -o /var/folders/bq/4xy9knvx413dwltf9c6ngvv
m0000gt/T/29185-11 -c '-D__GLASGOW_HASKELL__=804' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' '-Ddarwin_HOST_OS=1' '-Dx86_64_HOST_ARCH
=1' -I.stack-work/dist/x86_64-osx/Cabal-2.2.0.1/build/autogen -I. -I/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/b
ase-4.11.1.0/include -I/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0/include -I/Users/unhammer/
.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/include                                                                              

为什么不能ld链接到 MH_BUNDLE?cabal 只能链接到dylibmac 上的 's,还是我需要一些特殊选项?


编辑:通过链接到.so链接到的dylib来解决。

标签: macoshaskellshared-librariescabaldylib

解决方案


推荐阅读