This discussion is archived
2 Replies Latest reply: Oct 21, 2011 6:46 AM by 858326 RSS

g++ error......Multiple defnitions for oraca and sqlca

858326 Newbie
Currently Being Moderated
Hi All,

I have come across the following error when trying to compile the source code using g++.
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iostream:76: multiple definition of `oraca'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/new:94: multiple definition of `sqlca'
One common header is including sql2oci.h+. We are trying to create one shared library from many *.cc* files. Most of them include sql2oci.h+.

The following example shows the exact scenario.

sql2oci1.cc
      #include <sql2oci.h>
      #include <iostream>

      void display()
      {
        std::cout << "I am sqlca-1" << std::endl;
      }
sql2oci2.cc
      #include <sql2oci.h>
      #include <iostream>

      extern void display();

      int main() {
        display();
        std::cout << "I am sqlca-2" << std::endl;

        return 0;
      }
$ g++ -m32 -Wall -g -c -I/app/oracle/client/precomp/public -I/app/oracle/client/rdbms/public -o sql2oci1.o sql2oci1.cc
$ g++ -m32 -Wall -g -c -I/app/oracle/client/precomp/public -I/app/oracle/client/rdbms/public -o sql2oci2.o sql2oci2.cc
$ g++ -m32 -Wall -g -o sample sql2oci1.o sql2oci2.o
sql2oci2.o: In function `__static_initialization_and_destruction_0':
/data1/users/nfr1dev2/port_gcc/sql2oci2.cc:11: multiple definition of `sqlca'
sql2oci1.o:/data1/users/nfr1dev2/port_gcc/sql2oci1.cc:7: first defined here
sql2oci2.o: In function `main':
/data1/users/nfr1dev2/port_gcc/sql2oci2.cc:8: multiple definition of `oraca'
sql2oci1.o:(.bss+0xa0): first defined here
collect2: ld returned 1 exit status
In the header, sql2oci.h+, the structs oraca and sqlca are defined.
When i am trying to combine several *.o* files to produce a binary/library, the compiler is seeing the definitons of oraca and sqlca being included from different obj files.

Can someone suggest a solution...or.....any work-around for this?

Thanks in advance.

Cheers,
Sreekar

Edited by: 855323 on 20-Oct-2011 02:15
  • 1. Re: g++ error......Multiple defnitions for oraca and sqlca
    Steve_Clamage Pro
    Currently Being Moderated
    Apparently sql2oci.h has macro definitions or other declarations that conflict with the standard headers <iostream> and <new>.
    Try including <sql2oci.h> after the standard headers. In general, standard headers should be included before application and project headers to avoid such conflicts.

    If still no joy, check with the supplier of header sql2oci.h to see whether it has known compatibility issues with g++ on Linux.
  • 2. Re: g++ error......Multiple defnitions for oraca and sqlca
    858326 Newbie
    Currently Being Moderated
    Hi Steve,

    Thanks for the response.

    Even if the include the header after the standard header, the error still persists.

    In my case the file <sql2oci.h> is included via some other header-file.

    - header1.h (includes <sql2oci.h>)
    - shared-header.h (includes header1.h) has some function declarations.
    - shared-header-func-defnitions.c (function defnitions)
    - shared-header.h is included in many *.cc* files and that caused the problem.


    Scrutinized the code and found that header1.h is not actually being used in any of the *.cc* files.
    it is required only in the function-definitions (for declations included in shared-header.h).

    Hence, moved header1.h from shared-header.h to shared-header-func-defnitions.c

    That solved the issue.


    I strictly believe that one should never include the defnition of a structure/function in a shared-header.

    Cheers,
    Sreekar

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points