Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-08

Linking Pascal code to C/C++ static libraries under Windows.

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lowell C. Savage

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

505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)

Marco van de Voort
to Lowell C. Savage
Show quoted text 8 lines
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.

FPC is link compatible with GCC, not with VC. IOW, recompile your sources with GCC.

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.)

This should be possible though, as long as you refrain from memory allocation across processes (iow the program should have to free memory allocated by the dll, call a dll function to free)

Any suggestions?

Can't offer any real advice with the limited info, but my suggestion is to get the dll working. As soon as this works in general, it will work with FPC too.