kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 78 forks source link

checking for OCIEnvCreate() in oci.h... no on Big Sur (M1 chip) #237

Closed allthesignals closed 2 years ago

allthesignals commented 2 years ago

I'm trying to install 2.2.9 on Big Sur with a 2021 MacBook (M1 chip). I think this is a related issue: https://github.com/kubo/ruby-oci8/issues/236.

I installed from homebrew and set OCI_DIR (/opt/oracle/instantclient_19_8)


bash-3.2$ gem install ruby-oci8
Building native extensions. This could take a while...
ERROR:  Error installing ruby-oci8:
    ERROR: Failed to build gem native extension.

    current directory: /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8
/Users/mattgardner/.rbenv/versions/2.7.3/bin/ruby -I /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/2.7.0 -r ./siteconf20210927-43461-mmlsmc.rb extconf.rb
attempting to locate oracle-instantclient...
checking load library path...
  DYLD_LIBRARY_PATH is not set.
  DYLD_FALLBACK_LIBRARY_PATH is not set.
  checking OCI_DIR...
    checking /opt/oracle/instantclient_19_8... yes
  checking dependent shared libraries in /opt/oracle/instantclient_19_8/libclntsh.dylib.19.1...
  /opt/oracle/instantclient_19_8/libclntsh.dylib.19.1 looks like an instant client.
checking for cc... ok
checking for gcc... yes
checking for LP64... yes
checking for sys/types.h... yes
checking for ruby header... ok
checking for OCIEnvCreate() in oci.h... no
*** 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=/Users/mattgardner/.rbenv/versions/2.7.3/bin/$(RUBY_BASE_NAME)
    --with-instant-client
    --without-instant-client
    --with-instant-client-dir
    --without-instant-client-dir
    --with-instant-client-include
    --without-instant-client-include=${instant-client-dir}/include
    --with-instant-client-lib
    --without-instant-client-lib=${instant-client-dir}/lib
    --with-sys-dir
    --without-sys-dir
    --with-sys-include
    --without-sys-include=${sys-dir}/include
    --with-sys-lib
    --without-sys-lib=${sys-dir}/lib
/Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1138:in `block in initialize': RuntimeError (RuntimeError)
    from /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1106:in `open'
    from /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1106:in `initialize'
    from /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:271:in `new'
    from /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:271:in `get'
    from extconf.rb:22:in `<main>'
/Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1138:in `block in initialize': Could not compile with Oracle instant client. (RuntimeError)
You may need to set the environment variable RC_ARCHS or ARCHFLAGS as follows:

    RC_ARCHS=x86_64
    export RC_ARCHS
or
    ARCHFLAGS='-arch x86_64'
    export RC_ARCHS

If it does not fix the problem, delete all '-arch arm64'
in '/Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/2.7.0/arm64-darwin20/rbconfig.rb'.
    from /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1106:in `open'
    from /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1106:in `initialize'
    from /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:271:in `new'
    from /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:271:in `get'
    from extconf.rb:22:in `<main>'
---------------------------------------------------
Error Message:
  Could not compile with Oracle instant client.
  You may need to set the environment variable RC_ARCHS or ARCHFLAGS as follows:

      RC_ARCHS=x86_64
      export RC_ARCHS
  or
      ARCHFLAGS='-arch x86_64'
      export RC_ARCHS

  If it does not fix the problem, delete all '-arch arm64'
  in '/Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/2.7.0/arm64-darwin20/rbconfig.rb'.

Backtrace:
  /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1138:in `block in initialize'
  /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1106:in `open'
  /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:1106:in `initialize'
  /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:271:in `new'
  /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9/ext/oci8/oraconf.rb:271:in `get'
  extconf.rb:22:in `<main>'
---------------------------------------------------
See:
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-full-client.md for Oracle full client
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-instant-client.md for Oracle instant client
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-on-osx.md for OS X
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/report-installation-issue.md to report an issue.

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

  /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/extensions/arm64-darwin-20/2.7.0/ruby-oci8-2.2.9/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/ruby-oci8-2.2.9 for inspection.
Results logged to /Users/mattgardner/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/extensions/arm64-darwin-20/2.7.0/ruby-oci8-2.2.9/gem_make.out

Here is the mkmf.log:


"clang -o conftest -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/arm64-darwin20 -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/ruby/backward -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0 -I. -I/Users/mattgardner/.rbenv/versions/2.7.3/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c  -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -fstack-protector-strong  -m64   -lruby.2.7   "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

"clang -o conftest -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/arm64-darwin20 -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/ruby/backward -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0 -I. -I/Users/mattgardner/.rbenv/versions/2.7.3/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c  -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -fstack-protector-strong  -m64   -lruby.2.7   "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() { return 0; }
/* end */

./conftest
"clang -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/arm64-darwin20 -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/ruby/backward -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0 -I. -I/Users/mattgardner/.rbenv/versions/2.7.3/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe -m64  -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: /*top*/
4: #ifndef __GNUC__
5: # error
6: |:/ === __GNUC__ undefined === /:|
7: #endif
/* end */

"clang -o conftest -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/arm64-darwin20 -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/ruby/backward -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0 -I. -I/Users/mattgardner/.rbenv/versions/2.7.3/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe conftest.c  -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -fstack-protector-strong  -m64   -lruby.2.7   "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() { return sizeof(long) == 8 ? 0 : 1; }
/* end */

./conftest
have_header: checking for sys/types.h... -------------------- yes

"clang -E -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/arm64-darwin20 -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/ruby/backward -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0 -I. -I/Users/mattgardner/.rbenv/versions/2.7.3/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe  conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <sys/types.h>
/* end */

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

