Closed jmmk closed 7 years ago
Try linking final binary with -noautolink
.
Or you mean to make ocaml-mysql link in libmysqlclient statically? Then you are better off adding -Wl,-Bstatic to final link command line (but be careful to not statically link in glibc). Either way I think there is nothing specific to ocaml-mysql. Let me know if it is not the case.
You're right that this is not specific to ocaml-mysql. More an issue of statically linking C dependencies, specifically on a Mac. Thanks for pointing me in the direction of linker flags.
After some experimentation, it seems like this does not work well on Mac (it looks for .dylib
files before .a
files, so I have to rename the .dylibs
to be able to statically link). I think it might work if I could exclude some flags like -llibmysqlclient
and -L/usr/local/opt/mysql/lib
when I include the path to /usr/local/opt/mysql/lib/libmysqlclient.a
, but ocamlbuild is adding these flags and I don't know of an easy way to modify them.
The solution I'm using is to instead include the .dylib
and call install_name_tool -change /usr/local/opt/mysql/lib/libmysqlclient.20.dylib @executable_path/libmysqlclient.dylib <my_compiled_executable>
I think it might work if I could exclude some flags like -llibmysqlclient and -L/usr/local/opt/mysql/lib when I include the path to /usr/local/opt/mysql/lib/libmysqlclient.a, but ocamlbuild is adding these flags and I don't know of an easy way to modify them.
This is what -noautolink
is for.
But the idea of -Bstatic is exactly to avoid the need to specify .a directly, but influence the preference of linker instead (to resolve -llib to lib.a not lib.dylib). I don't know if this applies to Mac though
@ygrek I read in several places that -Bstatic
is a no-op on Mac because of the way the build toolchain is configured.
I could probably use something like -noautolink
, but I don't want to have to specify all the includes for every package, I just want to exclude mysql.
Got it, Mac OS strikes again.
Is it possible that I can compile my application with libmysqlclient included in the build artifact?