Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static linking ? #41

Closed
dbuenzli opened this issue Jul 28, 2013 · 1 comment
Closed

Static linking ? #41

dbuenzli opened this issue Jul 28, 2013 · 1 comment

Comments

@dbuenzli
Copy link
Contributor

This library is really scary (because it feels like magic).

One question though. It doesn't work if you statically link the C library you bind to or I am missing something ?

(osx)

Static:

/Users/dbuenzli/.opam/4.00.1/bin/ocamlfind ocamlopt -linkpkg -g -cclib /usr/local/lib/libSDL2.a -package ctypes -package ctypes.foreign src/sdl.cmx src/omin.cmx -o src/omin.native
> otool -L omin.native 
omin.native:
    /usr/local/opt/libffi/lib/libffi.6.dylib (compatibility version 7.0.0, current version 7.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
> ./omin.native 
Fatal error: exception Dl.DL_error("dlsym(RTLD_DEFAULT, SDL_Init): symbol not found")
Raised at file "src/dl.ml", line 42, characters 26-44
Called from file "src/foreign.ml", line 18, characters 25-53
Called from file "src/sdl.ml", line 15, characters 11-63

Dynamic:

/Users/dbuenzli/.opam/4.00.1/bin/ocamlfind ocamlopt -linkpkg -g -cclib -L/usr/local/lib -cclib -lSDL2 -package ctypes -package ctypes.foreign src/sdl.cmx src/omin.cmx -o src/omin.native
> otool -L omin.native 
omin.native:
    /usr/local/opt/libffi/lib/libffi.6.dylib (compatibility version 7.0.0, current version 7.1.0)
    /usr/local/lib/libSDL2-2.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
> ./omin.native 

(works)

@dbuenzli
Copy link
Contributor Author

dbuenzli commented Aug 7, 2013

Okay Jeremy you were right. It was about passing the right flag to the linker so that it gets the symbols in. In that case it was -force_load /usr/local/lib/libSDL2.a.

The only thing is that you then need to figure out which libraries that archive uses and dynlink against those things aswell (it doesn't seem to be recorded in the .a but I'm a little bit rusty on these things). A way to figure that out on osx is to use otool -L on the .dyld library.

So in the end here's the invocation that succeeded, the interesting bits are in the -cclib argument:

/Users/dbuenzli/.opam/4.00.1/bin/ocamlfind ocamlopt -linkpkg -g -thread -thread  \
-cclib "-liconv -framework Carbon -framework ForceFeedback -framework AudioUnit \
          -framework IOKit -framework  CoreAudio -framework Cocoa \
          -force_load /usr/local/lib/libSDL2.a" \
-package ctypes -package ctypes.foreign \ 
src/tsdl_consts.cmx src/tsdl.cmx test/test.cmx -o test/test.native

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant