[fpc-pascal]problem linking with c

Dean Zobec dezobec at tin.it
Tue Dec 23 23:33:05 CET 2003


Hi, 
i tried to link a c function but had some problems:
a simple example:
in file cwrite.c 

#include <stdio.h>

void writestringinc(void);

void writestringinc(void) {
        puts("This string is written using c");
        fflush( stdout );
}

compiled with c using
g++ -c cwrite.c

now, this is a test program in fpc:

Program testc;
{$linklib c}

{$L cwrite.o}

Procedure writestringinc; cdecl; external;

begin
writeln ('Written with Pascal');
writestringinc();
end.

both cwrite.o and testc.pp reside in the same directory.
compiling with fpc gives me this:
[dean at delfino c++progs]$ fpc testc.pp
Free Pascal Compiler version 1.9.1 [2003/11/14] for i386
Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Linux for i386
Compiling testc.pp
Linking testc
testc.o(.text+0x4a): In function `main':
: undefined reference to `writestringinc'
testc.pp(11,1) Error: Error while linking
Closing script ppas.sh

What am I doing wrong?

Another question: is fpc compatible with C++? 

Thanks in advance,

Ciao, Dean







More information about the fpc-pascal mailing list