SQLite的编译为Windows(64位) [英] Compiling SQLite for Windows (64-bit)

查看:173
本文介绍了SQLite的编译为Windows(64位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有MinGW的,我希望编译 SQLite的合并源到64位的DLL。我是相当新的这种汇编和我的努力,到目前为止已导致失败。 (我第一次开始使用autoconf的融合和使用的配置及放大器;使工具在Linux上,但显然是行不通的Windows二进制文件。)

I have MinGW and I wish to compile the SQLite amalgamation source into a 64-bit dll. I'm fairly new to this sort of compilation and my efforts so far have resulted in failure. (I first started using the autoconf amalgamation and used the configure & make tool on Linux. But apparently that will never work for Windows binaries.)

不管怎样,我已经告诉我需要以下preprocessor定义:

Anyway, I've been told I need the following preprocessor defines:

下面是编译器pre-处理器定义我使用一个64位的发行版本:

Here are the compiler pre-processor defines I use for a 64-bit release build:

      
  • 在WIN64 NDEBUG
  •   
  • _WINDOWS
  •   
  • _USRDLL
  •   
  • NO_TCL
  •   
  • _CRT_SECURE_NO_DE preCATE
  •   
  • THREADSAFE = 1
  •   
  • TEMP_STORE = 1
  •   
  • SQLITE_MAX_EXPR_DEPTH = 0
  •   
  • WIN64 NDEBUG
  • _WINDOWS
  • _USRDLL
  • NO_TCL
  • _CRT_SECURE_NO_DEPRECATE
  • THREADSAFE=1
  • TEMP_STORE=1
  • SQLITE_MAX_EXPR_DEPTH=0

下面是编译器pre-处理器定义我使用一个32位的发行版本:

Here are the compiler pre-processor defines I use for a 32-bit release build:

      
  • 在WIN32
  •   
  • NDEBUG
  •   
  • _WINDOWS
  •   
  • _USRDLL
  •   
  • NO_TCL
  •   
  • _CRT_SECURE_NO_DE preCATE
  •   
  • THREADSAFE = 1
  •   
  • TEMP_STORE = 1
  •   
  • SQLITE_MAX_EXPR_DEPTH = 0
  •   
  • WIN32
  • NDEBUG
  • _WINDOWS
  • _USRDLL
  • NO_TCL
  • _CRT_SECURE_NO_DEPRECATE
  • THREADSAFE=1
  • TEMP_STORE=1
  • SQLITE_MAX_EXPR_DEPTH=0

我不知道在哪里可以在把这些我终于拿了一个受过教育的猜测,作出了新的文件(整洁)呼吁sqlite3w64.h并粘贴以下内容:

I had no idea where to put these in. I eventually took an educated guess, made a new file (for neatness) called sqlite3w64.h and pasted in the following:

#define WIN64 NDEBUG
#define _WINDOWS
#define _USRDLL
#define NO_TCL
#define _CRT_SECURE_NO_DEPRECATE
#define THREADSAFE 1
#define TEMP_STORE 1
#define SQLITE_MAX_EXPR_DEPTH 0

然后我用下面的命令编译来源:

I then compiled the source with the following command:

gcc sqlitew64.h sqlite3.h sqlite3ext.h shell.c sqlite3.c -o sqlite_x64.dll

什么导致了一个733KB的DLL文件。不错!它是否真的有效么?做到了坚果 - 我有一个BadImageFormatException。我也然后试图用同样的方法做一个x86汇编。再一次,我得到了一个733KB的DLL文件(这是奇怪的?)再次,我得到了一个BadImageFormatException。

What resulted was a 733KB DLL file. Nice! Did it actually work? Did it nuts - I got a BadImageFormatException. I also then tried doing an x86 compilation using the same method. Once again, I got a 733KB DLL file (that's odd?) and once again, I got a BadImageFormatException.

帮助。

用于以下命令:

gcc -shared -DWIN64 -DNDEBUG -D_WINDOWS -D_USRDLL -DNO_TCL -D_CRT_SECURE_NO_DEPRECATE -DTHREADSAFE=1 -DTEMP_STORE=1 -DSQLITE_MAX_EXPR_DEPTH=0 -I. shell.c sqlite3.c -o sqlite_x64.dll -Wl,--out-implib,sqlite3.a

导致了740KB的DLL文件仍然给出了一个BadImageFormatException。

Resulted in a 740KB DLL file which still gives a BadImageFormatException.

原来我的MinGW版本仅为32位。获得一个64位版本,然后让我做SQLite,让64位。添加-m64设置编译成64位模式的标志。

Turns out my MinGW build was 32-bit only. Getting a 64-bit version then allowed me to make SQLite for 64-bit. Adding the flag -m64 sets the compiler into 64-bit mode.

64位:

gcc -shared -DWIN64 -DNDEBUG -D_WINDOWS -D_USRDLL -DNO_TCL -D_CRT_SECURE_NO_DEPRECATE -DTHREADSAFE=1 -DTEMP_STORE=1 -DSQLITE_MAX_EXPR_DEPTH=0 -m64 -I. shell.c sqlite3.c -o sqlite3_x64.dll -Wl,--out-implib,sqlite3_x64.a

32位:

gcc -shared -DWIN32 -D_WINDOWS -D_USRDLL -DNO_TCL -D_CRT_SECURE_NO_DEPRECATE -DTHREADSAFE=1 -DTEMP_STORE=1 -DSQLITE_MAX_EXPR_DEPTH=0 -m32 -I. shell.c sqlite3.c -o sqlite3_x86.dll -Wl,--out-implib,sqlite3_x86.a

MinGW的-64 precompiled:<一href="http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/mingw-w64-bin_i686-mingw_20111220.zip/download?use_mirror=ignum">http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/mingw-w64-bin_i686-mingw_20111220.zip/download?use_mirror=ignum

安装说明:<一href="http://$c$c.google.com/p/tonatiuh/wiki/InstallingMinGWForWindows64">http://$c$c.google.com/p/tonatiuh/wiki/InstallingMinGWForWindows64

推荐答案

正在编译到一个EXE。称这是一个DLL不会神奇的的是一个DLL。

You are compiling to an EXE. Calling it a DLL won't magically make it a DLL.

您需要通过特殊的连接器选项海湾合作委员会,使之产生的DLL。 需要在mingw网站引用:(排序的,我换成G ++与海湾合作委员会)

You need to pass special linker options to gcc to make it create DLLs. Quoted from Mingw site: (Sort of, I replaced g++ with gcc)

gcc -c -DBUILDING_EXAMPLE_DLL example_dll.cpp
gcc -shared -o example_dll.dll example_dll.o -Wl,--out-implib,libexample_dll.a

该网页还解释说,你希望你的DLL导出函数,必须以声明__ declspec(dllexport)的。 (再往下,有关于如何将所有全局函数导出到DLL,就像通常发生在Unix的一个例子。)

The page also explains that functions you want your DLL to export, must be declared with __declspec(dllexport). (Further down, there is an example on how to export all global functions to the DLL, like usually happens in Unix.)

-Wl 参数海合会是海湾合作委员会通知传递的进一步论证 - 出IMPLIB,libexample_dll.a 以链接器

The -Wl argument to gcc is what tells gcc to pass on the further arguments --out-implib,libexample_dll.a to the linker.

我也会让 100%的确保创建的DLL实际上是一个64位的DLL,而不是一个32位的DLL。你有什么办法检查?在Linux可以运行文件命令。

I would also make 100% sure that the built DLL is actually a 64 bit DLL and not a 32 bit DLL. Do you have any way to check that? On Linux you can run the "file" command.

您也可以尝试添加 -m64 选项,gcc的命令行,应该的动力的GCC瞄准AMD64的目标。

You can also try adding the -m64 option to the gcc commandline, that should force gcc to target the amd64 target.

如果的不工作,你可能有错误的编译器完全。请确保您有 MinGW的工具链的x86_64的/ AMD64版本。安装很简单,只要寻找合适的ZIP,拆包它,并设置路径

If that doesn't work, you may have the wrong compiler altogether. Make sure you have the x86_64/amd64 version of the Mingw toolchain. Installation is as simple as finding the right ZIP, unpacking it, and setting the path.

如果所有的失败,或者如果你只是想验证对一个所谓正确编译安装程序,尝试的 precompiled 64位二进制文​​件在这里从这里

If all of that fails, or if you just want to verify against a supposedly correctly compiled setup, try precompiled 64-bit binaries here or from here.

这篇关于SQLite的编译为Windows(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