13 Replies Latest reply: Sep 28, 2008 6:35 PM by 571637 RSS

    Building OCI app in XCode

    436038
      I'm trying to start my very first cocoa project that communicates with Oracle via OCI.

      And I see the Intel-friendly version of the instantclient is finally available---something which has kept me from starting the project for a while now.

      But I seem to be having some problems getting the project settings in XCode just right.

      Here's what I've done so far:

      1—downloaded the intel instant client... both basic and sdk
      2—unzipped and put everything into a folder called "instantclient" as per the Oracle instructions
      3—put the instantclient folder inside my Oracle home... /Library/Oracle
      4—went into XCode 3.0 and selected menu Project > Edit Project Settings
      5—clicked on the Build tab
      6—updated value for "Header Search Paths" to /Library/Oracle/instantclient/sdk/include
      7—updated value for "Library Search Paths" to /Library/Oracle/instantclient
      8—updated value for "Other Linker Flags" to -lclntsh

      But when I put the following line into my .h or .m file...
      #include <oci.h>

      I get a compiler error message:
      ld: library not found for -lclntsh
      collect2: ld returned 1 exit status

      I was just wondering if someone might be able to spot the error of my ways.

      Thanks.
        • 1. Re: Building OCI app in XCode
          Ronald Rood
          Normally that lib is in $ORACLE_HOME/lib.

          does that help you ?
          regards,
          Ronald
          http://ronr.nl/unix-dba
          • 2. Re: Building OCI app in XCode
            jpiwowar
            Brad,

            I don't have a full SDK installed, just instantclient+sqlplus, but here's what's in my ORACLE_HOME:
            zathras:instantclient_10_2 jpiwowar$ ls *clntsh*
            libclntsh.dylib.10.1
            Do you have a file called libclntsh.dylib in your ORACLE_HOME? If not, you may need to create a symlink to the dylib.10.1 file:
            ln -s libclntsh.dylib.10.1 libclntsh.dylib
            Regards,

            John P.
            http://only4left.jpiwowar.com
            • 3. Re: Building OCI app in XCode
              436038
              When I change the "Library Search Paths" to $ORACLE_HOME/lib I get the compiler error:
              ld: warning in /Library/Oracle/lib/libclntsh.dylib, file is not of required architecture

              I'm assuming that's because the ORACLE_HOME directory was originally created a while ago before the Intel-friendly version of instant client came out. So the file libclntsh.dylib in the /lib directory is for PowerPC.

              Which is why I pointed XCode to the new Intel "instantclient" directory instead. I thought it would see the new file libclntsh.dylib.10.1

              Is that not an Intel replacement for libcIntsh.dylib? Or am I missing something...
              • 4. Re: Building OCI app in XCode
                436038
                I tried the symlink and it got rid of the compiler error.

                But now I get a compiler warning:

                ld: warning in /Library/Oracle/lib/libclntsh.dylib, file is not of required architecture

                Isn't libclntsh.dylib.10.1 supposed to be Intel compatible? Or am I misinterpreting the message?

                I'm running XCode 3.0 / OS 10.5.4 / Intel Powerbook.
                • 5. Re: Building OCI app in XCode
                  jpiwowar
                  Brad,

                  You have the correct library, but it is Intel-only, not Universal. Consider the following comparison between the Oracle-supplied library and a typical OS X system library file:
                  zathras:instantclient_10_2 jpiwowar$ file libclntsh.dylib.10.1 
                  libclntsh.dylib.10.1: Mach-O dynamically linked shared library i386
                  zathras:instantclient_10_2 jpiwowar$ file `ls /usr/lib/*.dylib | tail -1`
                  /usr/lib/libzfs.dylib: Mach-O universal binary with 2 architectures
                  /usr/lib/libzfs.dylib (for architecture i386):     Mach-O dynamically linked shared library i386
                  /usr/lib/libzfs.dylib (for architecture ppc7400):     Mach-O dynamically linked shared library ppc
                  I'm guessing that Xcode is trying to compile a Universal binary by default, and that you need to supply additional options to XCode to get it to compile for only the Intel architecture. Unfortunately, since I'm not an XCode user (nor, to be honest, much of a developer at all ;-), I don't know what's necessary to make that happen.

                  Regards,

                  John P.
                  http://only4left.jpiwowar.com
                  • 6. Re: Building OCI app in XCode
                    436038
                    Hey John-

                    Thanks. I turned off all the valid architectures except i386 and the compiler error went away.

                    But now I'm getting an error message when I run the app—

                    The Debugger has exited with status 0.
                    [Session started at 2008-07-25 10:15:49 -0400.]
                    Loading program into debugger…
                    GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct 2 04:07:49 UTC 2007)
                    Copyright 2004 Free Software Foundation, Inc.
                    GDB is free software, covered by the GNU General Public License, and you are
                    welcome to change it and/or distribute copies of it under certain conditions.
                    Type "show copying" to see the conditions.
                    There is absolutely no warranty for GDB. Type "show warranty" for details.
                    This GDB was configured as "i386-apple-darwin".tty /dev/ttys000
                    warning: Unable to read symbols for "/scratch/plebld/208/rdbms/lib/libclntsh.dylib.10.1" (file not found).
                    Program loaded.
                    sharedlibrary apply-load-rules all
                    run
                    [Switching to process 1046 local thread 0x2f13]
                    Running…
                    dyld: Library not loaded: /scratch/plebld/208/rdbms/lib/libclntsh.dylib.10.1
                    Referenced from: /Users/bgourley/Documents/Programming/Cocoa Projects/DB Projects/OCI for Intel/Connect via OCI/build/Release/Connect via OCI.app/Contents/MacOS/Connect via OCI
                    Reason: image not found
                    Program received signal: “SIGTRAP”.
                    Xcode: Introspection dylib not loaded because thread 1 has function: __dyld_dyld_fatal_error on stack
                    warning: Couldn't find minimal bounds for "_sigtramp" - backtraces may be unreliable


                    And the application is literally nothing more than a header file with #include <oci.h>

                    Does anything in the error message look particularly insightful to you?
                    • 7. Re: Building OCI app in XCode
                      jpiwowar
                      Does anything in the error message look particularly insightful to you?
                      Hi Brad,

                      This part does:
                      dyld: Library not loaded: /scratch/plebld/208/rdbms/lib/libclntsh.dylib.10.1
                      I've seen a similar error message when I try to launch sqlplus without defining the DYLD_LIBRARY_PATH environment variable in my shell environment. I think that the '/scratch/plebld/208/rdbms/lib' is some sort of stub/default within the Oracle libraries themselves, or a relic from the build environment at Oracle where the libraries were generated.

                      I'm guessing that the runtime environment for your application needs to know about DYLD_LIBRARY_PATH. That environment variable needs to point to the directory that contains libclntsh.dylib.10.1. Easy enough if you're launching from the command line (just export the environment variable), but I don't know exactly how to accomplish that when launching from a GUI...somewhere in Info.plist, maybe?

                      Regards,

                      John P.
                      http://only4left.jpiwowar.com
                      • 8. Re: Building OCI app in XCode
                        436038
                        Hey John-

                        Muchas gracias dude.

                        That allowed me to compile without any errors.

                        To add an environment variable in XCode I opened the "Excutables" folder, double-clicked on my executable which brings up an executable info palette, then clicked on the "Arguments" tab and added an environment variable...

                        name—DYLD_LIBRARY_PATH
                        value—path to a libclntsh.dylib symlink which points to the Intel only friendly libcInsh.dylib.10.1
                        • 9. Re: Building OCI app in XCode
                          jpiwowar
                          Brad,

                          Cool, glad that got you rolling. Thanks for the XCode tip, too; I'll file that one away for later. :-)

                          Regards,

                          John P.
                          http://only4left.jpiwowar.com
                          • 10. Re: Building OCI app in XCode
                            436038
                            Well, now that I've got all the compiler errors out of the way... I keep getting an error when I call OCIEnvCreate.

                            My code so far is real simple and basically just cut and pasted from the demo code supplied with Oracle's instant client:

                            int main (int argc, const char * argv[]) {
                                 
                                 static OCIEnv *envhp;
                                 
                                 sword errcode = 0;
                                 
                                 errcode = OCIEnvCreate((OCIEnv **) &envhp, (ub4) OCI_DEFAULT,
                                                          (dvoid *) 0, (dvoid * (*)(dvoid *,size_t)) 0,
                                                          (dvoid * (*)(dvoid *, dvoid *, size_t)) 0,
                                                          (void (*)(dvoid *, dvoid *)) 0, (size_t) 0, (dvoid **) 0);
                                 
                                 if (errcode != 0) {
                                      (void) printf("OCIEnvCreate failed with errcode = %d.\n", errcode);
                                 }     

                                 return 0;
                            }

                            The errcode keeps coming back -1. And I don't know where to look without more information than that.

                            Any insights would be greatly appreciated.
                            • 11. Re: Building OCI app in XCode
                              436038
                              Problem fixed.

                              I threw away and reinstalled the complete client and things worked.
                              • 12. Re: Building OCI app in XCode
                                661334
                                I'm trying to build an application with Qt 4.4.1 OpenSource Edition and OTL. I made libclntsh.dylib symlink in the Instant Client home. Here is the part of my .pro file:

                                INCLUDEPATH += /opt/instantclient10_1/sdk/include
                                DYLD_LIBRARY_PATH = /opt/instantclient10_1
                                OCI_INCLUDES = /opt/instantclient10_1/sdk/include
                                OCI_LIBS = "-L/opt/instantclient10_1 -lclntsh"

                                Linker gives me an error:

                                /usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: Undefined symbols:
                                _OCIAttrSet
                                _OCIEnvInit
                                _OCIErrorGet
                                _OCIHandleAlloc
                                _OCIHandleFree
                                _OCIInitialize
                                _OCIServerAttach
                                _OCIServerDetach
                                _OCISessionBegin
                                _OCISessionEnd
                                collect2: ld returned 1 exit status

                                Where is the mistake? Help me please...
                                • 13. Re: Building OCI app in XCode
                                  571637
                                  Hi,

                                  Maybe OCI_LIBS = "-L/opt/instantclient10_1/lib -lclntsh" ? (See the extra lib on there, it soflinks back to the dylibs)

                                  Also I'm really not sure if this will help you at all but I had to fiddle around when I compiled PHP, so I suggest you do the following

                                  1) softlink like so :
                                  mkdir /scratch
                                  mkdir /scratch/plebld
                                  mkdir /scratch/plebld/208
                                  mkdir /scratch/plebld/208/rdbms
                                  ln -s /opt/instantclient10_1 /scratch/plebld/208/rdbms/lib
                                  n.b. Yes I know you shouldn't really need to do this as this is what setting DYLD_LIBRARY_PATH was about, but even if this gets you past the linking error then you know what to chase.

                                  2) IIRC I also had to add a softlink to a dylib as a .so, I think it may have been libclntsh.dylib.10.1 to libclntsh.so but this was more likely a PHP compile issue. Here is a list of my directory contents
                                  emagenote10:~ schaappa$ ls -al /scratch/plebld/208/rdbms/lib/
                                  total 203376
                                  drwxr-xr-x@ 28 schaappa staff 952 21 Jul 17:09 .
                                  drwxr-xr-x 4 schaappa admin 136 24 Apr 14:28 ..
                                  -rw-r--r--@ 1 schaappa staff 6148 24 Apr 13:49 .DS_Store
                                  -rw-r--r-- 1 schaappa staff 277 27 Mar 2008 BASIC_README
                                  -rw-r--r-- 1 schaappa staff 275 27 Mar 2008 JDBC_README
                                  -rw-r--r-- 1 schaappa staff 281 27 Mar 2008 SQLPLUS_README
                                  -r--r--r--@ 1 schaappa staff 1609607 18 Feb 2008 classes12.jar
                                  -rwxr-xr-x@ 1 schaappa staff 30556 27 Mar 2008 genezi
                                  -r-xr-xr-x@ 1 schaappa staff 1525 30 Aug 2004 glogin.sql
                                  drwxr-xr-x 10 schaappa staff 340 21 Jul 17:10 lib
                                  lrwxr-xr-x 1 schaappa staff 20 24 Apr 14:31 libclntsh.dylib -> libclntsh.dylib.10.1
                                  -rwxr-xr-x@ 1 schaappa staff 21252860 7 Mar 2008 libclntsh.dylib.10.1
                                  lrwxr-xr-x 1 schaappa staff 20 6 May 09:28 libclntsh.so -> libclntsh.dylib.10.1
                                  -rwxr-xr-x@ 1 schaappa staff 31016 22 Feb 2008 libheteroxa10.dylib
                                  -rwxr-xr-x@ 1 schaappa staff 31016 22 Feb 2008 libheteroxa10.jnilib
                                  -rwxr-xr-x@ 1 schaappa staff 1638264 7 Mar 2008 libnnz10.dylib
                                  lrwxr-xr-x 1 schaappa staff 18 24 Apr 14:31 libocci.dylib -> libocci.dylib.10.1
                                  -rwxr-xr-x@ 1 schaappa staff 1111964 11 Mar 2008 libocci.dylib.10.1
                                  -rwxr-xr-x@ 1 schaappa staff 72626696 27 Mar 2008 libociei.dylib
                                  -rwxr-xr-x@ 1 schaappa staff 103800 22 Feb 2008 libocijdbc10.dylib
                                  -rwxr-xr-x@ 1 schaappa staff 103800 22 Feb 2008 libocijdbc10.jnilib
                                  -rwxr-xr-x@ 1 schaappa staff 865412 21 Feb 2008 libsqlplus.dylib
                                  -rwxr-xr-x@ 1 schaappa staff 1442316 21 Feb 2008 libsqlplusic.dylib
                                  drwxr-xr-x 3 schaappa staff 102 6 May 13:18 network
                                  -r--r--r--@ 1 schaappa staff 1555682 18 Feb 2008 ojdbc14.jar
                                  -r--r--r--@ 1 schaappa staff 1646178 23 Jan 2008 orai18n.jar
                                  drwxr-xr-x@ 7 schaappa staff 238 24 Apr 13:49 sdk
                                  -rwxr-xr-x@ 1 schaappa staff 12612 21 Feb 2008 sqlplus

                                  Best of luck !