你是怎么编译的?
是否提前做好了一个makefile?否则的话难以编译,makefile你可以找到例子的。
看懂了,改一改,你就知道了,一句话说不清楚。

解决方案 »

  1.   

    环境设置是要的,
    你要把ORACLE_HOME\..\precomp\下的相关lib弄到库里面去,
    vc的标准c的都有,
    我在vc环境下试过能成功的,
    你试一试吧.
      

  2.   

    不好意思,我没有说清楚//
    我用的是Plus*c的预编译,预编译以后生成.cpp,但是实际上是预编译时没有通过。错误如上所述。希望高手解答!谢谢!oicu(阿猫) 同志你说说的是在预编译阶段还是最后的编译阶段?还有什么叫“把ORACLE_HOME\..\precomp\下的相关lib弄到库里面去”?
    谢谢!还有,能不能得到你们的联系方式?
      

  3.   

    pro*c 设置
    # vi $ORACLE_HOME/precomp/admin/pcsctg.cfgsys_include=(/export/home1/oracle/precomp/public, /usr/include, /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include/, /usr/include, /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include, /usr/include) 
    include=(/usr/include)
    include=(/export/home1/oracle/precomp/public) 
    include=(/export/home1/oracle/rdbms/demo) 
    include=(/export/home1/oracle/network/public) 
    include=(/export/home1/oracle/plsql/public) ltype=short # proc sample1.pc
    #  gcc -o sample1 sample1.c -L$ORACLE_HOME/lib/  -lclntsh 
    #  gcc -o sample1 sample1.c -L$LD_LIBRARY_PATH  -lclntsh 
     
     回复人:hem(何明) (2001-5-23 18:05:00)  得0分 
    oci 一些参考。
    Using the Oracle Call Interface 
    Before using the Oracle Call Interface (OCI), verify that the correct version of the Pro*C/C++ is properly installed. The required version for the Linux system is specified in Chapter 1 of the Oracle8i Installation Guide for Intel-Linux. Demonstration Programs 
    Demonstration programs have been provided that show the varied functionality of the OCI. There are two types of demonstration programs, C and C++. All of the demonstration programs are located in the $ORACLE_HOME/rdbms/demo directory. Many of the demonstration programs assume that the demonstration tables created by the $ORACLE_HOME/sqlplus/demo/demobld.sql script are in the SCOTT schema with the password TIGER. For further information on building the demonstration programs using SQL*Plus, see "Demonstration Tables" of this book. For further information on the demonstration programs see the Programmer's Guide to the Oracle Call Interface and the program source for details of each program. Use the makefile, $ORACLE_HOME/rdbms/demo/demo_rdbms.mk, to create the demonstration programs. For example, to compile and link the cdemo1 demonstration program, enter the following command: $ make -f demo_rdbms.mk cdemo1
    Alternatively, the following command may be used to achieve the same result with more explicit syntax: $ make -f demo_rdbms.mk build OBJS=cdemo1.o EXE=cdemo1
    By default, all programs are dynamically linked with the client shared library, $ORACLE_HOME/lib/libclntsh.so. To create all OCI C demonstration programs, enter this command: $ make -f demo_rdbms.mk demos
    To create all OCI C++ demonstration programs, enter this command: $ make -f demo_rdbms.mk c++demos--------------------------------------------------------------------------------
    Note: If you receive the following errors while linking a C++ program: ld: fatal: library -lC: not found
    ld: fatal: library -lC_mtstubs: not found
    ld: fatal: library -lcx: not foundYou must include in LD_LIBRARY_PATH, the directory in which the specified libraries exist. 
    For example, if you are using the Intel-Linux Compiler C++, then the directory is /opt/CDS++. And, the following command must be entered: $ setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/opt/CDS++  
    --------------------------------------------------------------------------------Some demonstration programs require you to run a SQL script manually before you execute the program. All of the scripts are located in the $ORACLE_HOME/rbdms/demo directory. In most cases, the SQL script name is the same as the program name with a .sql extension. For example, the SQL script for the program oci02 is oci02.sql. Read the comments at the beginning of the program to determine the required SQL script, if any. User Programs 
    The makefile, $ORACLE_HOME/rdbms/demo/demo_rdbms.mk, may be used to create user programs. The general syntax for linking a user program with demo_rdbms.mk is: $ make -f demo_rdbms.mk target OBJS="objfile1 objfile2 ..."  EXE=exename
    For example, to create the program myprog from the C source myprog.c, use one of the following commands depending on the type of executable desired: For C source, dynamically linked with client shared library, enter the following: $ make -f demo_rdbms.mk build OBJS=myprog.o EXE=myprog
    For C source, statically linked, enter the following: $ make -f demo_rdbms.mk build_static OBJS=myprog.o EXE=myprog
    To create the program myprog from the C++ source myprog.cc, use one of the following commands depending on the type of executable desired: For C++ source, dynamically linked with client shared library, enter the following: $ make -f demo_rdbms.mk buildc++ OBJS=myprog.o EXE=myprog
    For C++ source, statically linked, enter the following: $ make -f demo_rdbms.mk buildc++_static OBJS=myprog.o EXE=myprog
    Oracle Precompiler and Oracle Call Interface Linking and Makefiles 
    Custom Makefiles 
    It is recommended that the provided demo_product.mk makefiles be used to link user programs as described in the specific product sections of this chapter. If it is necessary to modify the provided makefile, or if you decide to use a custom written makefile, note the following: Do not modify the ordering of the Oracle libraries. Oracle libraries are included on the link line more than once so all symbols are resolved during linking. There are two reasons for this: 
    Oracle libraries are mutually referential, meaning that functions in library A call functions in library B, and functions in library B call functions in library A. 
    The Linux linker is a one-pass linker, meaning that the linker searches a library exactly once at the point it is encountered in the link line. 
    If you add your own library to the link line, add it to the beginning or to the end of the link line. User libraries should not be placed between the Oracle libraries. 
    If you choose to use a make utility such as nmake or GNU make, be aware of how macro and suffix processing differs from the make utility provided with Linux, /usr/bin/make. Oracle makefiles have been tested and are supported with the Linux make utility. 
    Oracle library names and the contents of those libraries are subject to change between releases. Always use the demo_product.mk makefile that ships with the current release as a guide to determine which libraries are necessary. 
    Undefined Symbols 
    A common error when linking a program is undefined symbols, similar to the following: $ make -f demo_proc.mk sample1
    Undefined                      first referenced
    symbol                            in file
    sqlcex                              sample1.o
    sqlglm                              sample1.o
    ld: fatal: Symbol referencing errors. No output written to sample1
    This error occurs when the linker cannot find a definition for a referenced symbol. Generally, the remedy for this type of problem is to ensure that the library or object file containing the definition exists on the link line and that the linker is searching the correct directories for the file. Oracle provides a utility called symfind to assist in locating a library or object file where a symbol is defined. Here is example output of symfind locating the symbol sqlcex: $ symfind sqlcexSymFind - Find Symbol <sqlcex> in <**>.a, .o, .so
    ------------------------------------------------------
    Command:        /u01/app/oracle/product/8.1.5/bin/symfind sqlcex
    Local Directory: /u01/app/oracle/product/8.1.5
    Output File:    (none)
    Note:            I do not traverse symbolic links
                    Use '-v' option to show any symbolic linksLocating Archive and Object files ...
    [11645] &brvbar;    467572&brvbar;      44&brvbar;FUNC &brvbar;GLOB &brvbar;0    &brvbar;8      &brvbar;sqlcex
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ./lib/libclntsh.so
    [35]    &brvbar;        0&brvbar;      44&brvbar;FUNC &brvbar;GLOB &brvbar;0    &brvbar;5      &brvbar;sqlcex
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ./lib/libsql.aThread Support 
    The Oracle libraries provided with this release are thread safe, allowing support for multi-threaded applications. Static and Dynamic Linking with Oracle Libraries 
    Precompiler and OCI applications can be linked with Oracle Libraries either statically or dynamically. With static linking, the libraries and objects of the whole application are linked together into a single executable program. As a result, application executables can become fairly large. With dynamic linking, the executing code partly resides in the executable program and also resides in libraries that are linked by the application dynamically at runtime. Libraries that are linked at runtime are called dynamic or shared libraries. There are two primary benefits of dynamic linking. Smaller disk requirements 
    Different applications, or different invocations of the same application, can use the same shared or dynamic library. As a result, the overall disk requirements are reduced. Smaller main memory requirements 
    The same shared or dynamic library image (for example, the in-memory copy), can be shared by different applications. This means that a library needs to be loaded only once into the main memory and then multiple applications can use the same library. As a result, main memory requirements are reduced. Oracle Shared Library 
    The Oracle shared library is $ORACLE_HOME/lib/libclntsh.so. If the Oracle provided demo_product.mk makefile is used to link an application, the Oracle shared library is used by default. It may be necessary to set the environment variable LD_LIBRARY_PATH so the runtime loader can find the Oracle shared library at process startup. If you receive the following error when starting an executable, LD_LIBRARY_PATH must be set to the directory where the Oracle shared library exists: % sample1
    ld.so.1: sample1: fatal: libclntsh.so.1.0: can't open file: errno=2 
    Killed
    Set LD_LIBRARY_PATH as follows: % setenv LD_LIBRARY_PATH $ORACLE_HOME/lib
    The Oracle shared library is created automatically during installation. If there is a need to re-create the Oracle shared library, exit all client applications using the Oracle shared library, including all Oracle client applications such as SQL*Plus and Recovery Manager, and run the following command logged in as the oracle user: % cd $ORACLE_HOME/rdbms/lib
    % make -f ins_rdbms.mk libclntsh.so 
      

  4.   

    谢谢您的回复//
    想再请教一个问题:
    在Oci中可不可以直接把n条纪录插入数据库(比如:用一条Oci函数)