Recent

Author Topic: Compiler define which is set when building shared library or when LCL is used  (Read 1303 times)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 512
  • Professional amateur ;-P
Hey Mark,

The dynamic library is a separate project, so at the source level the only thing that's shared is an (in my case) .inc file which specifies to the library what it should export and to the program what it should assume is available.

That's what I mean when I mention "headers", or "apart from sigs and data structures". In C/C++ land it's *.h / *.hpp, in our land it's *.inc.

I want to focus on an abstraction. You know what an abstraction is, right? :P
The abstraction I'm talking about is the shift in your thought process of having a dynamic lib. Not the particulars.
In this abstraction/context, when you decide that you're gonna put code in a dynamic lib, that's it, shared code is never at the source code context, it's at the binary context, right? And please don't repeat the obvious particulars of how a program has to interface with the dynamic lib. That's part of the implementation, not the abstraction/context.

So again: Why would you want the {$IFDEF LIBRARY} if you're not sharing code?

Cheers,
Gus
Lazarus 2.1.0(trunk) FPC 3.3.1(trunk) Ubuntu 20.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.0(stable) Ubuntu 20.10 64b Dark Theme
http://github.com/gcarreno

MarkMLl

  • Hero Member
  • *****
  • Posts: 2559
So again: Why would you want the {$IFDEF LIBRARY} if you're not sharing code?

Testing it. It's far easier to single-step etc. into a routine if it's statically linked.

Having said that, I notice that some of my own code uses library (rather than unit) even if statically linked... I'm not entirely sure what's going on there but it was working when I last needed it.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 2985
  • Compiler Developer
But now another question arose: If you're committing to the paradigm of having code inside a dynamic library, why would you want to have shared units with anything else?
Wouldn't it just be necessary to load the dynamic library?

In case of a shared library you need to have a well defined API and you can't just blindely use features like RTTI or managed string types across binaries then.

This kind of transparency is only possible with dynamic packages, but they also have a healthy amount of compiler and RTL magic to work correctly (and thus can't be used from non-Object Pascal code).

LacaK

  • Hero Member
  • *****
  • Posts: 619
Just to answer some questions, which were already answered :)

I have some units, which are USED either by Lazarus program or shared library (DLL on Windows).
If I compile library with uses units, which use units Classes, Graphics etc. I get large DLL (800+KB) even if there (in library) are not used procedures from these units (probably because of initialization/finalization sections of these units).
So my intention is "detect" that library is compiled and in this case conditionaly omit some part of code (presented in units), which I know is not needed by my library.

And yes I must do "Clean and build" when I switch from "program" to "library" and back.

(and as I wrote {$IFDEF LCL} is for me working solution ... it is defined in "program" and not defined in "library")

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 512
  • Professional amateur ;-P
Hey PascalDragon,

In case of a shared library you need to have a well defined API and you can't just blindely use features like RTTI or managed string types across binaries then.

This kind of transparency is only possible with dynamic packages, but they also have a healthy amount of compiler and RTL magic to work correctly (and thus can't be used from non-Object Pascal code).

Now, that actually makes sense and, at least in my view, kinda answers my second question.
Thanks!

Cheers,
Gus
Lazarus 2.1.0(trunk) FPC 3.3.1(trunk) Ubuntu 20.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.0(stable) Ubuntu 20.10 64b Dark Theme
http://github.com/gcarreno

 

TinyPortal © 2005-2018