Sign in Join

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

Mailing lists / fpc-pascal / 2011-07

Pascal and static executable

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

ik

Hello List,

I'm writing an article about modern (Object) Pascal, but there is one subject that I do not fully understand (for the article that is :)) and I wish to be prepared for it.

Let's say that I write the following code:

program say_hello;
begin
  writeln('Hello');
end.

This code is not linked to any shared library and therefor consider to be static linked. However if I write the following code:

program say_helloworld;
begin
  writeln('Hello World');
end.

They both have the same size and the same memory footprint. So what exactly is going on ? Why does Pascal compiler generate static linked executable while C/++ compiler will generate dynamic executable ?

What are the benefits in this approach and what are the bad things with it ?

Thanks,

Ido

Reply by email

Jonas Maebe
to ik
ik wrote 16 lines
Let's say that I write the following code: program say_hello; begin writeln('Hello'); end. program say_helloworld; begin writeln('Hello World'); end. They both have the same size and the same memory footprint. So what exactly is going on ?

Alignment/rounding of section sizes.

Why does Pascal compiler generate static linked executable while C/++ compiler will generate dynamic executable ? What are the benefits in this approach and what are the bad things with it ?

With static linking, you can copy the program to other systems and it will normally just work. With dynamic linking, the target systems needs a version of the same dynamic library (or a compatible version for the program to run. The advantage of dynamic linking is that shared libraries can be loaded in memory just once, and then the same copy of the library can be used by all programs that link to it (with copy-on-write for writable sections of the data, so that programs won't influence each other when writing).

FPC's rtl interface is not very stable, so using a shared library approach would probably cause lots of compatibility problems (or require the installation of many different version of the FPC rtl shared library, with most programs using a different version). The interface of libstdc++ changes less often.

Jonas

Reply by email

leledumbo
to ik: I'm writing an article about modern (Object) Pascal, but there is one subject that I do…
Why does Pascal compiler generate static linked executable while C/++

compiler will generate dynamic executable ?

It's really compiler dependent. There are Pascal compilers that generate dynamically linked executables by default and there are C/C++ compilers that generate static executables by default.

What are the benefits in this approach and what are the bad things with it ?

As stated by Jonas + from me: one bad thing about static linking, you can't have modular application at binary level, i.e. a couple of executables that share common codes residing in dynamically linked libraries. one good thing, static linking allows the linker to do dead code elimination (smartlinking in FPC term), so your executables contain only codes + datas that it really uses, thus reducing the size.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Pascal-and-static-executable-tp4598551p4600397.html Sent from the Free Pascal - General mailing list .

Reply by email