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

Unable to find 'musl-g++' on 'x86_64-unknown-linux-musl' target #22

Open
RaulTrombin opened this issue Sep 5, 2024 · 6 comments
Open

Comments

@RaulTrombin
Copy link

Hello guys, I'm having some issues building the musl version for linux amd64 target.

warning: [email protected]: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is musl-g++ installed?
details

On my computer it works fine with:
cross build --release --target="x86_64-unknown-linux-musl"

Any ideas?

@autarch
Copy link
Member

autarch commented Sep 5, 2024

Are you using the latest version of this action? I just updated it to install the musl-tools package when this is needed.

@RaulTrombin
Copy link
Author

Hi @autarch , thks for fast reply,

in fact it's installing the musl-tools,
line where it happens
image

I'm using the relase: "v0.0.14 - Install musl-tools if needed"
Other musl targets ( armv7, aarch64 ) worked fine.

@autarch
Copy link
Member

autarch commented Sep 21, 2024

I spent some time trying to find a solution for this, but I'm a bit stuck. I've tried the following:

Make a musl-g++ symlink to musl-gcc

This doesn't work because the musl-dev package doesn't include C++ headers, only C. So the build gets slightly further but then fails because it can't load the headers it needs.

Install a toolchain from https://musl.cc

This includes the C++ headers, but it's missing libraries that are needed, so it ends up with an error like this:

/opt/x86_64-linux-musl-native/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so: error loading plugin: Dynamic loading not supported

I think the best fix would be for the Ubuntu musl-dev package to include C++ headers. There's a bug report requesting this for the Debian package, but it's from 2021 and there hasn't been any response to it.

@RaulTrombin
Copy link
Author

RaulTrombin commented Sep 23, 2024

I spent some time trying to find a solution for this, but I'm a bit stuck. I've tried the following:

Make a musl-g++ symlink to musl-gcc

This doesn't work because the musl-dev package doesn't include C++ headers, only C. So the build gets slightly further but then fails because it can't load the headers it needs.

Install a toolchain from https://musl.cc

This includes the C++ headers, but it's missing libraries that are needed, so it ends up with an error like this:

/opt/x86_64-linux-musl-native/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so: error loading plugin: Dynamic loading not supported

I think the best fix would be for the Ubuntu musl-dev package to include C++ headers. There's a bug report requesting this for the Debian package, but it's from 2021 and there hasn't been any response to it.

Hmmm, maybe we could try something like they did on cross-rs's dockers images?
Seems they have a workaround for the c++ missing headers here:
https://github.com/cross-rs/cross/blob/d8631fe4f4e8bb4c4b24417a35544857fb42ee22/docker/musl-symlink.sh#L54

@autarch
Copy link
Member

autarch commented Oct 5, 2024

I gave it a shot using something based on the cross script, but then I encountered even more issues where the compiler couldn't find C++ header, for example for #include <algorithm>. I gave up at this point but I pushed a branch with my work in progress named musl-g++ if you're interested in working on this.

@autarch
Copy link
Member

autarch commented Oct 13, 2024

I dug into this more and found this project - https://github.com/musl-cross/musl-cross

If I make a musl-g++ symlink to the x86_64-multilib-linux-musl-g++ binary it provides, then compilation succeeds. However, it has a dynamic link to libstc++.so and it segfaults at runtime because it seems like the default libstdc++.so is incompatible with the binary that gets compiled.

I tried to figure out how to get it to statically link the libstdc++.a provided by musl-cross instead, but I really don't understand C or C++ compilation all that well, and having to filter this all through directives emitted by the build.rs left me pretty confused.

So while I think making this all work is possible, I'm a bit lost at how to do so for now.

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

No branches or pull requests

2 participants