PDA

View Full Version : cross compiling an x11 application with freepascal?



noeska
19-10-2009, 03:50 PM
Hello,

I am having a working crosscompiler win32->linux for fpc.
E.g. i can compile a console application with it on windows and run it on linux.

But i fail at compiling an X11 application with that. I need to collect a number of .a and .so files i guess. I downloaded the dev package belonging to my linux distro and discovered an libX11.a , but the acompanying libX11.so is 0 bytes large and as such the compile does not like it.

Who has attemted such a thing? Are there tutorials telling you what files you need to get and from where?

Thanks for your help in advance.

noeska
19-10-2009, 09:17 PM
I now turned of linking with -Cn
So i can addapt link.res and add the following to it:
-lxcb-xlib -lxcb -lXpm -lXext -lXdmcp
Now i get a lot less undefined error:


Linking minxapp
D:\lib\i386-linux\/libc.so: undefined reference to `_rtld_global@GLIBC_PRIVATE'
D:\lib\i386-linux\/libX11.so: undefined reference to `dlopen@GLIBC_2.1'
D:\lib\i386-linux\/libc.so: undefined reference to `__libc_enable_secure@GLIBC_P
RIVATE'
D:\lib\i386-linux\/libX11.so: undefined reference to `dlsym@GLIBC_2.0'
D:\lib\i386-linux\/libc.so: undefined reference to `__libc_stack_end@GLIBC_2.1'
D:\lib\i386-linux\/libc.so: undefined reference to `_rtld_global_ro@GLIBC_PRIVAT
E'
D:\lib\i386-linux\/libxcb.so: undefined reference to `XauGetBestAuthByAddr'
D:\lib\i386-linux\/libc.so: undefined reference to `___tls_get_addr@GLIBC_2.3'
D:\lib\i386-linux\/libxcb.so: undefined reference to `XauDisposeAuth'
D:\lib\i386-linux\/libc.so: undefined reference to `_dl_argv@GLIBC_PRIVATE'
D:\lib\i386-linux\/libc.so: undefined reference to `_dl_tls_get_addr_soft@GLIBC_
PRIVATE'
An error occured while linking minxapp

But what -l do belong to these errors ...

paul_nicholls
19-10-2009, 09:31 PM
I now turned of linking with -Cn
So i can addapt link.res and add the following to it:
-lxcb-xlib -lxcb -lXpm -lXext -lXdmcp
Now i get a lot less undefined error:


Linking minxapp
D:\lib\i386-linux\/libc.so: undefined reference to `_rtld_global@GLIBC_PRIVATE'
D:\lib\i386-linux\/libX11.so: undefined reference to `dlopen@GLIBC_2.1'
D:\lib\i386-linux\/libc.so: undefined reference to `__libc_enable_secure@GLIBC_P
RIVATE'
D:\lib\i386-linux\/libX11.so: undefined reference to `dlsym@GLIBC_2.0'
D:\lib\i386-linux\/libc.so: undefined reference to `__libc_stack_end@GLIBC_2.1'
D:\lib\i386-linux\/libc.so: undefined reference to `_rtld_global_ro@GLIBC_PRIVAT
E'
D:\lib\i386-linux\/libxcb.so: undefined reference to `XauGetBestAuthByAddr'
D:\lib\i386-linux\/libc.so: undefined reference to `___tls_get_addr@GLIBC_2.3'
D:\lib\i386-linux\/libxcb.so: undefined reference to `XauDisposeAuth'
D:\lib\i386-linux\/libc.so: undefined reference to `_dl_argv@GLIBC_PRIVATE'
D:\lib\i386-linux\/libc.so: undefined reference to `_dl_tls_get_addr_soft@GLIBC_
PRIVATE'
An error occured while linking minxapp

But what -l do belong to these errors ...


Sometimes undefined reference errors can be due to the order you define the linked libraries


-lxcb-xlib -lxcb -lXpm -lXext -lXdmcp

