[fpc-pascal] Bindings for FLTK - testers needed

Dibo dibo20 at wp.pl
Wed Jun 24 11:45:15 CEST 2026


Version 1.5.23.4. Finally solved issues with static linking. It turned 
out that FPC while linking doesn't call everything as g++ call while 
linking. I had to write patch. Does anyone know why it is needed and why 
FPC doesn't call this by default? This is a code which I need to call in 
my bindings at first thing before anything else:

{$IFNDEF USE_FLTK_SHARED_LIBS}
{$IFDEF LINUX}
type
   TCtorProc = procedure(); cdecl;
   PCtorProc = ^TCtorProc;

var
   __init_array_start: Byte; external name '__init_array_start';
   __init_array_end: Byte; external name '__init_array_end';

procedure RunCppGlobalConstructors;
var
   p, pend: PCtorProc;
begin
   p := PCtorProc(@__init_array_start);
   pend := PCtorProc(@__init_array_end);
   while p < pend do
   begin
     if Assigned(p^) then
       p^();
     Inc(p);
   end;
end;
{$ENDIF}
{$ENDIF}
(* ====== *)


(* === Added / Modified by cfltk2pas === *)
initialization
   {$IFNDEF USE_FLTK_SHARED_LIBS}
   {$IFDEF LINUX}
   RunCppGlobalConstructors;
   {$ENDIF}
   {$ENDIF}
(* ====== *)

W dniu 22.06.2026 o 10:13, Dibo via fpc-pascal pisze:
> Hi,
>
> I spend few evenings creating bindings for CFLTK / FLTK. It is not 
> only call H2Pas but made own converter tool which convert macros as 
> flatten C methods and do a lot of stuff.
>
> Description: FLTK is very lightweight multiplatform GUI written in 
> C++. It doesn't use Qt / GTK / WinCtrls in backend but pure X11 / GDI. 
> It is similar to our fpGUI / MSEGUI for Free Pascal.
>
> Link to repo: https://github.com/dibok/PasFLTK
>
> I need some testers for windows and macos because I'm not able do it 
> by my self for now.
>
> I have also question for FPC guru here. Please see section "Other 
> static linking options". I have trouble there. Is there correct way to 
> link *.a libs (even written in C++) so there is no need to deploy 
> libcfltk.so / libfltk.so?
>
> In short. Structure looks like that:
>
> FPC headers -> cfltk lib (C wrapper) -> fltk lib (C++)
>
> I used GDB to debug these libs and noticed that the main problem which 
> cause this SIGSEGV is related to some kind different initialization 
> order of C++ classes. For example:
>
> Class A {
>
> public:
>
>   *char get_filesystem_label();
>
> }
>
>
> Class B {
>
> static const *char somelabel = A::get_filesystem_label();
>
> }
>
>
> Demo is running but has SIGSEGV in some particular places. In FPC 
> demo, seems like C++ class B is initializated first before A so const 
> somelabel contain empty value (NULL in fact). But the same demo 
> written in C works fine. Even ldd command shows that both my demo and 
> C demo has linked the same libs in the same order. I didn't debug 
> deeper but I think that method in class A is using some X11 routine, 
> so maybe FPC demo should call some init from linked X11 first? But C 
> demo doesn't call anything like that. I have also tried compiler 
> option --whole-archive with no result. I looked at other bindings for 
> FLTK and for example Rust is generating one single small executable 
> without needing libcfltk.so / libfltk.so so it is probably linking *.a 
> libs. It would be great if FPC could do that too.
>
>
> Regards
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


More information about the fpc-pascal mailing list