linking C++/D static library - what is "crt0.o"?

bitwise via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Sun Dec 28 14:08:15 PST 2014


Hi, just wondering if someone can help me out.
I'm trying to mix C++ and D code using ldc2 and clang++.

I'm using ldc 0.14.0, and the version of clang which came with 
Xcode(Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 
3.5svn))

I have two files:

<main.d>
module main;

import std.stdio;
import std.conv;

extern(C) int add(int a, int b);

void main() {
	int ret = add(1, 2);
	writeln("1 + 2 = " ~ to!string(ret));
}
</main.d>

<native.cpp>
extern "C" int add(int a, int b) {
	return a + b;
}
</native.cpp>


When I compile the above two files as executable, everything 
compiles and runs fine:

> ldc2 -c -od/.../test_exec/obj/Debug main.d
> clang++ -c -working-directory /.../test_exec/obj/Debug 
> ../../native.cpp
> clang++  -working-directory /.../test_exec 
> /.../test_exec/obj/Debug/main.o 
> /.../test_exec/obj/Debug/native.o /.../libdruntime-ldc.a 
> /.../libphobos2-ldc.a -obin/Debug/test_exec

the resulting executable outputs: "1 + 2 = 3"


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

> 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?



More information about the digitalmars-d-ldc mailing list