client.c:178:24:错误:调用未声明的函数“rb_tainted_str_new2”; ISO C99 及更高版本不支持隐式函数声明

问题描述 投票:0回答:1

我尝试在 macOS Sonoma 14.2.1 上安装 mysql2 gem,首先收到错误:

> gem install mysql2
...
ld: library 'zstd' not found
...

然后:

> gem install mysql2 -- --with-ldflags=-L(brew --prefix zstd)/lib
(works fine)

所以实际上我正在做的是(来自另一篇 Stack Overflow 帖子):

> gem install mysql2 -v '0.5.3' -- --with-opt-dir=(brew --prefix openssl) --with-ldflags=-L(brew --prefix zstd)/lib
...
client.c:178:24: error: call to undeclared function 'rb_tainted_str_new2'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  VALUE rb_sql_state = rb_tainted_str_new2(mysql_sqlstate(wrapper->client));
                       ^
...

我找不到如何解决这个错误


还有

第一个完整日志:

> gem install mysql2
Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/mysql2-0.5.5/ext/mysql2
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/bin/ruby extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
-----
Using --with-openssl-dir=/opt/homebrew/opt/openssl@3
-----
-----
Using mysql_config at /opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_DEFAULT_AUTH in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/8.2.0_1/lib
-----
creating Makefile

current directory: /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240111-94110-1asi02 sitelibdir\=./.gem.20240111-94110-1asi02 clean

current directory: /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240111-94110-1asi02 sitelibdir\=./.gem.20240111-94110-1asi02
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c:304:35: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
        precision = field->length - (field->decimals > 0 ? 2 : 1);
                  ~ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library 'zstd' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/mysql2-0.5.5 for inspection.
Results logged to /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/extensions/arm64-darwin-23/3.3.0/mysql2-0.5.5/gem_make.out

第二个完整日志:

> gem install mysql2 -v '0.5.3' -- --with-opt-dir=(brew --prefix openssl) --with-ldflags=-L(brew --prefix zstd)/lib
Fetching mysql2-0.5.3.gem
Building native extensions with: '--with-opt-dir=/opt/homebrew/opt/openssl@3 --with-ldflags=-L/opt/homebrew/opt/zstd/lib'
This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/mysql2-0.5.3/ext/mysql2
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/bin/ruby extconf.rb --with-opt-dir\=/opt/homebrew/opt/openssl@3 --with-ldflags\=-L/opt/homebrew/opt/zstd/lib
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Setting rpath to /opt/homebrew/Cellar/mysql/8.2.0_1/lib
-----
creating Makefile

current directory: /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/mysql2-0.5.3/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240111-96291-f3ji93 sitelibdir\=./.gem.20240111-96291-f3ji93 clean

current directory: /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/mysql2-0.5.3/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240111-96291-f3ji93 sitelibdir\=./.gem.20240111-96291-f3ji93
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
client.c:178:24: error: call to undeclared function 'rb_tainted_str_new2'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  VALUE rb_sql_state = rb_tainted_str_new2(mysql_sqlstate(wrapper->client));
                       ^
client.c:787:14: warning: incompatible function pointer types passing 'VALUE (void *)' (aka 'unsigned long (void *)') to parameter of type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
  rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
             ^~~~~~~~~~~~~
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/include/ruby-3.3.0/ruby/internal/iterator.h:388:26: note: passing argument to parameter 'b_proc' here
VALUE rb_rescue2(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*r_proc)(VALUE, VALUE), VALUE data2, ...);
                         ^
client.c:795:16: warning: incompatible function pointer types passing 'VALUE (void *)' (aka 'unsigned long (void *)') to parameter of type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
    rb_rescue2(do_query, (VALUE)&async_args, disconnect_and_raise, self, rb_eException, (VALUE)0);
               ^~~~~~~~
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/include/ruby-3.3.0/ruby/internal/iterator.h:388:26: note: passing argument to parameter 'b_proc' here
VALUE rb_rescue2(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*r_proc)(VALUE, VALUE), VALUE data2, ...);
                         ^
4 warnings and 1 error generated.
make: *** [client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/extensions/arm64-darwin-23/3.3.0/mysql2-0.5.3/gem_make.out
mysql ruby-on-rails ruby rubygems
1个回答
0
投票

解决方案是添加

--with-cflags="-Wno-error=implicit-function-declaration"

例如

gem install mysql2 -v '0.5.3' -- --with-opt-dir=(brew --prefix openssl) --with-ldflags=-L(brew --prefix zstd)/lib --with-cflags="-Wno-error=implicit-function-declaration"
© www.soinside.com 2019 - 2024. All rights reserved.