Troubleshooting Rust Linker Failures on macOS (linking with cc
failed: exit status: 1)
#204
-
When running ...
Compiling stylex_compiler_rs v0.6.1-rc.2 (/Users/derekwilliams/development/stylex-swc-plugin/crates/stylex-rs-compiler)
Compiling stylex_swc_plugin v0.6.1-rc.2 (/Users/derekwilliams/development/stylex-swc-plugin/crates/stylex-swc-plugin)
error: linking with `cc` failed: exit status: 1 I was able to fix this by adding a config file: [target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
] Following the suggestion here: https://stackoverflow.com/questions/28124221/error-linking-with-cc-failed-exit-code-1 If it makes sense to add that to the repo I'd be more than happy to do so. My Rust skills are minimal at this point so I didn't want to add an issue or make a PR without touching base. I also was not sure if this issue was already addressed in the project's github actions; the concern on my part being breaking the CI/CD workflow with adding a Note: I do have an Intel i7 machine running an older version of macOS (Monterey), so I can verify on that machine as well, if needed, and I can start up an Ubuntu VM if needed to verify on Linux |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hi @derekjwilliams, I had the same problem with a M1 machine. This problem also existed on previous versions of MacOS. The solution was one of the solutions suggested in the link above, add
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
] After that, this problem did not occur again. Perhaps it is worth adding a description of this problem and solution directly to the repository, for example, the Q&A section, or maybe the presence of this discussion is enough. I am ready to consider various options, including PR. |
Beta Was this translation helpful? Give feedback.
-
I like the idea of a Q&A section. There are likely to be other small 'gotchas' that only occur in some edge cases. In this case I naïvely ran I'd be glad to submit a PR for either, or both sections, if you'd like, at the end of the existing README.md? I agree that it does not make sense to add a Edit: I'll mark your answer as the solution so we don't have this as a BUG |
Beta Was this translation helpful? Give feedback.
-
Great idea. |
Beta Was this translation helpful? Give feedback.
Hi @derekjwilliams,
I had the same problem with a M1 machine. This problem also existed on previous versions of MacOS.
The solution was one of the solutions suggested in the link above, add
~/.cargo/config.toml
(https://doc.rust-lang.org/cargo/reference/config.html) file with the following content:After that, this problem did not occur again.
Perhaps …