[fpc-pascal] linking and using dynamic libraries on amd64

Tony Whyman tony.whyman at mccallumwhyman.com
Fri Feb 13 10:07:37 CET 2015


A pity, because that would have been an easy fix. This type of error
comes from either mis-matched calling conventions or incompatible
argument lists.

From having done this sort of thing before all I can advise is to go
through each function argument one by one and make sure that each
argument type is exactly the same in terms of data representation. When
going between 32 and 64 bit you can often find that there are subtle
differences in how the different compilers treat types resulting in a
type that might be compatible in the 32 bit world, ceasing to be
compatible in the 64bit world.

Also: you are using a 'C' library and not a C++ library aren't you?


On 12/02/15 19:30, Marc Santhoff wrote:
> On Do, 2015-02-12 at 09:03 +0000, Tony Whyman wrote:
>> Marc,
>>
>> If your running on a *nix system then you probably want "cdecl" rather
>> than "stdcall"
> Err ... you're right and it is cdecl. I have mixed it up because it is
> an $if_n_def ...:
>
> ...;{$ifndef Win32}cdecl{$else}stdcall{$endif};external libname name 'xxx';
>
> If I find the time I'll go on and investigate the exact position the
> error occurs. Maybe it is possible to build it with debugging symbols,
> in code I have to find a way throug the macro djungle ... one reason to
> use Object Pascal.
>
> Thanks for waking me up. ;)
>
> Marc
>
>> On 12/02/15 04:54, Marc Santhoff wrote:
>>> On Do, 2015-02-12 at 00:42 +0100, Marc Santhoff wrote:
>>>> Hi,
>>>>
>>>> when I try to run a program that dynamically links an external .so
>>>> library it throws a SIGSEGV error at startup. That seems to happen while
>>>> loading the library before any code of mine is exeuted.
>>>>
>>>> The library is pulled into it by a header translation from C to Pascal.
>>>> The functions are declared "...; stdcall; external libname name xxx'.
>>>> This way it worked on i386.
>>>>
>>>> When the error occurs the ASM window pops up, which is not very helpful
>>>> for me.
>>>>
>>>> There may be a minor change in the lib source itself, but compiling the
>>>> header and linking works OK. I have no idea how to check besides getting
>>>> the older versions source and try again. Will try if nothing else is
>>>> fishy.
>>> I did test the old library and the error is the same.
>>>
>>> GDB tells me it happens when starting at BEGIN and running the init function
>>> of the library. That function does not have any arguments, I'm assuming
>>> "something else" then ...
>>>
>>>> My questions:
>>>>
>>>> Is there any difference in declaring external functions between 32 and
>>>> 64 bit mode?
>>>>
>>>> How can I debug what is happening? Will compiling the library having an
>>>> external debug file work when debugging from Lazarus?
>>>>
>>>> Any hints for diagnosing what's going wrong are very welcome.
>>>>
>>>>
>>>>
>>>> Some data points:
>>>> fpc 2.6.2 x86_64
>>>> library is compiled to 64 bit
>>>> FreeBSD 9.1-STABLE amd64
>>>>
>>>> Best regards,
>>>> Marc 
>>>>
>> _______________________________________________
>> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
>> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal





More information about the fpc-pascal mailing list