[fpc-pascal] Linking FPC units with Visual Studio 2013 projects

Sven Barth pascaldragon at googlemail.com
Fri Aug 21 11:47:46 CEST 2015

Am 21.08.2015 08:40 schrieb "Tobias Giesen" <tobiasgiesen at gmail.com>:
> Hello,
> I have to compile a few Pascal units with FPC and add them to a Visual
> C++ project. After adding system.o to the Visual C++ project, I get
> linker errors like this:
> system.o : error LNK2001: unresolved external symbol _$dll$kernel32$Sleep
> Apparently the Microsoft linker does not recognize the FPC way of
> mangling the DLL dependencies? Is there a way to compile the RTL in a
> way that Microsoft can link? Or anything else I can do?

Short answer: no

Long answer:

Where you found the system.o you should also see a libimpsystem.a or so
that you should link as well.
No guarantees though...

You also will need to manually call the initialization sections of each
unit you use (check the assembler listings of the units), because otherwise
for example the RTL won't be initialized which will result in unuseable
code (you won't even be able to use New()).

A better and much less fragile solution would be to ompile the units you
need into a DLL and provide a C based, flat interface. Or export functions
that create interface instances as these are compatible with IUnknown
(you'll need to write suitable headers then).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150821/8b68b9ad/attachment.html>

More information about the fpc-pascal mailing list