client.c:439:3: error: use of undeclared identifier 'my_bool'

client.c:439:3: error: use of undeclared identifier 'my_bool',第1张

解决方式:

把mysql的gem版本换成0.5.2

再bundle

bundle完之後再改回原本的版本就不影响团队开发。

原则就是可以顺利跑完bundle就好,暂时更改版号骗过bundle

Gemfile

gem "mysql2", "~>0.5.2"

发生问题:

$ sudo gem install mysql2 -v 0.3.21

Building native extensions. This could take a while...

ERROR:  Error installing mysql2:

ERROR: Failed to build gem native extension.

    current directory: /Users/huyy01/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.3.21/ext/mysql2

/Users/huyy01/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20180724-29825-pksvq0.rb extconf.rb

checking for ruby/thread.h... yes

checking for rb_thread_call_without_gvl() in ruby/thread.h... yes

checking for rb_thread_blocking_region()... no

checking for rb_wait_for_single_fd()... yes

checking for rb_hash_dup()... yes

checking for rb_intern3()... yes

-----

Using mysql_config at /usr/local/bin/mysql_config

-----

checking for mysql.h... yes

checking for errmsg.h... yes

checking for mysqld_error.h... yes

-----

Setting rpath to /usr/local/Cellar/mysql/8.0.11/lib

-----

creating Makefile

current directory: /Users/huyy01/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.3.21/ext/mysql2

make "DESTDIR=" clean

current directory: /Users/huyy01/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.3.21/ext/mysql2

make "DESTDIR="

compiling client.c

client.c:439:3: error: use of undeclared identifier 'my_bool'

  my_bool res = mysql_read_query_result(client)

  ^

client.c:441:19: error: use of undeclared identifier 'res'

  return (void *)(res == 0 ? Qtrue : Qfalse)

                  ^

client.c:762:3: error: use of undeclared identifier 'my_bool'

  my_bool boolval

  ^

client.c:793:7: error: use of undeclared identifier 'boolval'

      boolval = (value == Qfalse ? 0 : 1)

      ^

client.c:794:17: error: use of undeclared identifier 'boolval'

      retval = &boolval

                ^

client.c:797:10: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'did you mean 'MYSQL_DEFAULT_AUTH'?

    case MYSQL_SECURE_AUTH:

         ^~~~~~~~~~~~~~~~~

         MYSQL_DEFAULT_AUTH

/usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here

  MYSQL_DEFAULT_AUTH,

  ^

client.c:798:7: error: use of undeclared identifier 'boolval'

      boolval = (value == Qfalse ? 0 : 1)

      ^

client.c:799:17: error: use of undeclared identifier 'boolval'

      retval = &boolval

                ^

client.c:830:38: error: use of undeclared identifier 'boolval'

        wrapper->reconnect_enabled = boolval

                                     ^

client.c:1185:38: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'did you mean 'MYSQL_DEFAULT_AUTH'?

  return _mysql_client_options(self, MYSQL_SECURE_AUTH, value)

                                     ^~~~~~~~~~~~~~~~~

                                     MYSQL_DEFAULT_AUTH

/usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here

  MYSQL_DEFAULT_AUTH,

  ^

10 errors generated.

make: *** [client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/huyy01/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.3.21 for inspection.

Results logged to /Users/huyy01/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/mysql2-0.3.21/gem_make.out

sh-huyy01:redmine huyy01$ cd /Users/huyy01/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/

1、通过命令创建项目的时候加上参数 -d,如rails new 项目名称 -d mysql

2、上述命令执行完后,rails 会自动安装 mysql2这个gem,同时会把该Gem加入到你的Gemfile文件中。

3、接着把database.xml中对于数据库的配置信息按照实际情况进行配置

4、执行rake db:create 命令创建数据库,即可

注意,如果你用的rails版本是小于4.2的版本,在执行步骤4的时候回报错“如果出现‘specified mysql2 for database adapter but the

gem is not loaded add gem mysql2 to your gemfile’,该错误的原因是因为你的Rails的版本和安装的mysql2的Gem版本之间的兼容问题,这个时候,需要在,把Gemfile中 mysql2 这个Gem制定 0.3.18这个版本 即【gem ‘mysql2’, ’~>0.3.18’】。保存后,执行bundle install。最后再执行步骤4即可。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6207987.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-18
下一篇 2023-03-18

发表评论

登录后才能评论

评论列表(0条)

保存