linking C++/D static library - what is "crt0.o"?
Daniel Murphy via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Sun Dec 28 20:55:21 PST 2014
"bitwise" wrote in message news:ckjqktzsmonjdcrhkhfg at forum.dlang.org...
> However, when I try to make a static library with the above files, it
> fails:
>
> > ldc2 -c -od/.../test_lib/obj/Debug main.d
> > clang++ -c -working-directory /.../test_lib/obj/Debug ../../native.cpp
> > clang++ -static -working-directory /.../test_lib
> > /.../test_lib/obj/Debug/main.o
> > /.../test_lib/obj/Debug/native.o -obin/Debug/libtest_lib.a
IIRC passing -static to gcc/clang means 'statically link with C runtime
libraries' not 'make a static library'. To create a static lib you need to
create object files with -c and use 'ar' to create the static library.
http://www.adp-gmbh.ch/cpp/gcc/create_lib.html
> > ld: library not found for -lcrt0.o
> > clang: error: linker command failed with exit code 1 (use -v to see
> > invocation)
>
> So what is "-lcrt0.o" and why is clang trying to automatically add it to
> my static library?
crt0.o contains the code to call C's main and a few other things. It is
automatically added when building an executable. The error possibly means
your system isn't set up for statically linking the cruntime.
More information about the digitalmars-d-ldc
mailing list