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

Can't build with --enable-executable-static missing crt0.o #9636

Open
alt-romes opened this issue Jan 20, 2024 · 4 comments
Open

Can't build with --enable-executable-static missing crt0.o #9636

alt-romes opened this issue Jan 20, 2024 · 4 comments

Comments

@alt-romes
Copy link
Collaborator

alt-romes commented Jan 20, 2024

Describe the bug
I was trying to build a fully static executable to test a few hypothesis, however, I just ran into this bug. Weirdly, I couldn't reproduce it in an actual project. After building with cabal build --enable-executable-static:

(tmp.jzlXN3vozO) ⚑ cabal build --enable-executable-static
Warning: this is a debug build of cabal-install with assertions enabled.
Warning: Parsing the index cache failed (Data.Binary.Get.runGet at position
16: Non-matching structured hashes: f46da61e7afa58a5e8fd1d2b6fb79899;
expected: d81bdd513f41b5d7ee4cd28455adadbe). Trying to regenerate the index
cache...
Resolving dependencies...
Build profile: -w ghc-9.8.1 -O1
In order, the following will be built (use -v for more details):
 - tmp-jzlXN3vozO-0.1.0.0 (exe:tmp-jzlXN3vozO) (first run)
Warning: this is a debug build of cabal-install with assertions enabled.
Configuring executable 'tmp-jzlXN3vozO' for tmp-jzlXN3vozO-0.1.0.0...
Warning: this is a debug build of cabal-install with assertions enabled.
Preprocessing executable 'tmp-jzlXN3vozO' for tmp-jzlXN3vozO-0.1.0.0...
Building executable 'tmp-jzlXN3vozO' for tmp-jzlXN3vozO-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, /private/var/folders/tv/35hlch6s3y15hfvndc71l6d40000gn/T/tmp.jzlXN3vozO/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tmp-jzlXN3vozO-0.1.0.0/x/tmp-jzlXN3vozO/build/tmp-jzlXN3vozO/tmp-jzlXN3vozO-tmp/Main.o )
[2 of 2] Linking /private/var/folders/tv/35hlch6s3y15hfvndc71l6d40000gn/T/tmp.jzlXN3vozO/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tmp-jzlXN3vozO-0.1.0.0/x/tmp-jzlXN3vozO/build/tmp-jzlXN3vozO/tmp-jzlXN3vozO
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ghc-9.8.1: `gcc' failed in phase `Linker'. (Exit code: 1)
Error: [Cabal-7125]
Failed to build exe:tmp-jzlXN3vozO from tmp-jzlXN3vozO-0.1.0.0.

To Reproduce
Steps to reproduce the behavior:

cd $(mktemp -d)
cabal init --exe --simple
cabal build --enable-executable-static

Expected behavior
The executable should compile and be fully static (no dynamic libraries).

System information

  • Operating system: macOS
  • cabal: HEAD and 3.10, ghc: 9.8

Additional context
Add any other context about the problem here.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 20, 2024

I assume "Parsing the index cache failed" is unrelated? I wonder if it fails the same on Linux and I wonder if there are already tests for something similar and if they work (if not, we should add the tests regardless of how this ticket resolves).

@Mikolaj
Copy link
Member

Mikolaj commented Jan 20, 2024

Related: #8909 and the issues mentioned there.

@geekosaur
Copy link
Collaborator

-lcrt0.o will never work: the C RTS is an object file, but -l will append .a for a static archive or .dylib (.so on Linux) for a shared object. Where is this coming from?

@alt-romes
Copy link
Collaborator Author

alt-romes commented Jan 20, 2024

-lcrt0.o will never work: the C RTS is an object file, but -l will append .a for a static archive or .dylib (.so on Linux) for a shared object. Where is this coming from?

Indeed. I haven't investigated this yet. But it doesn't come from any kind of user-custom option. As I've said in the reproducer section, it is just a clean executable project in a tmp directory.

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

No branches or pull requests

3 participants