在Windows上创建rails项目时出现Sqlite错误

问题描述 投票:2回答:3

我是铁路的新手。我正在尝试创建一个rails项目

rails new depot

不幸的是,在rails试图进行sqlite的geminstall时,这是失败的

错误如下

Fetching sqlite3 1.4.0
Installing sqlite3 1.4.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/sqlite3-1.4.0/ext/sqlite3
C:/Ruby24-x64/bin/ruby.exe -r ./siteconf20190205-19788-3qr0ge.rb extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Install SQLite3 from http://www.sqlite.org/ first.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby24-x64/bin/$(RUBY_BASE_NAME)
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-config
        --without-sqlite3-config
        --with-pkg-config
        --without-pkg-config
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

C:/Ruby24-x64/lib/ruby/gems/2.4.0/extensions/x64-mingw32/2.4.0/sqlite3-1.4.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/sqlite3-1.4.0 for inspection.
Results logged to
C:/Ruby24-x64/lib/ruby/gems/2.4.0/extensions/x64-mingw32/2.4.0/sqlite3-1.4.0/gem_make.out

An error occurred while installing sqlite3 (1.4.0), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.4.0'` succeeds before bundling.

In Gemfile:
  sqlite3

C:\Users\rose\railsprojects>

我已经从SQLite下载页面安装(复制的二进制文件)到我的C:\ sqlite文件夹。我的操作系统是64位,所以我下载了“sqlite-dll-win64-x64-3260000.zip”和“sqlite-tools-win32-x86-3260000.zip”(从这里https://www.sqlite.org/download.html)我也有dll和头文件显示

02/12/2018  12:38 AM           504,837 shell.c
02/12/2018  12:39 AM           490,496 sqldiff.exe
02/12/2018  12:38 AM         7,770,073 sqlite3.c
02/12/2018  12:26 PM             5,933 sqlite3.def
02/12/2018  12:27 PM         1,878,528 sqlite3.dll
02/12/2018  12:40 AM           911,360 sqlite3.exe
02/12/2018  12:38 AM           556,318 sqlite3.h
02/12/2018  12:38 AM            33,713 sqlite3ext.h
02/12/2018  12:40 AM         2,003,968 sqlite3_analyzer.exe

因为这个错误我尝试用gem命令安装sqlite3因为我的头和DLL在目录C:\ sqlite中,我在msys2终端上使用了以下命令


ridk enable
C:\Users\rose>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:\sqlite
Fetching: sqlite3-1.4.0.gem (100%)
Installing required msys2 packages: mingw-w64-x86_64-sqlite3
Building native extensions with: '--with-sqlite3-dir=C:\sqlite'
This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.4.0/ext/sqlite3
C:/Ruby25-x64/bin/ruby.exe -r ./siteconf20190205-17968-rk6pw2.rb extconf.rb --with-sqlite3-dir=C:\sqlite
checking for sqlite3.h... yes
checking for pthread_create() in -lpthread... yes
checking for -ldl... no
checking for dlopen()... no
missing function dlopen
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby25-x64/bin/$(RUBY_BASE_NAME)
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-config
        --without-sqlite3-config
        --with-pkg-config
        --without-pkg-config
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib
        --with-pthreadlib
        --without-pthreadlib
        --with-dllib
        --without-dllib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/Ruby25-x64/lib/ruby/gems/2.5.0/extensions/x64-mingw32/2.5.0/sqlite3-1.4.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.4.0 for inspection.
Results logged to C:/Ruby25-x64/lib/ruby/gems/2.5.0/extensions/x64-mingw32/2.5.0/sqlite3-1.4.0/gem_make.out

C:\Users\rose>

有什么线索丢失了吗?

mkmf日志说

"pkg-config --exists sqlite3"
| pkg-config --libs sqlite3
=> "-LC:/Ruby25-x64/msys64/mingw64/lib -lsqlite3\n"
"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=x86-64 -mtune=generic -O2 -pipe conftest.c  -L. -LC:/Ruby25-x64/lib -L. -pipe -s     -lx64-msvcrt-ruby250  -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }
/* end */

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=x86-64 -mtune=generic -O2 -pipe conftest.c  -L. -LC:/Ruby25-x64/lib -L. -pipe -s     -lx64-msvcrt-ruby250 -LC:/Ruby25-x64/msys64/mingw64/lib -lsqlite3 -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }
/* end */

| pkg-config --cflags-only-I sqlite3
=> "-IC:/Ruby25-x64/msys64/mingw64/include\n"
| pkg-config --cflags-only-other sqlite3
=> "\n"
| pkg-config --libs-only-l sqlite3
=> "-lsqlite3\n"
package configuration for sqlite3
cflags: 
ldflags: -LC:/Ruby25-x64/msys64/mingw64/lib
libs: -lsqlite3

find_header: checking for sqlite3.h... -------------------- yes

"x86_64-w64-mingw32-gcc -E -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -IC:/Ruby25-x64/msys64/mingw64/include -IC:\sqlite/include -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=x86-64 -mtune=generic -O2 -pipe   conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: #include <sqlite3.h>
/* end */

--------------------

find_library: checking for pthread_create() in -lpthread... -------------------- yes

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -IC:/Ruby25-x64/msys64/mingw64/include -IC:\sqlite/include -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=x86-64 -mtune=generic -O2 -pipe  conftest.c  -L. -LC:/Ruby25-x64/lib -LC:\sqlite/lib -L. -pipe -s -LC:/Ruby25-x64/msys64/mingw64/lib     -lsqlite3 -lx64-msvcrt-ruby250 -lpthread  -lsqlite3 -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:16:57: error: 'pthread_create' undeclared (first use in this function); did you mean 'rb_thread_create'?
 int t(void) { void ((*volatile p)()); p = (void ((*)()))pthread_create; return !p; }
                                                         ^~~~~~~~~~~~~~
                                                         rb_thread_create
conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: int t(void) { void ((*volatile p)()); p = (void ((*)()))pthread_create; return !p; }
/* end */

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -IC:/Ruby25-x64/msys64/mingw64/include -IC:\sqlite/include -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=x86-64 -mtune=generic -O2 -pipe  conftest.c  -L. -LC:/Ruby25-x64/lib -LC:\sqlite/lib -L. -pipe -s -LC:/Ruby25-x64/msys64/mingw64/lib     -lsqlite3 -lx64-msvcrt-ruby250 -lpthread  -lsqlite3 -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: extern void pthread_create();
17: int t(void) { pthread_create(); return 0; }
/* end */

--------------------

have_library: checking for -ldl... -------------------- no

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -IC:/Ruby25-x64/msys64/mingw64/include -IC:\sqlite/include -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=x86-64 -mtune=generic -O2 -pipe  conftest.c  -L. -LC:/Ruby25-x64/lib -LC:\sqlite/lib -L. -pipe -s -LC:/Ruby25-x64/msys64/mingw64/lib    -lpthread  -lsqlite3 -lx64-msvcrt-ruby250 -ldl -lpthread  -lsqlite3 -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
C:/Ruby25-x64/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ldl
collect2.exe: error: ld returned 1 exit status
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: 
17: int t(void) { ; return 0; }
/* end */

--------------------

have_func: checking for dlopen()... -------------------- no

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -IC:/Ruby25-x64/msys64/mingw64/include -IC:\sqlite/include -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=x86-64 -mtune=generic -O2 -pipe  conftest.c  -L. -LC:/Ruby25-x64/lib -LC:\sqlite/lib -L. -pipe -s -LC:/Ruby25-x64/msys64/mingw64/lib    -lpthread  -lsqlite3 -lx64-msvcrt-ruby250 -lpthread  -lsqlite3 -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
conftest.c: In function 't':
conftest.c:16:57: error: 'dlopen' undeclared (first use in this function); did you mean '_lopen'?
 int t(void) { void ((*volatile p)()); p = (void ((*)()))dlopen; return !p; }
                                                         ^~~~~~
                                                         _lopen
conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: int t(void) { void ((*volatile p)()); p = (void ((*)()))dlopen; return !p; }
/* end */

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25-x64/include/ruby-2.5.0/x64-mingw32 -IC:/Ruby25-x64/include/ruby-2.5.0/ruby/backward -IC:/Ruby25-x64/include/ruby-2.5.0 -I. -IC:/Ruby25-x64/msys64/mingw64/include -IC:\sqlite/include -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=x86-64 -mtune=generic -O2 -pipe  conftest.c  -L. -LC:/Ruby25-x64/lib -LC:\sqlite/lib -L. -pipe -s -LC:/Ruby25-x64/msys64/mingw64/lib    -lpthread  -lsqlite3 -lx64-msvcrt-ruby250 -lpthread  -lsqlite3 -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "
C:\Users\Navarose\AppData\Local\Temp\ccNQH25m.o:conftest.c:(.text+0x5): undefined reference to `dlopen'
collect2.exe: error: ld returned 1 exit status
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <winsock2.h>
 4: #include <windows.h>
 5: 
 6: /*top*/
 7: extern int t(void);
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13: 
14:   return 0;
15: }
16: extern void dlopen();
17: int t(void) { dlopen(); return 0; }
/* end */

--------------------

作为最后的手段,我使用mingw64构建了SQlite。后来尝试安装gem。还有一个像shostopper这样的新错误

gem install sqlite3 --platform=ruby -- --with-sqlite3-include=C:\sqlite\ --with-sqlite3-lib=C:\sqlite\.libs\

C:/RailsInstaller/Ruby2.3.3/bin/ruby.exe -r ./siteconf20190205-18436-ve1008.rb extconf.rb --with-sqlite3-include=C:\sqlite\ --with-sqlite3-lib=C:\sqlite\.libs\
checking for sqlite3.h... yes
checking for pthread_create() in -lpthread... no
checking for main() in -ldl... no
checking for dlopen()... no
missing function dlopen
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/RailsInstaller/Ruby2.3.3/bin/$(RUBY_BASE_NAME)
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-config
        --without-sqlite3-config
        --with-pkg-config
        --without-pkg-config
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib=${sqlite3-dir}/lib
        --with-pthreadlib
        --without-pthreadlib
        --with-dllib
        --without-dllib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/sqlite3-1.4.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/sqlite3-1.4.0 for inspection.
Results logged to C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/sqlite3-1.4.0/gem_make.out

ruby-on-rails ruby sqlite ruby-on-rails-5
3个回答
3
投票

在这里找到了一个非常巧妙的解决方案

https://github.com/sparklemotion/sqlite3-ruby/issues/248

它似乎只缺少msys2中的库。

ridk exec pacman -S mingw-w64-x86_64-dlfcn

之后,编译就可以了。

gem install sqlite3 -v 1.4.0

注意: - 在git分支上添加依赖项似乎并不理想。


2
投票

指向sqlite3-ruby gem的分支并使用2018年最后更新的分支:

gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"

到你的Gemfile。到目前为止,它对我有用。祝好运! :)


0
投票

根据帖子中提到的描述,似乎sqlite未正确安装在您的计算机上,包括所需的所有标头。

运行以下提到的命令以正确安装它:

gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/path/to/sqlite3

其中C:/path/to/sqlite3是sqlite3的头文件(include)和libs(lib)所在的位置。

希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.