ld: library not found for -lcrt0.o on OSX 10.6 with gcc/clang -static flag

后端 未结 3 668
有刺的猬
有刺的猬 2020-11-29 03:03

When I try to build the following program:

#include 

int main(void)
{
  printf(\"hello world\\n\");
  return 0;
}

On OS X 1

3条回答
  •  眼角桃花
    2020-11-29 04:00

    Per Nate's answer, a completely static application is apparently not possible - see also man ld:

    -static Produces a mach-o file that does not use the dyld. Only used building the kernel.

    The problem in linking with static libraries is that, if both a static and a dynamic version of a library are found in the same directory, the dynamic version will be taken in preference. Three ways of avoiding this are:

    1. Do not attempt to find them via the -L and -l options; instead, specify the full paths, to the libraries you want to use, on the compiler or linker command line.

      $ g++ -Wall -Werror -o hi /usr/local/lib/libboost_unit_test_framework.a hi.cpp

    2. Create a separate directory, containing symbolic links to the static libraries, use the -L option to have this directory searched first, and use the -l option to specify the libraries you want to use.

      $ g++ -Wall -Werror -L ./staticBoostLib -l boost_unit_test_framework -o hi hi.cpp

    3. Instead of creating a link of the same name in a different directory, create a link of a different name in the same directory, and specify that name in a -l argument.

      $ g++ -Wall -Werror -l boost_unit_test_framework_static -o hi hi.cpp

提交回复
热议问题