www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - linking with c

reply Mike <sgtmuffles myrealbox.com> writes:
So I'm trying to link a C file to be used in a D program:

hw.c:

#include <stdio.h>

void hw()
{
	printf("Hello, world!");
}


hw_main.d:

module hw_main;

extern (C) void hw();

int main()
{
	hw();
	return 0;
}

I compile the C file with dmc: dmc -c hw.c

and the D file with dmd: dmd -c hw_main.d

I try to link them with the digital mars linker: link hw.obj hw_main.obj

bu it complains about phobos.lib. So I try: link hw.obj hw_main.obj
(path)\phobos.lib

and I get a bunch of "symbol undefined" errors. Any advice?
Jan 10 2009
parent Jason House <jason.james.house gmail.com> writes:
Mike wrote:

 So I'm trying to link a C file to be used in a D program: 
 I compile the C file with dmc: dmc -c hw.c
 and the D file with dmd: dmd -c hw_main.d
I usually keep it simple and do: dmd main.d hw.obj
Jan 10 2009