
Hello, Can anyone give me some tips concerning the following error: myPrompt> ghc --make -fffi f.hs -l mylib.lib ghc --make -fffi f.hs -l mylib.lib [1 of 1] Compiling Main ( f.hs, f.o ) Linking f.exe ... d:\ghc\ghc6.6\gcc-lib\ld.exe: cannot find -l-Ld:/ghc/ghc6.6 collect2: ld returned 1 exit status thanks, Jeff

On May 29, 2007, at 23:01 , jeff p wrote:
myPrompt> ghc --make -fffi f.hs -l mylib.lib
For historical reasons, you can't have a space between the -l and the library name. It's inserting an empty library name into the link command, which is producing the odd "cannot find" error. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Hello,
On 5/29/07, Brandon S. Allbery KF8NH
On May 29, 2007, at 23:01 , jeff p wrote:
myPrompt> ghc --make -fffi f.hs -l mylib.lib
For historical reasons, you can't have a space between the -l and the library name. It's inserting an empty library name into the link command, which is producing the odd "cannot find" error.
Ok. Now I get another error: myPrompt> ghc --make -fffi f.hs -lmylib.lib ghc --make -fffi f.hs -lmylib.lib Linking f.exe ... d:\ghc\ghc6.6\gcc-lib\ld.exe: cannot find -lmylib.lib collect2: ld returned 1 exit status which is strange because the file mylib.lib is in the same directory as the haskell code. Any thoughts? thanks, Jeff

On May 29, 2007, at 23:09 , jeff p wrote:
d:\ghc\ghc6.6\gcc-lib\ld.exe: cannot find -lmylib.lib collect2: ld returned 1 exit status
which is strange because the file mylib.lib is in the same directory as the haskell code.
Typically -l appends the necessary extension itself (.lib on Windows, .a or .so on Unix, .a or .dylib on OSX). You may also need - L. (again, no space) to make it check the current directory. It may be easier to see if ghc has an option to pass through the next argument straight to the linker, or even recognizes .lib files and passes them through unchanged (then you'd not need any option to include it, just the filename). Unfortunately my knowledge of ghc on Windows is rather sketchy. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Hello, Thanks for the tips. I've gotten to the point where linking fails on an undefined reference. The strange thing about this is that when I make a C program to call the library function and compile with: myPrompt> gcc f.c mylib.lib everything works fine. I think ghc is using it's own version of gcc and ld which aren't happy about my library. Does this seem possible? thanks, Jeff

On Tue, May 29, 2007 at 11:48:18PM -0400, jeff p wrote:
Hello,
Thanks for the tips. I've gotten to the point where linking fails on an undefined reference. The strange thing about this is that when I make a C program to call the library function and compile with:
myPrompt> gcc f.c mylib.lib
everything works fine. I think ghc is using it's own version of gcc and ld which aren't happy about my library. Does this seem possible?
No, but ghc does pass a lot of funny flags... Double check ccall v. stdcall in the import declaration. That bites a lot of people on Windows. Stefan

Hello,
No, but ghc does pass a lot of funny flags...
Double check ccall v. stdcall in the import declaration. That bites a lot of people on Windows.
My import statement originally looked like: foreign import ccall "mylib.h myFun" my_fun :: CDouble -> IO (Ptr CDouble) and my original linker error was an undefined reference to 'myFun'. Changing the import statement to: foreign import stdcall "mylib.h myFun" my_fun :: CDouble -> IO (Ptr CDouble) results in the linker complaining about undefined reference to 'myFun@24'. I also tried throwing in "static" but it seems to have no effect. thanks, Jeff

On Wed, May 30, 2007 at 12:28:43AM -0400, jeff p wrote:
Hello,
No, but ghc does pass a lot of funny flags...
Double check ccall v. stdcall in the import declaration. That bites a lot of people on Windows.
My import statement originally looked like:
foreign import ccall "mylib.h myFun" my_fun :: CDouble -> IO (Ptr CDouble)
and my original linker error was an undefined reference to 'myFun'.
Changing the import statement to:
foreign import stdcall "mylib.h myFun" my_fun :: CDouble -> IO (Ptr CDouble)
results in the linker complaining about undefined reference to 'myFun@24'.
That is very very very suspicious. the number after the @ is the number of bytes of argument data, which should be 8 for a single CDouble on x86 - not 24.
I also tried throwing in "static" but it seems to have no effect.
What does the definition in the library look like? To be compatible with that import it should be: double *myFun(double); NOT any of: double *my_fun(double); static double *myFun(double); double myFun(double); I suspect you may have the two names in the import statement swapped. Stefan

On Tue, May 29, 2007 at 11:09:15PM -0400, jeff p wrote:
Hello,
On 5/29/07, Brandon S. Allbery KF8NH
wrote: On May 29, 2007, at 23:01 , jeff p wrote:
myPrompt> ghc --make -fffi f.hs -l mylib.lib
For historical reasons, you can't have a space between the -l and the library name. It's inserting an empty library name into the link command, which is producing the odd "cannot find" error.
Ok. Now I get another error:
myPrompt> ghc --make -fffi f.hs -lmylib.lib ghc --make -fffi f.hs -lmylib.lib Linking f.exe ... d:\ghc\ghc6.6\gcc-lib\ld.exe: cannot find -lmylib.lib collect2: ld returned 1 exit status
which is strange because the file mylib.lib is in the same directory as the haskell code.
Don't know about Windows, but on traditional Unix systems -l appends an extension and prepands /library/path/lib, so -lc links /lib/libc.so; if your library does not follow the naming conventions, you must omit -l and directly reference ./foobarlib.so as a file to link (GHC will link any object code files listed on the command line). Stefan
participants (3)
-
Brandon S. Allbery KF8NH
-
jeff p
-
Stefan O'Rear