Statically linking SQLite with DMD (Windows x86)

2020-07-13 10:40发布

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).

3条回答
Juvenile、少年°
2楼-- · 2020-07-13 11:20

Try using implib with /system switch.

查看更多
Viruses.
3楼-- · 2020-07-13 11:27

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

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-07-13 11:33

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

查看更多
登录 后发表回答