• Topic
  • Discussion
  • UdaWikiWeb.UdadocArticleosxodbclink(Last) -- Owiki? , 2016-08-19 15:01:09 Edit owiki 2016-08-19 15:01:09

    doc.Article.osxodbclink






    iODBC is an open-source project licensed under the LGPL and BSD licenses, developed and maintained by OpenLink Software. iODBC is here to facilitate connections from non-Windows systems to databases via ODBC.

    ODBC is a C API, a set of functions to let any C/C++ applications linked with it to access and manage data. Currently, ODBC is maintained by Microsoft as version 3.51. iODBC is compliant with this ODBC version.

    iODBC SDKs are different for each platform. They are shipped free of charge and are made available on the iODBC web site. They consist of: include files (.h), libraries for the corresponding platform and an application test program (iodbctest).

    There are no drivers included with the iODBC SDK, but you can find them on the OpenLink web site and provided by other companies. You can find below a set of URLs for the right iODBC SDK regarding the platform (which is the operating system and the CPU) you are targeting at http://www.iodbc.org/opliodbc.htm

    The package provided for this platform is a compressed Macintosh format (.hqx). After uncompressing on to your hard drive, you will find below, the tree of the iODBC SDK directory installed on the Mac OS Classic :

    iODBC/ the iODBC root directory include/ the iODBC include directory
    lib/ the iODBC library include directory
    samples/ the ODBC test project for Code Warrior
    ODBC setup PPC the iODBC Administrator

    iODBC consists of three parts, with each one having its own set of includes files and libraries. The ODBC Driver Manager is the core; its main task is to load the ODBC driver and pass the functions through. The task of the ODBC Configuration Manager is to access and manage the DSN files. The ODBC GUI Manager's main task is to allow the user to access all the ODBC functionality through a GUI. The iODBC CFM Bridge is the library against which Carbon applications have to be linked. Its main task is to redirect the ODBC API functions call to the right iODBC version regarding on which platform the applications is running on (Mac OS Classic / Mac OS X).

    NOTE: if you link against the iODBC CFM Bridge, be sure that no other iODBC libraries are linked in your project. An iODBC CFM Bridge-linked applications needs a valid iODBC installation on the target platform to run properly.

    Under the include directory, you will find all the iODBC header files which can be used in your sources - the main ones being isql.h, isqlext.h, isqltypes.h, iodbcadm.h, iodbcinst.h and are generally there are only a proxy for the other header files provided on the same directory : sql.h, sqlext.h, sqltypes.h, odbcinst.h. To access all these include files, you will just have to add to your compiler an include path which point to iODBC:include. This depends on the compiler you are using, so you will have to dig your compiler documentation. For Code Warrior, you can do that through the project preferences panel.

    Under the lib directory, you will find all the iODBC libraries needed to link against your application. All the parts explained before, are shipped in the three different forms: CFM shared library, static object file, and static object file with debugging information.

    ODBC Configuration Manager PPC \ ODBC Driver Manager PPC |---- CFM shared library ODBC GUI Manager PPC | iODBC CFM Bridge / iodbcinstPPC.o \ iodbcPPC.o |---- Static object file iodbcadm.o / iodbcinstPPC-dbg.o \ iodbcPPC-dbg.o |---- Static object file + debugging iodbcadm-dbg.o / 
    


    You will have to link your application with only one set of libraries. If you choose the CFM shared-library set, you will have to be careful that at runtime these files have to be put in the System-Extensions folder of your Mac Classic system.

    To access the right set of library files, you will just have to add to your linker a library path. After that, it depends on the compiler you are using, so you will have to read its documentation. For Code Warrior, you can do that through the project preferences panel.

    To access the right set of library files, you have to add to your linker a library path which point to iODBC:lib. This depends on the compiler you are using, so you will have to read the compiler documentation. For Code Warrior, you can do that through the project preferences panel, where you can set the libraries you wish to use in your project.

    The package provided for this platform is a Macintosh Installer package (.mpkg) inside a disk-image (.dmg) file. After mounting the disk-image by double-clicking on it, you should launch the Macintosh Installer package (.mpkg). You will be guided through the installation via the Macintosh Installer application.

    iODBC follows the Programmer and System guidelines defined by Apple, this document can be found at http://www.apple.com/developer/techpubs/macosx/SystemOverview/SystemOverview/SystemOverview.pdf

    You will find below all the tree of the iODBC SDK installed on Mac OS X :

    / ------------------------------------------------------------------> the Mac OS X root | directory | |-- Applications/ -------------------------------------------> the Mac OS X | | applications directory | | | |-- iODBC/ -------------------------------------------> the iODBC applications directory | | | |-- iODBC Administrator.app --------------> the iODBC Administrator | |-- iODBC Test.command ------------------> the iODBC test application | |-- Library/ --------------------------------------------------> the Mac OS X library | directory | |-- Application Support/ -----------------> the third parties support directory | | | |-- iodbc/ -------------------------------> the iODBC directory | | | |-- bin/odbctest -----------------> the odbc test command | | line application | | | |-- src/ -----------------------------> the odbc test project for | Project Builder | |-- CFM Support/ --------------------------> the CFM libraries directory | | | |-- iODBC CFM Bridge -------------> the iODBC CFM Bridge | | |-- Frameworks/ ---------------------------> the Mac OS X framework | | directory | | | |-- iODBC.framework --------------> the iODBC Core framework | |-- iODBCinst.framework ----------> the iODBC Conf. framework | |-- iODBCadm.framework --------> the iODBC GUI framework | |-- ODBC/ -----------------------------------> the ODBC drivers installed 
    


    The frameworks on Mac OS X the main point for all SDKs. They include all needed for developers, from the include-files to the shared-libraries against which to link, with version control. Support for the frameworks is well managed with Project Builder, shipped by Apple: use the GUI to drag and drop the framework you want use into place. We discuss use of frameworks through command-line utilities later.

    The framework is basically a directory, structured as follows:

    sample.framework ----------------------------------> our sample framework | |-- Headers -----------------> the includes files directory | |-- Resources --------------> the resources needed by our sample framework. | |-- sample -------------------> the library (in dyld format) which has the same name as the framework. 
    


    When you need to include one of the framework header files, you have to prepend your header file name with the framework name as below :

    #include <samples/my_sample_header.h> 
    


    iODBC is composed of three frameworks, each one having its own set of include files and libraries. The iODBC.framework is the core of the ODBC driver manager; its main task is to load the requested driver and convey the ODBC functions to it. The iODBCinst.framework is the ODBC configuration manager; its main task is to access and manage the DSNs. The iODBCadm.framework is the GUI manager, which gives the user the ability to access all the ODBC functionality through a GUI.

    First of all, you have to be sure that the compiler and linker you are using can manage frameworks correctly. The iODBC SDK ships with the odbctest application sources and project file, so it can be an example for you to let your application using iODBC.

    Under Project Builder, you have to put all the frameworks that your application will use in your project. Implicitly, all these frameworks will be used. Also, you have to be sure that the machine where you will run the application include all the frameworks you link with. In such cases, iODBC can be shipped with your application and all the frameworks. This is the most straight-forward way, but you can also directly use the compiler and linker command-line shipped with Project Builder. In a such case, you need to add options to let know the compiler and linker that you want to use a specific framework, but the sources do not need to be changed.

    During the compilation phase, you use the -F option to specify a framework search-path. The correct syntax is -Fdir, where dir is the path you want to add. You have to put one path, and there are no limit of -F option to pass on the command line. Regarding iODBC, you will have to add only -F/Library/Frameworks and -F/System/Library/Frameworks . A complete cc compilation command line will be like :

    -c "-F/Library/Frameworks" "-F/System/Library/Frameworks" ... mysources.c 
    


    During the linkage phase, you use the same option as above, and specify at the end of the command-line all the framework you want to link with, preceded with the option -framework . A complete cc linkage command line will be like :

    -o "myapplication" "-F/Library/Frameworks" "-F/System/Library/Frameworks" ... -framework "iODBC" -framework "iODBCinst" -framework "iODBCadm" 
    


    This documents has covered the problems faced when integrating iODBC support on Mac OS systems. The document is by no means complete but should provide a framework from which to start. Any feedback toward this subject is very welcome. Please mail any feedback regarding the subject of this HOW-TO to the maintainer of this document above.