[OS X] When using the -static option with gcc, clang : error occurs.

Asked 2 years ago, Updated 2 years ago, 103 views

I wrote a c code to run a simple shell, gave the -static option to gcc, and compiled it. The following error occurs:

ld: library not found for -lcrt0.o clang: error: linker command failed with exit code 1 (use -v to see invocation)

How do we solve this?

clang gcc

2022-09-22 22:07

2 Answers

As explained above, you cannot write -static that requires you to write a static library unconditionally because the gcc libraries themselves are not all compiled statically. If a library is statically compiled, you can direct the static library, such as -library.a, or use the -Bstatic command to search for the static library.


2022-09-22 22:07

Apple says it does not support static linking on the gcc of Mac OS X.

Apple does not support statically linked binaries on Mac OS X. A statically linked binary assumes binary compatibility at the kernel system call interface, and we do not make any guarantees on that front. Rather, we strive to ensure binary compatibility in each dynamically linked system library and framework.

Note: https://developer.apple.com/library/mac/qa/qa1118/_index.html


2022-09-22 22:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.