Sign in Join

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

Mailing lists / fpc-devel / 2003-02

Exporting variables in libraries for Linux / FreeBSD

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Maarten Bekers

Hi,

I've been experimenting a lot lately with creating a library, using FPC. However, a certain library i'm writing requires me to export an variable. Unfortunately, exporting of variables is not available in Linux or FreeBSD - only in Win32, according to the documentation. This does work for Win32, but wont compile on Linux nor FreeBSD.

Is there anyone that know if there is any sort of workaround, that would accomplish this anyway?
Thanks!

groeten, Maarten.

Reply by email

Anton Tichawa
to Maarten Bekers

Hi!

In Free Pascal Programmer's Manual, 7. 2., I didn't find anything about restrictions for exporting variables. Where did you read that? And what kind of library (static, shared, ..) is it?

Anton.

----------

"Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben."

Doris Langley Moore: Ada, Countess of Lovelace (London 1977).

----------

Anton Tichawa
Volkertstrasse 19 / 20
A-1020 Wien
mobil: +43 664 52 07 907
email:

----------

Reply by email

Maarten Bekers
to Anton Tichawa

hey Anton,

In Free Pascal Programmer's Manual, 7. 2., I didn't find anything about restrictions for exporting variables. Where did you read that? And what

kind

of library (static, shared, ..) is it?

It's very simple.

Try compiling this:

-cut-
library test;
var o: integer;
exports
  o;
end.
-cut-

it will compile on Win32, but just refuse to compile on Linux. When you search on the error the compiler generates, you'll find the docs that explain that exporting of variables is only supported on Win32.

Sincerely,
Maarten.

Reply by email

Peter Vreman
to Maarten Bekers
you wrote 24 lines
hey Anton, > In Free Pascal Programmer's Manual, 7. 2., I didn't find anything about > restrictions for exporting variables. Where did you read that? And what kind > of library (static, shared, ..) is it? It's very simple. Try compiling this: -cut- library test; var o: integer; exports o; end. -cut- it will compile on Win32, but just refuse to compile on Linux. When you search on the error the compiler generates, you'll find the docs that explain that exporting of variables is only supported on Win32.

Under linux it is not supported because linux works different with shared libraries. For procedures we could add an extra jmp with the new name. But for variables it's not possible as for the imported variables it is not know if they need an extra derefence (that is what WIn32 is using for dll variables) or that they need to be imported bij the dynamic linker.

Peter

Reply by email

Maarten Bekers
to Peter Vreman

hi Peter,

Show quoted text 9 lines
>it will compile on Win32, but just refuse to compile on Linux. When you >search on the error the compiler generates, you'll find the docs that >explain that exporting of variables is only supported on Win32. Under linux it is not supported because linux works different with shared libraries. For procedures we could add an extra jmp with the new name. But for variables it's not possible as for the imported variables it is not know if they need an extra derefence (that is what WIn32 is using for dll variables) or that they need to be imported bij the dynamic linker.

I see. Is there any chance of getting this feature implemented, or would it be better to try to write a library in C that in turn uses my library in FPC to provide the functionality that it should?

groeten, Maarten.

Reply by email

Marco van de Voort
to Maarten Bekers
Show quoted text 13 lines
> >it will compile on Win32, but just refuse to compile on Linux. When you > >search on the error the compiler generates, you'll find the docs that > >explain that exporting of variables is only supported on Win32. > > Under linux it is not supported because linux works different with shared > libraries. For procedures we could add an extra jmp with the new name. But > for variables it's not possible as for the imported variables it is not > know if they need an extra derefence (that is what WIn32 is using for dll > variables) or that they need to be imported bij the dynamic linker. I see. Is there any chance of getting this feature implemented, or would it be better to try to write a library in C that in turn uses my library in FPC to provide the functionality that it should?

I wouldn't do that. I'd make getters and setters (functions and procedures wrappers to read/write vars) to access them. These even can get handy later to get things threadsafe.

Reply by email

Maarten Bekers
to Marco van de Voort

hey Marco,

> I see. Is there any chance of getting this feature implemented, or would

it

> be better to try to write a library in C that in turn uses my library in

FPC

> to provide the functionality that it should? I wouldn't do that. I'd make getters and setters (functions and procedures wrappers to read/write vars) to access them. These even can get handy

later

to get things threadsafe.

Yeah, i use that technique in a lot of my code too, unfortunately, Apache requires you to export an variable, so that it can load the procedure/function addresses, in order to be able to create an Apache module, so i'm affraid i'll have to try to craete a wrapper library.

groeten, Maarten.

Reply by email