libsqlite3.so vs libsqlite3.a lazarus / 66-Unix ---------------------------------------------------------------------- Pascal · 2018-10-24 06:49 My app uses SQLite3Conn. When cross compiling to powerpc64-aix it tries to link libsqlite3.a although only libsqlite3.so is availabel. How can i enable dynamic linking here? ---------------------------------------------------------------------- Pascal · 2018-10-24 07:06 I added -XD to "Custom Options" but linker still complains: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Hint: (11030) Start of reading config file C:\freepascal\fpc\trunk\bin\i386-win32\fpc.cfgHint: (11031) End of reading config file C:\freepascal\fpc\trunk\bin\i386-win32\fpc.cfgFree Pascal Compiler version 3.3.1 [2018/10/24] for powerpc64Copyright (c) 1993-2018 by Florian Klaempfl and others(1002) Target OS: AIX for PowerPC64(3104) Compiling susMake.lpr(9009) Assembling susmake(9015) Linking C:\freepascal\projects\susMake\susmakeC:\freepascal\fpc\trunk\ bin\i386-win32\powerpc64-aix-ld.exe: cannot find -lsqlite3C:\freepascal\projects\susMake\susMake.lpr(30,44) Error: (9013) Error while linkingC:\freepascal\projects\susMake\susMake.lpr(30,44) Fatal: (10026) There were 1 errors compiling module, stoppingFatal: (1018) Compilation aborted ---------------------------------------------------------------------- Pascal · 2018-10-24 08:10 I also tried to add option "-dy", "-Bdynamic" to linker. No success. ---------------------------------------------------------------------- marcov · 2018-10-24 08:44 Did you double check that the files are for the correct architecture (IOW power64 ?) ---------------------------------------------------------------------- Pascal · 2018-10-24 08:49 Quote from: marcov on October 24, 2018, 10:44:21 amDid you double check that the files are for the correct architecture (IOW power64 ?) Don't know. libsqlite3.so could by 32bit. How can i check this? ---------------------------------------------------------------------- Pascal · 2018-10-24 09:14 Tried powerpc instead of powerpc64: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Hint: (11030) Start of reading config file C:\freepascal\fpc\trunk\bin\i386-win32\fpc.cfgHint: (11031) End of reading config file C:\freepascal\fpc\trunk\bin\i386-win32\fpc.cfgFree Pascal Compiler version 3.3.1 [2018/10/24] for powerpcCopyright (c) 1993-2018 by Florian Klaempfl and others(1002) Target OS: AIX for PowerPC(3104) Compiling susMake.lpr(9009) Assembling susmake(9015) Linking C:\freepascal\projects\susMake\susMakeC:\freepascal\fpc\trunk\ bin\i386-win32\powerpc-aix-ld.exe: cannot find -lsqlite3C:\freepascal\projects\susMake\susMake.lpr(30,44) Error: (9013) Error while linkingC:\freepascal\projects\susMake\susMake.lpr(30,44) Fatal: (10026) There were 1 errors compiling module, stoppingFatal: (1018) Compilation aborted So nothing changed here. If i provide a libsqlite3.a in C:\freepascal\aixroot\lib it links in both, 32bit and 64bit. So the linker does not seem to get informed that it shoul link dynamic! ---------------------------------------------------------------------- marcov · 2018-10-24 09:23 Pass -s and check the generated ppas.sh/.bat and link.res to see what parameters the linker gets. If you back up some files, you can do various linking attempts by running ppas.bat without rebuilding everything every time ---------------------------------------------------------------------- Thaddy · 2018-10-24 10:15 Sqlite is one of the few large opensource projects for which you can say: if in doubt, compile it yourself. Sqlite3 is very easy to compile yourself for your platform. ---------------------------------------------------------------------- Pascal · 2018-10-24 10:45 Quote from: marcov on October 24, 2018, 11:23:03 amPass -s and check the generated ppas.sh/.bat and link.res to see what parameters the linker gets. If you back up some files, you can do various linking attempts by running ppas.bat without rebuilding everything every time Thanks for the hints! I could see that -Xc does nothing here. I used -k-dy and linker gets called with -dy but it is not willing to link libsqlite3.so neither in 32bit nor 64bit. If i use --verbose i can see that linker only tries to find "libsqlite3.a". ---------------------------------------------------------------------- marcov · 2018-10-24 10:58 It is possible that cross linkers can't shared link, or refuses to do so if some global resource (like ld.so.conf) is not found. It is also possible that certain default paths are set. Maybe the linker makes a difference between shared and static linking directories. Anyway, it is clearly not a FPC problem, but a linker one. Searching AIX maillists looking for crosscompiling or simply "windows aix crosscompile" seems the best option. ---------------------------------------------------------------------- DonAlfredo · 2018-10-24 13:20 Please try this. I have uploaded new binutils. https://github.com/newpascal/fpcupdeluxe/releases/download/wincrossbin s_v1.0/powerpc-aix.zip Just copy them over your existing ones. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1;{$L C:\fpclazbydeluxe\trunk\cross\lib\powerpc64-aix\libsqlite3.so}//{$L libsqlite3.so} uses ctypes; var  sqlite3_libversion: function(): pansichar; cdecl;  s:pansichar;  SQLiteLibraryHandle: TLibHandle; procedure LoadAddresses(LibHandle: TLibHandle);begin  pointer(sqlite3_libversion) := GetProcedureAddress(LibHandle,'sqlite3_libversion');end; begin  SQLiteLibraryHandle := LoadLibrary('libsqlite3.so');  LoadAddresses(SQLiteLibraryHandle);  writeln('hello !');  s:=sqlite3_libversion();  writeln(s);end. The above does cross-compile. But if it works on AIX you have to test yourself ! ---------------------------------------------------------------------- Pascal · 2018-10-24 13:56 Quote from: DonAlfredo on October 24, 2018, 03:20:24 pmPlease try this. I have uploaded new binutils. https://github.com/newpascal/fpcupdeluxe/releases/download/wincrossbin s_v1.0/powerpc-aix.zip Just copy them over your existing ones. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1;{$L C:\fpclazbydeluxe\trunk\cross\lib\powerpc64-aix\libsqlite3.so}//{$L libsqlite3.so} uses ctypes; var  sqlite3_libversion: function(): pansichar; cdecl;  s:pansichar;  SQLiteLibraryHandle: TLibHandle; procedure LoadAddresses(LibHandle: TLibHandle);begin  pointer(sqlite3_libversion) := GetProcedureAddress(LibHandle,'sqlite3_libversion');end; begin  SQLiteLibraryHandle := LoadLibrary('libsqlite3.so');  LoadAddresses(SQLiteLibraryHandle);  writeln('hello !');  s:=sqlite3_libversion();  writeln(s);end. The above does cross-compile. But if it works on AIX you have to test yourself ! For me too! But the executable is unusable. See output: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i exec(): 0509-036 Das Programm unixtest kann wegen der folgenden Fehler nicht geladen werden:        0509-150   Das abhängige Modul C:\freepascal\aixroot/lib/libsqlite3.so konnte nicht geladen werden.      0509-022 Das Modul C:\freepascal\aixroot/lib/libsqlite3.so kann nicht geladen werden.        0509-026 Systemfehler: Eine Datei oder ein Verzeichnis des Pfadnamens ist nicht vorhanden. ---------------------------------------------------------------------- DonAlfredo · 2018-10-24 13:59 Use this one: {$L libsqlite3.so} (without the path) ---------------------------------------------------------------------- Pascal · 2018-10-24 16:04 Quote from: DonAlfredo on October 24, 2018, 03:59:37 pmUse this one: {$L libsqlite3.so} (without the path) I did! Same result. The linker adds "C:\freepascal\aixroot\lib\". I also tried /usr/lib/libsqlite3.so but that doesn't link! ---------------------------------------------------------------------- marcov · 2018-10-24 16:17 I believe that is what -Xr is for. ---------------------------------------------------------------------- Pascal · 2018-10-24 18:26 Quote from: marcov on October 24, 2018, 06:17:36 pmI believe that is what -Xr is for. Makes sense. I'll try that tomorrow. ---------------------------------------------------------------------- Pascal · 2018-10-25 10:42 -Xr does not help here. The linker always adds the complete path where it found the lib to the executable. Instead it should just leave the library name (without path). @DonAlfredo: Can you check the linker sources if there is a way to suppress this behaviour? ---------------------------------------------------------------------- DonAlfredo · 2018-10-25 10:51 Would you mind adding this into your fpc.cfg ? (changing the paths towards your setup naturally) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #IFDEF FPC_CROSSCOMPILING#IFDEF AIX#IFDEF CPUPOWERPC64# Inserted by fpcup 25-10-2018 09:30:42-FDC:\fpclazbydeluxe\trunk\cross\bin\powerpc- aix\-XPpowerpc-aix--Xd-FlC:\fpclazbydeluxe\trunk\cross\lib\powerpc64- aix\-XRC:\fpclazbydeluxe\trunk\cross\lib\powerpc64-aix- Xr/usr/lib#ENDIF#ENDIF#ENDIF  Ps: Hacking through the linker sources is not my favorite way of spending precious programming time. The hacks until now were not that hard, but preventing a basic functionality of the linker will not be easy. And besides, it should not be necessary: cross-compiling should work on AIX as it works on other Linux and Unix systems. Meaning: we have to dig deeper ... ;-) ---------------------------------------------------------------------- Pascal · 2018-10-25 11:34 Again: Many thanks for your efforts! I changed my fpc.cfg: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #IFDEF FPC_CROSSCOMPILING#IFDEF AIX#IFDEF CPUPOWERPC64# Inserted by fpcup 25-10-2018 09:30:42-FDC:\freepascal\fpc\binutils\i386-win32\-XPpowerpc-aix--Xd-Fl C:\freepascal\cross\aix\-XRC:\freepascal\cross\aix\- Xr/usr/lib#ENDIF#ENDIF#ENDIF And removed all custom options from project/mode. Result of run: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i exec(): 0509-036 Das Programm tools/unixtest kann wegen der folgenden Fehler nicht geladen werden:        0509-150   Das abhängige Modul C:\freepascal\cross\aix\/lib/libsqlite3.so konnte nicht geladen werden.        0509-022 Das Modul C:\freepascal\cross\aix\/lib/libsqlite3.so kann nicht geladen werden.        0509-026 Systemfehler: Eine Datei oder ein Verzeichnis des Pfadnamens ist nicht vorhanden. ---------------------------------------------------------------------- Pascal · 2018-10-25 11:39 With option "-s" i can see the linker call: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i C:\freepascal\fpc\trunk\bin\i386-win32\powerpc64-aix-ld.exe -bpT:0x10000000 -bpD:0x20000000 -btextro   -L. -o C:\freepascal\projects\unixtest\unixtest C:\freepascal\projects\unixtest\link.res -b64 --sysroot=C:\freepascal\cross\aix\ "-Xr/usr/lib" ssems to have no effect here. I tried "-k-rpath-link /usr/lib" and "-k-rpath /usr/lib". Both have no effet on the binary. ---------------------------------------------------------------------- DonAlfredo · 2018-10-25 11:45 Did you do a Clean and Build ? But I guess you did ... ;-) Now I am (nearly) out of ideas ! Few remain. It would be nice if I could get access to an (or yours) AIX server through SSH. Makes testing easier. Second, I am preparing a new release of fpcupdeluxe. It will build a cross-compiler for AIX. With settings I know about. I would like you to try to use that to install FPC and Lazarus, and the AIX cross- compiler. But please be patient. The release will take another couple of hours. Will inform you ! Ps: To add linker options, do: -k-rpath-link -k/usr/lib ---------------------------------------------------------------------- Pascal · 2018-10-25 12:02 Quote from: DonAlfredo on October 25, 2018, 01:45:11 pmDid you do a Clean and Build ? But I guess you did ... ;-) Now I am (nearly) out of ideas ! Few remain. It would be nice if I could get access to an (or yours) AIX server through SSH. Makes testing easier. Second, I am preparing a new release of fpcupdeluxe. It will build a cross-compiler for AIX. With settings I know about. I would like you to try to use that to install FPC and Lazarus, and the AIX cross- compiler. But please be patient. The release will take another couple of hours. Will inform you ! Ps: To add linker options, do: -k-rpath-link -k/usr/lib We have to somehow leave out -XR. The problem we have then is that "crt0_64.o" is not found as it is added to the link.res as absolute path ("\lib\crt0_64.o") so it will not use the seach pathes. Were does this absolute path come from? With symlink from /lib to /freepascal/cross/aix/lib i got it linking but the resolved path is still added to the binary. ---------------------------------------------------------------------- Pascal · 2018-10-25 13:09 I removed the absolute path to crt0_64.o from compiler/systems/t_aix.pas. The object gets found now by the linker but the binary still includes the complete path to libsqlite3.so. Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i exec(): 0509-036 Das Programm tools/unixtest kann wegen der folgenden Fehler nicht geladen werden:        0509-150   Das abhängige Modul C:\freepascal\cross\aix\lib\/libsqlite3.so konnte nicht geladen werden.        0509-022 Das Modul C:\freepascal\cross\aix\lib\/libsqlite3.so kann nicht geladen werden.        0509-026 Systemfehler: Eine Datei oder ein Verzeichnis des Pfadnamens ist nicht vorhanden. ---------------------------------------------------------------------- DonAlfredo · 2018-10-25 14:15 New try, with all standard options. Please add this into the linker options. -rpath /usr/lib (see included picture) The -Xr option is ignored by FPC for AIX ... do not ask why. If I look at the generated binary, the /usr/lib library searchpatch is added ! ---------------------------------------------------------------------- Pascal · 2018-10-25 14:20 Quote from: DonAlfredo on October 25, 2018, 04:15:52 pmNew try, with all standard options. Please add this into the linker options. -rpath /usr/lib (see included picture) The -Xr option is ignored by FPC for AIX ... do not ask why. If I look at the generated binary, the /usr/lib library searchpatch is added ! I did that already and i also could see "/usr/lib" in the binary but right after this string there is the found path of libsqlite3.so in the binary ("C:\freepascal\cross\aix\lib"). I found no way to get it out of the binary! This drives me nuts ---------------------------------------------------------------------- DonAlfredo · 2018-10-25 14:25 I see something different. There is a zero between the path and the library. Meaning two different strings. Its not an absolute path. See picture. ---------------------------------------------------------------------- Pascal · 2018-10-25 14:28 Quote from: DonAlfredo on October 25, 2018, 04:25:51 pmI see something different. There is a zero between the path and the library. Meaning two different strings. Its not an absolute path. See picture. Yes, right but system puts the final string together from path-string and pathdelimiter and library-string ---------------------------------------------------------------------- Pascal · 2018-10-25 16:19 The linker should omit the pathes in the binary if -rpath is specified! Is there an option for that or for omitting the pathes to the shared libs in general? ---------------------------------------------------------------------- Pascal · 2018-10-26 06:40 While trying to link the static libsqlite3.a the linker refused to link a 64 bit version and only accepts the 32 bit version. If this 64 bit binary finds the 32 bit libsqlite3.a on the system it loads and starts. Strange! Why does the linker not accept the 64 bit static libs? ---------------------------------------------------------------------- DonAlfredo · 2018-10-26 07:07 The 64bit version is only a link towards the 32bit version. The libs are suitable for boths architectures. ---------------------------------------------------------------------- Pascal · 2018-10-26 07:38 Yes, i just realized the same! Sorry