Recent

Author Topic: Convert C to Lazarus  (Read 13236 times)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Convert C to Lazarus
« Reply #15 on: March 23, 2013, 09:25:39 am »
So, in resume,  we have 3 ways to load libraries.

1- Static loading of built-in Library. (example 1)
2- Static Linking of Dynamic Library. (example 2)
3- Dynamic Linking of Dynamic Library. (example 3)

Do you agree with those appellations ?

ASFAIK Yes,

Quote
Cfr benchmark, is there a plus to use Static Linking of Dynamic Library vs Dynamic Linking of Dynamic Library ?

Pros or cons of Static Linking of Dynamic Library are many, few known to my knowledge is as follows.

Pros

Quote
1. dll/so file  is loaded once, when the program starts. And is available throughout execution of the program,
    and only unloads when program is closed.

2. It is easily implemented in the program.

Cons
Quote
1. The application will NOT start if any DLLs are missing (cannot be found). When you run the program you will see an ugly message:
    "This application has failed to start because 'missing.dll' was not found. Re-installingn the application may fix this problem".

2. More memory used, as all DLLs are loaded even if you will not use some of the functions.


 Dynamic Linking of Dynamic Library.

Pros

Quote
1. You can run your program even when some of the libraries it uses are not present.
2. Smaller memory consumption - DLLs used when needed.
3. You can specify the full path to the DLL.
4. Use for functionality that is rarely needed by the application.
5. Could be used for modular applications. The application only exposes (loads) modules (dlls) "approved" for the user.
6. The ability to load and unload library dynamically, is the foundation of a plug-in system that allow a developer to add extra functionality to programs.
7. Backwards compatibility with older Windows versions, in which system dlls may not support the same functions or in the same way.
    Detecting the Windows   version first, then dynamic linking based on what your app is running on, allows you to support more versions of
    Windows and provide work arounds for older OSs, or at the very least gracefully disabling features you can't support.

Cons

Quote
Requires more code, not trivial for a beginner developer.


The list can be more for pros/cons.  :)

for me it is always Static Linking of Dynamic Library. Requires less code and is easily maintained.
« Last Edit: March 23, 2013, 09:52:27 am by deepaak99 »
Holiday season is online now. :-)

TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: Convert C to Lazarus
« Reply #16 on: March 23, 2013, 11:55:18 pm »
So, in resume,  we have 3 ways to load libraries.

1- Static loading of built-in Library. (example 1)
2- Static Linking of Dynamic Library. (example 2)
3- Dynamic Linking of Dynamic Library. (example 3)

Do you agree with those appellations ?

In essence that's right, but I'd say you mixed up the words "load" and "link" ;)

Namely,  that's "3 ways to LINK libraries", and under "1" it's static linking, not static loading. That description better fits "2", because static libraries are linked on compile time, while dynamic libraries are loaded and linked at runtime.
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Convert C to Lazarus
« Reply #17 on: March 24, 2013, 04:52:53 am »

In essence that's right, but I'd say you mixed up the words "load" and "link" ;)

Namely,  that's "3 ways to LINK libraries", and under "1" it's static linking, not static loading. That description better fits "2", because static libraries are linked on compile time, while dynamic libraries are loaded and linked at runtime.

Yes it is..  ;)

1- Static Linking of Library. (example 1)
Holiday season is online now. :-)

danny

  • New Member
  • *
  • Posts: 29
Re: Convert C to Lazarus
« Reply #18 on: March 25, 2013, 01:38:50 pm »
 In Example 1, in which folder I put the file "yourlib.a"?
This file can be a "yourlib.lib"?

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Convert C to Lazarus
« Reply #19 on: March 25, 2013, 02:31:14 pm »
In Example 1, in which folder I put the file "yourlib.a"?
This file can be a "yourlib.lib"?

Your Project root folder.. 
Holiday season is online now. :-)

danny

  • New Member
  • *
  • Posts: 29
Re: Convert C to Lazarus
« Reply #20 on: March 25, 2013, 07:33:54 pm »
Result error:

/usr/bin/ld: não foi possível encontrar -lyourlib.lib

yourlib.lib is in the project folder!

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Convert C to Lazarus
« Reply #21 on: March 25, 2013, 07:52:06 pm »
Result error:

/usr/bin/ld: não foi possível encontrar -lyourlib.lib

yourlib.lib is in the project folder!


AFAIK, Lazarus don't accept .lib file, please build your c project using gcc. It will result in  .a (gcc static library )file.
Holiday season is online now. :-)

AlexVinS

  • New Member
  • *
  • Posts: 10
Re: Convert C to Lazarus
« Reply #22 on: March 25, 2013, 10:25:10 pm »
C ABI is compiler agnostic - any C static library should be linkable.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12719
  • FPC developer.
Re: Convert C to Lazarus
« Reply #23 on: March 26, 2013, 11:20:08 am »
C ABI is compiler agnostic - any C static library should be linkable.

The format of static libraries isn't.   .LIB is mostly used for MSVC static libs, while FPC uses GCC static libs (.a).

AlexVinS

  • New Member
  • *
  • Posts: 10
Re: Convert C to Lazarus
« Reply #24 on: March 26, 2013, 03:12:58 pm »
C ABI is compiler agnostic - any C static library should be linkable.

The format of static libraries isn't.   .LIB is mostly used for MSVC static libs, while FPC uses GCC static libs (.a).

AFAIK they are identical - file extension is the only difference. (I`m not 100% sure about all static libs, but absolutely sure about importlibs)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Convert C to Lazarus
« Reply #25 on: March 26, 2013, 04:37:23 pm »

AFAIK they are identical - file extension is the only difference. (I`m not 100% sure about all static libs, but absolutely sure about importlibs)

AFAIK  .lib and .a are not identical at all.

BTW, Which importlibs are you pointing that are same for gcc and ms
Holiday season is online now. :-)

AlexVinS

  • New Member
  • *
  • Posts: 10
Re: Convert C to Lazarus
« Reply #26 on: March 26, 2013, 05:11:27 pm »
BTW, Which importlibs are you pointing that are same for gcc and ms
all.
I just use .lib`s (from VC) with gcc with no problems.

 

TinyPortal © 2005-2018