have_func: checking for OCIEnvCreate() in oci.h... -------------------- no

"clang -o conftest -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/arm64-darwin20 -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/ruby/backward -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0 -I. -I/Users/mattgardner/.rbenv/versions/2.7.3/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe -I/opt/oracle/instantclient_19_8/sdk/include conftest.c  -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -fstack-protector-strong  -m64   -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -L/opt/oracle/instantclient_19_8 -Wl,-rpath,/opt/oracle/instantclient_19_8 -lclntsh -lruby.2.7  -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -L/opt/oracle/instantclient_19_8 -Wl,-rpath,/opt/oracle/instantclient_19_8 -lclntsh  "
ld: warning: ignoring file /opt/oracle/instantclient_19_8/libclntsh.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
  "_OCIEnvCreate", referenced from:
      _t in conftest-573d1a.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <oci.h>
 4: 
 5: /*top*/
 6: extern int t(void);
 7: int main(int argc, char **argv)
 8: {
 9:   if (argc > 1000000) {
10:     int (* volatile tp)(void)=(int (*)(void))&t;
11:     printf("%d", (*tp)());
12:   }
13: 
14:   return !!argv[argc];
15: }
16: int t(void) { void ((*volatile p)()); p = (void ((*)()))OCIEnvCreate; return !p; }
/* end */

"clang -o conftest -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/arm64-darwin20 -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0/ruby/backward -I/Users/mattgardner/.rbenv/versions/2.7.3/include/ruby-2.7.0 -I. -I/Users/mattgardner/.rbenv/versions/2.7.3/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -fno-common -pipe -I/opt/oracle/instantclient_19_8/sdk/include conftest.c  -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib -L. -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -fstack-protector-strong  -m64   -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -L/opt/oracle/instantclient_19_8 -Wl,-rpath,/opt/oracle/instantclient_19_8 -lclntsh -lruby.2.7  -L/Users/mattgardner/.rbenv/versions/2.7.3/lib  -L/opt/oracle/instantclient_19_8 -Wl,-rpath,/opt/oracle/instantclient_19_8 -lclntsh  "
conftest.c:16:13: error: conflicting types for 'OCIEnvCreate'
extern void OCIEnvCreate();
            ^
/opt/oracle/instantclient_19_8/sdk/include/ociap.h:7324:9: note: previous declaration is here
sword   OCIEnvCreate (OCIEnv **envp, ub4 mode, void  *ctxp,
        ^
conftest.c:17:28: error: too few arguments to function call, expected 8, have 0
int t(void) { OCIEnvCreate(); return 0; }
              ~~~~~~~~~~~~ ^
/opt/oracle/instantclient_19_8/sdk/include/ociap.h:7324:9: note: 'OCIEnvCreate' declared here
sword   OCIEnvCreate (OCIEnv **envp, ub4 mode, void  *ctxp,
        ^
2 errors generated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <oci.h>
 4: 
 5: /*top*/
 6: extern int t(void);
 7: int main(int argc, char **argv)
 8: {
 9:   if (argc > 1000000) {
10:     int (* volatile tp)(void)=(int (*)(void))&t;
11:     printf("%d", (*tp)());
12:   }
13: 
14:   return !!argv[argc];
15: }
16: extern void OCIEnvCreate();
17: int t(void) { OCIEnvCreate(); return 0; }
/* end */

--------------------
kubo commented 2 years ago

@allthesignals Could you run file /Users/mattgardner/.rbenv/versions/2.7.3/bin/ruby?

If it prints Mach-O 64-bit executable arm64, you need to install ruby compiled for intel mac and run it on Rosetta 2 until Oracle releases Oracle client for M1 chip. I don't know how to install ruby for intel mac on M1 mac.

If it prints Mach-O 64-bit executable x86_64 or Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64], could you run gem install ruby-oci8 on Rosetta 2 as follows? According to this Japanese page, clang creates x86_64 binary by default on Rosetta 2.

$ arch -x86_64 /bin/zsh
$ gem install ruby-oci8
allthesignals commented 2 years ago

@allthesignals Could you run file /Users/mattgardner/.rbenv/versions/2.7.3/bin/ruby?

If it prints Mach-O 64-bit executable arm64, you need to install ruby compiled for intel mac and run it on Rosetta 2 until Oracle releases Oracle client for M1 chip. I don't know how to install ruby for intel mac on M1 mac.

If it prints Mach-O 64-bit executable x86_64 or Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64], could you run gem install ruby-oci8 on Rosetta 2 as follows? According to this Japanese page, clang creates x86_64 binary by default on Rosetta 2.

$ arch -x86_64 /bin/zsh
$ gem install ruby-oci8

Perfect, thank you — this did the trick. I had all the pieces just couldn't put them together in the right order! Thanks again.

duffyjp commented 2 years ago

@allthesignals Can you detail out your steps? I'm using the same 19.8 instant client but I'm getting errors on the gem install ruby-oci8 step run under x86_64. Probably because my ruby is still arm.

Did you end up installing an entire intel ruby? I'm using RVM and haven't found a way to do that, though it appears to be somewhat architecture aware. You're using rbenv?

$ rvm list
   ruby-2.6.9 [ arm64 ]
   ruby-2.7.5 [ arm64 ]
=* ruby-3.0.3 [ arm64 ]
$ arch -x86_64 gem install ruby-oci8
...
oci8lib.c:408:10: error: implicit declaration of function 'rb_thread_blocking_region' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    rv = rb_thread_blocking_region((VALUE(*)(void*))parg->func, parg->data, oci8_unblock_func, parg->svcctx);
         ^
1 error generated.