如何在 macOS Catalina 上使用 Oracle Instant Client 安装 Perl DBD::Oracle
How to install Perl DBD::Oracle with Oracle Instant Client on macOS Catalina
我正在 运行安装 macOS Catalina 10.15.7,我需要将 Oracle Instant Client 安装到 运行 运行 连接到数据库的 Perl 脚本。
1。安装 Oracle Instant Client
我下载了我需要的包:
- 基本灯包 (DMG)
- SDK 包 (DMG)
- ODBC 包 (DMG)
从 Instant Client 19.8 开始并遵循 installation instructions 没有任何问题(只是复制和粘贴)
The files are extracted in /Users/username/Downloads/instantclient_19_8
2。设置 ORACLE_HOME
接下来,我确实将 ORACLE_HOME 设置为 /Users/username/Downloads/instantclient_19_8
export ORACLE_HOME=/Users/username/Downloads/instantclient_19_8
3。正在安装 DBD::Oracle
当我尝试安装 DBD::Oracle
时出现以下错误:
$ cpanm DBD::Oracle
--> Working on DBD::Oracle
Fetching http://www.cpan.org/authors/id/M/MJ/MJEVANS/DBD-Oracle-1.80.tar.gz ... OK
Configuring DBD-Oracle-1.80 ... N/A
! Configure failed for DBD-Oracle-1.80. See /Users/username/.cpanm/work/1608142485.48272/build.log for details.
日志文件内容:
$ cat /Users/username/.cpanm/work/1608142485.48272/build.log
cpanm (App::cpanminus) 1.7044 on perl 5.032000 built for darwin-thread-multi-2level
Work directory is /Users/username/.cpanm/work/1608142485.48272
You have make /usr/bin/make
You have LWP 6.47
You have /usr/bin/tar: bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.6
You have /usr/bin/unzip
Searching DBD::Oracle () on cpanmetadb ...
--> Working on DBD::Oracle
Fetching http://www.cpan.org/authors/id/M/MJ/MJEVANS/DBD-Oracle-1.80.tar.gz
-> OK
Unpacking DBD-Oracle-1.80.tar.gz
Entering DBD-Oracle-1.80
Checking configure dependencies from META.json
Checking if you have Config 0 ... Yes (5.032000)
Checking if you have Encode 0 ... Yes (3.06)
Checking if you have Math::BigInt 0 ... Yes (1.999818)
Checking if you have Devel::Peek 0 ... Yes (1.28)
Checking if you have Test::More 0 ... Yes (1.302177)
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.44)
Checking if you have Data::Dumper 0 ... Yes (2.174)
Checking if you have DBI 1.623 ... Yes (1.643)
Checking if you have Test::NoWarnings 0 ... Yes (1.04)
Configuring DBD-Oracle-1.80
Running Makefile.PL
Using DBI 1.643 (for perl 5.032000 on darwin-thread-multi-2level) installed in /usr/local/Cellar/perl/5.32.0/lib/perl5/site_perl/5.32.0/darwin-thread-multi-2level/auto/DBI/
Configuring DBD::Oracle for perl 5.032000 on darwin (darwin-thread-multi-2level)
If you encounter any problem, a collection of troubleshooting
guides are available under lib/DBD/Oracle/Troubleshooting.
'DBD::Oracle::Troubleshooting' is the general troubleshooting
guide, while platform-specific troubleshooting hints
live in their labelled sub-document (e.g., Win32
hints are gathered in 'lib/DBD/Oracle/Troubleshooting/Win32.pod').
Trying to find an ORACLE_HOME
Your DYLD_LIBRARY_PATH env var is set to ''
The ORACLE_HOME environment variable is not set and I couldn't guess it.
It must be set to hold the path to an Oracle installation directory
on this machine (or a machine with a compatible architecture).
See the appropriate troubleshooting guide for your OS for more information.
ABORTED!
-> N/A
-> FAIL Configure failed for DBD-Oracle-1.80. See /Users/username/.cpanm/work/1608142485.48272/build.log for details.
我读过 here ORACLE_HOME
应该设置为包含 /bin
目录的目录的值,但我找不到任何 /bin
.
macOS 一直在变化,但在 Mojave 上我从 DMG 安装了 Instant Client 然后做了:
brew install perl
ln -s $HOME/Downloads/instantclient_19_8 $HOME/instantclient
export DYLD_LIBRARY_PATH=$HOME/instantclient
cpan -i -T DBI
cpan -i -T DBD::Oracle
一般来说,永远不要为 Instant Client 设置 ORACLE_HOME。 (这可能导致读取错误的配置文件)。 ORACLE_HOME 用于 'full' 数据库或完整客户端安装,不适用于 Instant Client。然而,一些安装程序仍然引用该变量来查找构建文件,因此您将需要它 - 至少在构建时。 DBD::Oracle 将在内部搜索 Instant Client 并在未设置 $ORACLE_HOME 时使用 $HOME/instantclient。
macOS 已逐渐删除 DYLD_LIBRARY_PATH 的用处,因为它不会传播到子外壳。这意味着它不能可靠地使用。在 Mojave 上,我发现我可以选择将 Instant Client 库复制到 $HOME/lib/ 而不需要设置 DYLD_LIBRARY_PATH.
旁注:如果您使用 DBD::Oracle,则不需要 Instant Client ODBC 包。
Christopher Jones 的回答对我来说还不够(macOS Monterey 12.2,Apple M1 Pro)。安装停止于
./Oracle.h:37:10: fatal error: 'oci.h' file not found
要解决此问题,需要安装 Oracle SDK 包 https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html#ic_osx_inst
第二条评论:
export DYLD_LIBRARY_PATH=$HOME/instantclient
不起作用(参见 Bash variable of name starting with 'DYLD' is not loaded into environment: bug or feature?)
============================================= =====
但这不是end-of-the-problem。安装的DBD::Oracle无法使用。失败:
Can't load '/Users/myname/.perlbrew/libs/perl-5.34.1@eien6/lib/perl5/darwin-2level/auto/DBD/Oracle/Oracle.bundle'
for module DBD::Oracle: dlopen(/Users/myname/.perlbrew/libs/perl-5.34.1@eien6/lib/perl5/darwin-2level/auto/DBD/Oracle/Oracle.bundle, 0x0001):
symbol not found in flat namespace '_OCIAttrGet' at
/Users/myname/perl5/perlbrew/perls/perl-5.34.1/lib/5.34.1/darwin-2level/DynaLoader.pm line 197.
这与MacOS SIP机制有关吗?如何使用 DBD::Oracle ?
我正在 运行安装 macOS Catalina 10.15.7,我需要将 Oracle Instant Client 安装到 运行 运行 连接到数据库的 Perl 脚本。
1。安装 Oracle Instant Client
我下载了我需要的包:
- 基本灯包 (DMG)
- SDK 包 (DMG)
- ODBC 包 (DMG)
从 Instant Client 19.8 开始并遵循 installation instructions 没有任何问题(只是复制和粘贴)
The files are extracted in
/Users/username/Downloads/instantclient_19_8
2。设置 ORACLE_HOME
接下来,我确实将 ORACLE_HOME 设置为 /Users/username/Downloads/instantclient_19_8
export ORACLE_HOME=/Users/username/Downloads/instantclient_19_8
3。正在安装 DBD::Oracle
当我尝试安装 DBD::Oracle
时出现以下错误:
$ cpanm DBD::Oracle
--> Working on DBD::Oracle
Fetching http://www.cpan.org/authors/id/M/MJ/MJEVANS/DBD-Oracle-1.80.tar.gz ... OK
Configuring DBD-Oracle-1.80 ... N/A
! Configure failed for DBD-Oracle-1.80. See /Users/username/.cpanm/work/1608142485.48272/build.log for details.
日志文件内容:
$ cat /Users/username/.cpanm/work/1608142485.48272/build.log
cpanm (App::cpanminus) 1.7044 on perl 5.032000 built for darwin-thread-multi-2level
Work directory is /Users/username/.cpanm/work/1608142485.48272
You have make /usr/bin/make
You have LWP 6.47
You have /usr/bin/tar: bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.6
You have /usr/bin/unzip
Searching DBD::Oracle () on cpanmetadb ...
--> Working on DBD::Oracle
Fetching http://www.cpan.org/authors/id/M/MJ/MJEVANS/DBD-Oracle-1.80.tar.gz
-> OK
Unpacking DBD-Oracle-1.80.tar.gz
Entering DBD-Oracle-1.80
Checking configure dependencies from META.json
Checking if you have Config 0 ... Yes (5.032000)
Checking if you have Encode 0 ... Yes (3.06)
Checking if you have Math::BigInt 0 ... Yes (1.999818)
Checking if you have Devel::Peek 0 ... Yes (1.28)
Checking if you have Test::More 0 ... Yes (1.302177)
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.44)
Checking if you have Data::Dumper 0 ... Yes (2.174)
Checking if you have DBI 1.623 ... Yes (1.643)
Checking if you have Test::NoWarnings 0 ... Yes (1.04)
Configuring DBD-Oracle-1.80
Running Makefile.PL
Using DBI 1.643 (for perl 5.032000 on darwin-thread-multi-2level) installed in /usr/local/Cellar/perl/5.32.0/lib/perl5/site_perl/5.32.0/darwin-thread-multi-2level/auto/DBI/
Configuring DBD::Oracle for perl 5.032000 on darwin (darwin-thread-multi-2level)
If you encounter any problem, a collection of troubleshooting
guides are available under lib/DBD/Oracle/Troubleshooting.
'DBD::Oracle::Troubleshooting' is the general troubleshooting
guide, while platform-specific troubleshooting hints
live in their labelled sub-document (e.g., Win32
hints are gathered in 'lib/DBD/Oracle/Troubleshooting/Win32.pod').
Trying to find an ORACLE_HOME
Your DYLD_LIBRARY_PATH env var is set to ''
The ORACLE_HOME environment variable is not set and I couldn't guess it.
It must be set to hold the path to an Oracle installation directory
on this machine (or a machine with a compatible architecture).
See the appropriate troubleshooting guide for your OS for more information.
ABORTED!
-> N/A
-> FAIL Configure failed for DBD-Oracle-1.80. See /Users/username/.cpanm/work/1608142485.48272/build.log for details.
我读过 here ORACLE_HOME
应该设置为包含 /bin
目录的目录的值,但我找不到任何 /bin
.
macOS 一直在变化,但在 Mojave 上我从 DMG 安装了 Instant Client 然后做了:
brew install perl
ln -s $HOME/Downloads/instantclient_19_8 $HOME/instantclient
export DYLD_LIBRARY_PATH=$HOME/instantclient
cpan -i -T DBI
cpan -i -T DBD::Oracle
一般来说,永远不要为 Instant Client 设置 ORACLE_HOME。 (这可能导致读取错误的配置文件)。 ORACLE_HOME 用于 'full' 数据库或完整客户端安装,不适用于 Instant Client。然而,一些安装程序仍然引用该变量来查找构建文件,因此您将需要它 - 至少在构建时。 DBD::Oracle 将在内部搜索 Instant Client 并在未设置 $ORACLE_HOME 时使用 $HOME/instantclient。
macOS 已逐渐删除 DYLD_LIBRARY_PATH 的用处,因为它不会传播到子外壳。这意味着它不能可靠地使用。在 Mojave 上,我发现我可以选择将 Instant Client 库复制到 $HOME/lib/ 而不需要设置 DYLD_LIBRARY_PATH.
旁注:如果您使用 DBD::Oracle,则不需要 Instant Client ODBC 包。
Christopher Jones 的回答对我来说还不够(macOS Monterey 12.2,Apple M1 Pro)。安装停止于
./Oracle.h:37:10: fatal error: 'oci.h' file not found
要解决此问题,需要安装 Oracle SDK 包 https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html#ic_osx_inst
第二条评论:
export DYLD_LIBRARY_PATH=$HOME/instantclient
不起作用(参见 Bash variable of name starting with 'DYLD' is not loaded into environment: bug or feature?)
============================================= =====
但这不是end-of-the-problem。安装的DBD::Oracle无法使用。失败:
Can't load '/Users/myname/.perlbrew/libs/perl-5.34.1@eien6/lib/perl5/darwin-2level/auto/DBD/Oracle/Oracle.bundle'
for module DBD::Oracle: dlopen(/Users/myname/.perlbrew/libs/perl-5.34.1@eien6/lib/perl5/darwin-2level/auto/DBD/Oracle/Oracle.bundle, 0x0001):
symbol not found in flat namespace '_OCIAttrGet' at
/Users/myname/perl5/perlbrew/perls/perl-5.34.1/lib/5.34.1/darwin-2level/DynaLoader.pm line 197.
这与MacOS SIP机制有关吗?如何使用 DBD::Oracle ?