Search code examples
perloracle-databasemacososx-snow-leoparddbd

How do you install perl DBD::Oracle on OSX Snow Leopard 10.6


I'm trying to connect to Oracle 10.2.0.4 on a remote system from my intel mac running OSX 10.6 snow leopard. I've tried using perl CPAN to install DBD::Oracle (DBI worked ok) but get compilation errors. Could someone provide an easy to follow guide?


Solution

  • Getting a mac install of perl to play nicely with oracle is a bit of a pain - once it's running it is fantastic, getting it running is a little frustrating..

    The below has worked for me on a few different intel macs, there could well be superfluous steps in there and it is likely not going to be the same for other platforms.

    This will require use of shell, the root user and a bit of CPANing - nothing too onerous

    First off create a directory for the oracle pap - libraries, instant client etc

    sudo mkdir /usr/oracle_instantClient64
    

    Download and extract all 64 bit instant client packages from oracle to the above directory

    Create a symlink within that directory for one of the files in there

    sudo cd /usr/oracle_instantClient64
    sudo ln -s /usr/oracle_instantClient64/libclntsh.dylib.10.1 libclntsh.dylib
    

    The following dir is hardcoded into the oracle instant client - god knows why - so need to create and symlink it

    sudo mkdir -p /b/227/rdbms/
    sudo cd /b/227/rdbms/
    sudo ln -s /usr/oracle_instantClient64/ lib
    

    Need to add a couple of environment variables, so edit /etc/profile and add them so they exist for all users:

    export ORACLE_HOME=/usr/oracle_instantClient64
    export DYLD_LIBRARY_PATH=/usr/oracle_instantClient64
    

    Now try and install DBD::Oracle through CPAN - this will fail, but it means any dependencies will be downloaded and it retrieves the module for us

    sudo perl -MCPAN -e shell
    install DBD::Oracle
    

    When this fails exit CPAN and head to your .cpan/build dir - if you used automatic config of CPAN it'll be

    cd ~/.cpan/build
    

    if you didn't auto configure you can find your build directory with the following command in CPAN

    o conf build_dir
    

    Once in the build dir look for the DBD::Oracle dir which has just been created (it'll be called something like DBD-Oracle-1.28-?) and cd into it.

    Now we need to switch to the root user. Root isn't enabled as default in osx - for details on enabling see this post on the apple website

    Once logged in as root we need to set the above environment variables for root:

    export ORACLE_HOME=/usr/oracle_instantClient64
    export DYLD_LIBRARY_PATH=/usr/oracle_instantClient64
    

    Now while still logged in as root we need to run the makefile for the module, then make, then install

    perl Makefile.pl
    make
    make install
    

    Assuming that all worked without error log out of root: we're DBD'd up! If this didn't work it's time to bust out google on whatever errors you're seeing

    Now just to install the DBI module

    sudo perl -MCPAN -e shell
    install DBI
    

    Now you're all set - enjoy your perly oracley new life

    Additional info from user852637:

    1. Correction to this step

      perl Makefile.pl
      make
      install
      

      The last step should be make install

    2. During make, you may encounter an error that looks like :

      lipo: can't open input file: /var/tmp//ccIevTzM.out (No such file or directory)

      To correct this you must edit the file "Makefile" created after the "perl Makefile.pl" step and remove all occurrences of the following text :

      -arch ppc 
      

      This will eliminate the error.

    3. The same error described in (2.) will occur during the installation of the DBI module. You must edit the Makefile created after the perl Makefile.pl step and remove all occurrences of the following text :

      -arch ppc