rpath & shared libraries in ghc 7.10.1
Suppose that I have :
//test.h
int add(int a, int b);
//test.c
int add(int a, int b){
return (a + b);
}
//mylib.c
#include "test.h"
int testAdd(){
return add(2,3);
}
Then I compile via :
gcc -shared -o libDir/libtest.so test.c
gcc -fPIC -c mylib.c -o mylib.o
gcc -shared -o libDir/libMy.so mylib.o -L./libDir -l test -Wl,-rpath=./libDir
Then I have Main.hs with :
module Main where
import Foreign.C.Types
foreign import ccall "testAdd" c_testAdd :: CInt -> CInt -> IO (CInt)
main = do
result <- c_testAdd 3 4
print result
and I have the associated cabal file :
name: illustrate
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10
executable illustrate
main-is: Main.hs
build-depends: base >=4.8 && <4.9
default-language: Haskell2010
extra-libraries: test My
extra-lib-dirs: ./libDir
Then cabal repl
works fine, but upon cabal run
we get the following error :
cabal run
Preprocessing executable 'illustrate' for illustrate-0.1.0.0...
[1 of 1] Compiling Main ( Main.hs, dist/build/illustrate/illustrate-tmp/Main.o )
Linking dist/build/illustrate/illustrate ...
Running illustrate...
/home/linux/Downloads/illustrate_withDir/dist/build/illustrate/illustrate: error while loading shared libraries: libtest.so: cannot open shared object file: No such file or directory
In #10442 (closed)##10492 (closed) trommler mentions that the problem arises because -rpath
is not fed as an argument for libtest.so
during linking.
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | high |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | hvr, rwbarton, thoughtpolice, trommler |
Operating system | |
Architecture |