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

Naive question about static linking #126

Open
RBornat opened this issue Sep 3, 2022 · 2 comments
Open

Naive question about static linking #126

RBornat opened this issue Sep 3, 2022 · 2 comments

Comments

@RBornat
Copy link

RBornat commented Sep 3, 2022

I have a project (github mdxtoc/qtpi) which uses zarith. Many thanks for zarith, by the way. I distribute my program to not very many users on macOS, Windows and Linux. But some of these not very many complain, because along with my program they have to load libgmp, and they don't see themselves as system administrators. Hoping to make their lives easier I thought I'd static link libgmp into my program.

But that's not easy. On macOS at least it's really quite difficult: you can't use the -static flag when loading, and the -lgmp flag isn't issued by me but as a side effect of loading the zarith package. So I can't see how to insert -l/libgmp.a, which was my first idea.

I came across this very useful website
https://ocamlpro.com/blog/2021_09_02_generating_static_and_portable_executables_with_ocaml
which tells me to find out all the flags used when loading, and copy them, changing the -lgmp one. That might well work, but I'd rather not if there's a simpler way, because of the maintenance problems it would introduce.

I thought of temporarily renaming the dynamic library so that -lgmp could only see the static version, but I'm scared to try that. I can't make a directory containing only the static library, because zarith also issues the -L flag which points to the libgmp directory.

So that's two bad ideas (three, if you count -static). Is there a better idea?

@xavierleroy
Copy link
Contributor

Static linking of libraries is becoming a challenge, not just for Zarith, not just for OCaml programs in general, but even for programs written entirely in C or C++... Right now I have no better suggestion to offer than those on the OCamlPro blog.

@RBornat
Copy link
Author

RBornat commented Sep 5, 2022 via email

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

2 participants