Statically linking SQLite with DMD (Windows x86)
Asked Answered
P

3

5

I've tried to statically link with sqlite3 without success. I'm using the 'etc.c.sqlite3' header, and the sqlite3 amalgamation. To create the .lib file I've tried both VC++ and MinGW-gcc, both of these compile the source file successfully - but they both generate COFF object format (optlink, which DMD uses, works with OMF). After reading tons of posts on 'digitalmars.D', I've tried several different solutions.

objconv:

  • tried to convert lib file created with GCC, resulted in undefined symbols such as __divdi3 and __muldi3, wasn't able to solve this.

  • Also tried this to convert the sqlite3.o file to *.obj, and then use digitalmars 'lib.exe' - unsuccessful as well

  • Attempting objconv on a VC++ generated lib fails because: "SQLite.lib is an import library"

implib:

  • If I download the precompiled DLL from sqlite.org and use implib, it generates a lib file, but the name mangling does not seem to match, because even though I link with the static library, I still receive the same sqlite errors (e.g undefined symbol _sqlite3_open, _sqlite3_errmsg, _sqlite3_close...

coffimplib:

  • If I use coffimplib on the VC++ created library file, the program generates a nearly empty file (~2KB) which only contains garbage (i.e no symbols at all and mostly just 'null' values).

  • If I do the same with the GCC created library, coffimplib complains about "not an import library" and no converted library file is generated.

If I use DMC to compile the sqlite3 amalgamation, the compilation fails complaining about tons of errors. So here I am, stuck in nowhere, does anyone have any ideas or tips what might solve this?

NOTE: I do not want to use a DLL, but statically link with sqlite (for executable size concerns).

Postern answered 18/11, 2012 at 18:30 Comment(4)
What errors do you get with the C compiler?Scorcher
Tons and tons. It would require way too much to fix them all, with all types of errors (e.g illegal cast, unknown identifer)Postern
I downloaded and tried DMC; it appears the errors are caused by bugs in the Windows header files shipped with DMC.Scorcher
Is there anything that could be fixed or is it too extensive? My errors did not seem to be related with windows headers though...Postern
A
3

Try using implib with /system switch.

Avitzur answered 18/11, 2012 at 18:39 Comment(1)
That actually did the trick! Although this created an import library, not a static library, so the executable still depends on the whole sqlite dll when it only uses ~5 of its functionsPostern
N
1

On Windows you're better off with dlls. Saves you a lot of headaches.

Work on x64 support is underway which will leverage COFF + VC's linker I think. This will hopefully change the awkward situation.

Edit: If you really need static libs you may try out Unilink, which is able to link OMF and COFF files together: ftp://ftp.styx.cabel.net/pub/UniLink

Newbold answered 19/11, 2012 at 10:41 Comment(3)
Yes, that's what I'm using at the moment, but not all libraries support shared ones (e.g dyncall) and the application size jumps when producing small executables (relative to the dependencies)Postern
Unilink sure is an interesting choice! I'll check it up (shallow documentation though). Do you have any idea when x64 support for COFF will be available?Postern
Phobos compiles but doesn't work yet. github.com/D-Programming-Language/dmd/commits/masterNewbold
I
0

Why you simply do not compile and link the SQLite C code with your D application? I guess that will save your from library-related headaches.

Of course a good alternative is to compile the SQLite static library with DMC, and use it with your D project by simply doing: dmd -of myproggy myproggy.d somefile.d libsqlite.lib

Iphlgenia answered 19/11, 2012 at 10:6 Comment(1)
Dmc fails to compile (see my comments) the SQLite amalgamation. And if I want to link, the objects need to be in OMF format, and that's the root of my problem!Postern

© 2022 - 2024 — McMap. All rights reserved.