-
Notifications
You must be signed in to change notification settings - Fork 459
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
Building a shared library #250
Comments
IIRC that flag was added to fix a bug but didn't actually end up fixing the bug or wasn't needed. In general though it's not the intention of this crate to produce shared libraries, just static libraries. |
I understand the current intent of this library. I think there could be value in expanding the scope to building shared libraries and executables. I suggest this because it could be useful for other needs, and you've already done some good legwork here (like the windows registry, for example) that others would need to duplicate. For my current needs (building a different language at runtime to c/c++, but others could have other situations), it seems like another alternative is for me to expect cmake to do this work instead. Could you consider expanding the scope even just a little for now, or would you recommend relying on cmake? Or I guess another alternative is compile to rust with c included there ... |
Unfortunately everything to do with shared libraries, loading, and copying them around I do not have time to review or maintain. I'd prefer to keep this library as simple as possible and targeted towards just "getting C into Rust" which 99% of the time doesn't require shared libraries. I think that this function should likely be built on top of |
Thanks for the feedback. I think I'll just start from this project as a base for getting what I need done. Thanks for your hard work! |
I'm going to close this because I would prefer to not support building a shared library with this crate. It'd be neat to see if a crate could be made which depends on |
For people who are still interested in building shared libraries, at least on macOS you just have to run e.g. let status = Command::new("/usr/bin/clang")
.args(["-dynamiclib", "-o", "libfoobar.dylib"])
.args(find_object_files_in("."))
.status()
.expect("link command failed, IO error");
if !status.success() {
panic!("link command failed, exit status {}", status);
} Pass |
It seems that
cc
offers the ability to build a shared object via the.shared(true)
method, but this object is then statically linked into the rust executable. Additionally, by default on macOS (which usesgcc
as an alias forclang
), the use of the.shared(true)
method doesn't actually do anything becauseclang
doesn't recognize-shared
as a valid flag when creating an object file. As far as I can tell, there does not seem to be a way to build a shared library and then link it with the rust executable with this crate.This seems to be confirmed here where
cc
is always usingar
, rather than the necessaryld
for shared libraries.Is there something I'm missing? If not I think this would be useful functionality.
The text was updated successfully, but these errors were encountered: