Statically linking SQLite with DMD (Windows x86)

笑着哭i 提交于 2020-01-01 10:28:09

问题


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


回答1:


Try using implib with /system switch.




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/13443193/statically-linking-sqlite-with-dmd-windows-x86

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!