Skip to content

Instantly share code, notes, and snippets.

@robryk
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robryk/2de6e4abf66d9a01b7f2 to your computer and use it in GitHub Desktop.
Save robryk/2de6e4abf66d9a01b7f2 to your computer and use it in GitHub Desktop.
program a;
{$L ac.o}
{$LinkLib c}
{$LinkLib gcc_s}
procedure install_foo;cdecl;external;
begin
install_foo;
end.
#include <stdlib.h>
#include <stdio.h>
void __attribute__ ((destructor)) stuff3() {
printf("baz\n");
}
void __attribute__ ((constructor)) stuff2() {
printf("bar\n");
}
void stuff() {
printf("foo\n");
}
void install_foo() {
atexit(&stuff);
}
program a;
{$L bc.o}
{$LinkLib c}
{$LinkLib stdc++}
{$LinkLib gcc_s}
uses initc;
begin
end.
#include <cstdio>
bool do_foo() {
printf("foo\n");
return true;
}
static bool foo = do_foo();
gcc -c ac.c
fpc a.pas
Free Pascal Compiler version 2.6.4 [2014/03/12] for x86_64
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling a.pas
Linking a
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
11 lines compiled, 0.1 sec
./a
foo
baz
g++ -c bc.cpp
fpc b.pas
Free Pascal Compiler version 2.6.4 [2014/03/12] for x86_64
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling b.pas
Linking b
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
11 lines compiled, 0.1 sec
./b
#!/bin/bash
set -e
set -v
gcc -c ac.c
fpc a.pas
./a
g++ -c bc.cpp
fpc b.pas
./b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment