[fpc-pascal] Linking Pascal code to C/C++ static libraries under Windows.

Lowell C. Savage savage at lanl.gov
Tue Aug 16 19:48:10 CEST 2005


Background:

I have an old DOS console program that I'm trying to resurrect to run on 
Windows XP.  There isn't much about the structure of the program that I 
need (or want) to change.  But the interfaces to hardware will have to 
change.  It uses the old "PORT" array to communicate to the Serial port and 
a similar mechanism to communicate to an add-in board.

To work under XP, my understanding is that the old memory mapping stuff 
will no longer work.  So, we got a newer, equivalent A/D board which comes 
with a library of interface functions.  We have figured out how to replace 
the old interface code with newer calls to wrapper functions written in 
C.  (The original author did a VERY good job of structuring the code to 
isolate the interfaces!)

So the new structure is:

Application.pas, App1.pas, App2.pas, ..., AppBdIF.pas

Wrapper.c

Interface1.lib, Interface2.lib

Where "AppBdIF.pas" calls functions in "Wrapper.c" which in turn makes 
calls into "Interface1.lib" and "Interface2.lib".  The ideal would be to 
compile "Wrapper.c" and the two "InterfaceX.lib" files into a "Wrapper.lib" 
which contains everything.  Then, I link "Application.pas" to all the other 
".pas" files and to "Wrapper.lib" and I'm done.

The Problem:

The problem is that I can't seem to figure out how to get FPC to link to 
static libraries.  FPC's linker won't look for the "Wrapper.lib".  It 
either wants "Wrapper.dll" or "Wrapper.lib.dll".  I can compile wrapper.c 
to an object module (in Visual C 6.0) and FPC will link to that object 
file.  However, then the interface functions are undefined because I can't 
get the linker to see the "Interface.lib" files that contain them.  I've 
tried setting up my wrapper module as a DLL  but haven't had much luck 
there (I suspect the problem is that I'm not correctly creating the DLL in 
the first place since I can't get another test C program to link to it.)

Any suggestions?

Thanks in advance!


Lowell C. Savage
savage at lanl.gov
505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax) 






More information about the fpc-pascal mailing list