www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Shared object with Sqlite?

reply Benjiro <benjiro benjiro.com> writes:
A silly question that has me pounding my head for a while. I am 
trying to compile a shared object WITH sqlite3 included into the 
shared object.

dmd -c dll.d -fPIC -L-ldl 
-L/usr/lib/x86_64-linux-gnu/libsqlite3.a
dmd -oflibdll.so dll.o -shared -defaultlib=libphobos2.so 
-L-rpath=/root/dlangProjects
No ability to access the C object. It does not even seem to be included based upon the file size. This works ( using the already existing shared sqlite3 object ) but i am just linking the sqlite3 to the shared object.
dmd -c dll.d -fPIC
dmd -oflibdll.so dll.o -shared -defaultlib=libphobos2.so 
-L-rpath=/root/dlangProjects 
-L/usr/lib/x86_64-linux-gnu/libsqlite3.so
And for fun... this one just errors out big time ;)
dmd -c dll.d -fPIC
dmd -oflibdll.so dll.o -shared -defaultlib=libphobos2.so -L-ldl 
-L/usr/lib/x86_64-linux-gnu/libsqlite3.a
 /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libsqlite3.a(sqlite3.o): 
 relocation R_X86_64_PC32 against symbol `sqlite3_strnicmp' can 
 not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value collect2: error: ld 
returned 1 exit status
The goal is to have the sqlite3 embedded into the shared object so i can have my own orm in D build into the dll.d ( for easy distribution ). And then my main programs can dynamically load this shared object. Complicated. I am probably mixing things up but its a bit of experimentation. ;)
Dec 12 2016
parent reply Mike Parker <aldacron gmail.com> writes:
On Monday, 12 December 2016 at 13:12:35 UTC, Benjiro wrote:
 A silly question that has me pounding my head for a while. I am 
 trying to compile a shared object WITH sqlite3 included into 
 the shared object.

dmd -c dll.d -fPIC -L-ldl 
-L/usr/lib/x86_64-linux-gnu/libsqlite3.a
dmd -oflibdll.so dll.o -shared -defaultlib=libphobos2.so 
-L-rpath=/root/dlangProjects
No ability to access the C object. It does not even seem to be included based upon the file size.
Right, because there's no linking taking place when you compile dll.d. The -c option means compile only. The link step happens in the second command line, when you build the shared library. Any linker options you pass when compiling with -c are simply ignored.
 This works ( using the already existing shared sqlite3 object ) 
 but i am just linking the sqlite3 to the shared object.

dmd -c dll.d -fPIC
dmd -oflibdll.so dll.o -shared -defaultlib=libphobos2.so 
-L-rpath=/root/dlangProjects 
-L/usr/lib/x86_64-linux-gnu/libsqlite3.so
So replace libsqlite3.so with the static library here.
Dec 12 2016
parent reply Benjiro <benjiro benjiro.com> writes:
On Monday, 12 December 2016 at 14:11:49 UTC, Mike Parker wrote:
 So replace libsqlite3.so with the static library here.
See the 3th example in the original post...
 /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libsqlite3.a(sqlite3.o): 
 relocation R_X86_64_PC32 against symbol `sqlite3_strnicmp' can 
 not be used when making a shared object; recompile with -fPIC
 /usr/bin/ld: final link failed: Bad value
From my understanding, because the libdll has a shared tag, the libsqlite3.a needs to be linked as static and the rest needs to be dynamic. I found some examples using Gcc ( static & dynamic flags ) but those do not work for DMD.
Dec 12 2016
parent reply Mike Parker <aldacron gmail.com> writes:
On Monday, 12 December 2016 at 15:19:55 UTC, Benjiro wrot
 From my understanding, because the libdll has a shared tag, the 
 libsqlite3.a needs to be linked as static and the rest needs to 
 be dynamic. I found some examples using Gcc ( static & dynamic 
 flags ) but those do not work for DMD.
If you can't get DMD to pass the proper linker flags, you should still be able to call the linker manually. Or even pass the object files and libs along via gcc.
Dec 12 2016
parent Benjiro <benjiro benjiro.com> writes:
On Monday, 12 December 2016 at 15:39:47 UTC, Mike Parker wrote:
 On Monday, 12 December 2016 at 15:19:55 UTC, Benjiro wrot
 From my understanding, because the libdll has a shared tag, 
 the libsqlite3.a needs to be linked as static and the rest 
 needs to be dynamic. I found some examples using Gcc ( static 
 & dynamic flags ) but those do not work for DMD.
If you can't get DMD to pass the proper linker flags, you should still be able to call the linker manually. Or even pass the object files and libs along via gcc.
Thanks. Simply ended up linking to the shared library. Not what i had in mind but it works. It always takes time to figure things out ;)
Dec 14 2016