www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to compile d programm with external c function

reply meldolion <pi marsinvasion.de> writes:
I tried to use this official page to solve a problem :
http://www.digitalmars.com/d/2.0/interfaceToC.html

The problem is there is nothing said about compiling this source.

I created a main.d and a helloworld.c sourcefile. 

module main;
import std.string;

extern (C)
{
void printHelloWorld();
}

void main(){
printHelloWorld();
}





helloworld.c

#include <stdio.h>

void printHelloWorld(){
printf("hello world");
}


I created the object file for helloworld.c.

but when i call

bud_win_3.04.exe main.d helloworld.o 

i get following error message.

OPTLINK (R) for Win32 Release 8.00.1
Copyright (C) Digital Mars 1989-2004 All rights reserved.
main.obj(main) 
Error 42: Symbol Undefined _printHelloWorld

Does anyone knows the solution of this problem?

thx meldolion
Feb 25 2008
parent oliver <oliver.ruebenkoenigREM web.de> writes:
meldolion Wrote:

 
 
 I tried to use this official page to solve a problem :
 http://www.digitalmars.com/d/2.0/interfaceToC.html
 
 The problem is there is nothing said about compiling this source.
 
 I created a main.d and a helloworld.c sourcefile. 
 
 module main;
 import std.string;
 
 extern (C)
 {
 void printHelloWorld();
 }
 
 void main(){
 printHelloWorld();
 }
 
 
 
 
 
 helloworld.c
 
 #include <stdio.h>
 
 void printHelloWorld(){
 printf("hello world");
 }
 
 
 I created the object file for helloworld.c.
 
 but when i call
 
 bud_win_3.04.exe main.d helloworld.o 
 
 i get following error message.
 
 OPTLINK (R) for Win32 Release 8.00.1
 Copyright (C) Digital Mars 1989-2004 All rights reserved.
 main.obj(main) 
 Error 42: Symbol Undefined _printHelloWorld
 
 Does anyone knows the solution of this problem?
 
 thx meldolion
this worked for me: test.d: import std.string; extern (C) { void printHelloWorld(); } void main(){ printHelloWorld(); } helloworld.c: #include <stdio.h> void printHelloWorld(){ printf("hello world"); } gcc -c helloworld.c gdc test.d helloworld.o (also the version with the "module main") hth, oliver
Feb 26 2008