You could try changing the order of the above items and see if this helps...

cheers,
Paul

noeska
24-10-2009, 06:47 PM
I cannot get the x11 app to cross-compile on windows to linux :-(

I made another testcase:
fplink.pp


unit fplink;

interface

function fpLoadLibrary(AName: PChar): Pointer;
function fpFreeLibrary(ALibHandle: Pointer): Boolean;
function fpGetProcAddress(AProcName: PAnsiChar; ALibHandle: Pointer): Pointer;

implementation

const
RTLD_LAZY = $001;
RTLD_NOW = $002;
RTLD_BINDING_MASK = $003;

// Seems to work on Debian / Fedora
LibraryLib = {$IFDEF Linux} 'libdl.so.2'{$ELSE} 'c'{$ENDIF};

function dlopen(Name: PAnsiChar; Flags: LongInt): Pointer; cdecl; external LibraryLib name 'dlopen';
function dlclose(Lib: Pointer): LongInt; cdecl; external LibraryLib name 'dlclose';
function dlsym(Lib: Pointer; Name: PAnsiChar): Pointer; cdecl; external LibraryLib name 'dlsym';

function fpLoadLibrary(AName: PChar): Pointer;
begin
fpLoadLibrary := dlopen(AName, RTLD_LAZY);
end;


function fpFreeLibrary(ALibHandle: Pointer): Boolean;
begin
if ALibHandle = nil then
fpFreeLibrary := False
else
fpFreeLibrary := dlclose(ALibHandle) = 0;
end;


function fpGetProcAddress(AProcName: PAnsiChar; ALibHandle: Pointer): Pointer;
begin
fpGetProcAddress := dlsym(ALibHandle, AProcName);
if fpGetProcAddress <> nil then
exit;
end;

end.

Dont mind the fcgitest all it does is using the functions in fplink.pp
But compiling gives:

D:\Projecten\i386-linux\fastcgi\test>ppcross386 -TLINUX -gl -FlD:\i386-linux\lib
-XrD:\i386-linux\lib -FL/usr/lib/ld-linux.so.2 -XLAc=c,dl,gmodule fcgitest.pp
Free Pascal Compiler version 2.5.1 [2009/10/24] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for i386
Compiling fcgitest.pp
Linking fcgitest
fplink.o: In function `FPLINK_FPLOADLIBRARY$PCHAR$$POINTER':
fplink.pp:(.text+0xf): warning: Using 'dlopen' in statically linked applications
requires at runtime the shared libraries from the glibc version used for linkin
g
D:\lib\\libdl.a(dlopen.o): In function `dlopen':
: undefined reference to `__dlopen'
D:\lib\\libdl.a(dlclose.o): In function `dlclose':
: undefined reference to `__dlclose'
D:\lib\\libdl.a(dlsym.o): In function `dlsym':
: undefined reference to `__dlsym'
fcgitest.pp(84,1) Error: Error while linking
fcgitest.pp(84,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Maybe i should give up .

noeska
26-10-2009, 06:53 PM
Ok got it working for compiling to the bb (not x11 but sqlite3).

With codesourcery a lib and /usr/lib are suplied (from what i got the bin utils). Copying them (lib and usr/lib) in the root of the drive where fpc is makes it autodetect them.
But in /usr/lib are some .o files that do not agree with fpc so they must be removed.
Next you get the _fini and _init error again. But that can be solved by copying prt0.o over cprt0.o . And next compiling works.

With using dynlibs it is now possible to use sqlite3 dynamicaly e.g. only calling the libsqlite3.so.0 library at runtime so no more copying over lots of libs.

With that working i can now focus on getting an hello world opengles example working ...

PS CrossCompiling and using dynlibs still does not work for compiling to i386-linux on windows xp. Even my fastcgi application that worked before refuses to compile.
What is the 'standard' crosscompile tool for compiling with gcc on windows for linux? Maybe that comes with some distro independend base .so and .a files.