Sign in Join

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

Mailing lists / fpc-pascal / 2015-08

Linking FPC units with Visual Studio 2013 projects

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Unknown author

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?

Thanks.
Tobias Giesen

Reply by email

Tobias Giesen

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?

Thanks.
Tobias Giesen

Reply by email

Michael Schnell
to Unknown author: I have to compile a few Pascal units with FPC and add them to a Visual C++ project. After…
Hello, I have to compile a few Pascal units with FPC and add them to a Visual C++ project.

As the object structure (and supposedly the naming scheme for overloaded functions) is different in fpc and C++ you can't link them (neither statically nor dynamically).

You need to do a "flat" interface between the parts of the project using e.,g. STDCALL on either site.

-Michael

Reply by email

Tobias Giesen
to Michael Schnell

Hello,

yes, to interface between Pascal and C I use 'extern "C"'. I do not have any problems linking between my C code and the Pascal code.

The only problem is that the Pascal RTL uses DLL imports, which the Microsoft linker cannot resolve, for example:

unresolved external symbol _$dll$kernel32$Sleep

So again the question is how to enable the Microsoft linker to resolve the DLL dependencies.

Cheers,
Tobias

Show quoted text 13 lines
On 08/20/2015 12:27 PM, wrote: > Hello, > > I have to compile a few Pascal units with FPC and add them to a Visual > C++ project. As the object structure (and supposedly the naming scheme for overloaded functions) is different in fpc and C++ you can't link them (neither statically nor dynamically). You need to do a "flat" interface between the parts of the project using e.,g. STDCALL on either site. -Michael _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Tomas Hajny
to Tobias Giesen

On Fri, August 21, 2015 09:36, Tobias Giesen wrote:

Hello,

Show quoted text 10 lines
yes, to interface between Pascal and C I use 'extern "C"'. I do not have any problems linking between my C code and the Pascal code. The only problem is that the Pascal RTL uses DLL imports, which the Microsoft linker cannot resolve, for example: unresolved external symbol _$dll$kernel32$Sleep So again the question is how to enable the Microsoft linker to resolve the DLL dependencies.

The particular symbol should be defined in libimpsystem.a (and also in libimpwindows.a). However, I don't know whether adding this library to your Visual Studio project really solves the problem completely.

Tomas

Reply by email

Tobias Giesen
to Tomas Hajny
The particular symbol should be defined in libimpsystem.a

Fantastic! After adding some more libraries, the only remaining missing symbol is FPC_WIDEINITTABLES. I can probably just create a dummy for that in a Pascal unit, as the code does not need widestrings.

Cheers,
Tobias

Reply by email

Tomas Hajny
to Tobias Giesen
Tobias Giesen wrote 5 lines
> The particular symbol should be defined in libimpsystem.a Fantastic! After adding some more libraries, the only remaining missing symbol is FPC_WIDEINITTABLES. I can probably just create a dummy for that in a Pascal unit, as the code does not need widestrings.

FPC_WIDEINITTABLES should be defined in system.o.

Tomas

Reply by email

Sven Barth
to Tobias Giesen: I have to compile a few Pascal units with FPC and add them to a Visual C++ project. After…
"Tobias Giesen" wrote 12 lines
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).

Regards,
Sven

Reply by email

Sven Barth
to Tomas Hajny: FPC_WIDEINITTABLES should be defined in system.o. Tomas
"Tomas Hajny" wrote 9 lines
On Fri, August 21, 2015 10:22, Tobias Giesen wrote: >> The particular symbol should be defined in libimpsystem.a > > Fantastic! After adding some more libraries, the only remaining missing > symbol is FPC_WIDEINITTABLES. I can probably just create a dummy for > that in a Pascal unit, as the code does not need widestrings. FPC_WIDEINITTABLES should be defined in system.o.

No, it's created in the main program file.

Regards,
Sven

Reply by email

Tobias Giesen
to Sven Barth: Short answer: no Long answer: Where you found the system.o you should also see a…

Hello,

many thanks for all the insight! I will be able to complete it now. A separate DLL should be easy enough, too.

Cheers,
Tobias

Show quoted text 19 lines
Am 21.08.2015 08:40 schrieb "Tobias Giesen" : > > 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: ...

Reply by email