Problem linking a C++ shared object and C executable

Problem linking a C++ shared object and C executable

Post by news.barak.net.i » Tue, 25 Apr 2000 04:00:00



Hi,
I have the next problem:

I am building a C++ shared object using the SUN's workshop 5.0 compiler and
an executable using the gcc 2.8.1 compiler. Every thing works
just find until the moment I am trying to use an iostream object, from this
moment on I get the unresolved symbol error.

The C++ header :
#ifdef __cplusplus
extern "C"
#endif
 void foo( );

The source:
#include "a.h"
#include <iostream.h>
#ifdef __cplusplus
extern "C"
#endif
void foo( )
{
cout << "Hello world\n";

Quote:}

The C source (the executable):
#include "a.h"
#include <dlfcn.h>
#include <errno.h>
#include <stdio.h>

int main(){
        void* lpHandle;
        void (*lpFunc)();
        lpHandle=dlopen ( "liba.so", RTLD_NOW | RTLD_LOCAL);
        if ( !lpHandle )
        {
                perror ( "dlopen");
                printf ( "%s\n", dlerror());
                exit (errno );
        }

        lpFunc = (void(*)())(dlsym ( lpHandle, "foo"));
        if ( !lpFunc)
        {
                perror ( "dlsym");
                printf ( "%s\n", dlerror());
                exit (errno );
        }

        (*lpFunc)();

        dlclose ( lpHandle);

Quote:}

Every thing works fine until I start to build the executable using the gcc
compiler instead of the CC compiler.
The error I get is:
dlopen: Error 0
ld.so.1: ./a.out: fatal: relocation error: file ./liba.so: symbol
__1cDstd2l6Frn0ANbasic_ostream4Ccn0ALchar_traits4Cc____pkc_2_: referenced
symbol not found

The motivation for doing this is that I want to write an Apache's module in
C++. I have to use the CC compiler since I am using the ObjectSpace's STL.
But
the Apache was build using gcc. Using the Apache I get the same problem.

Thank you for your time.

Eyal

 
 
 

Problem linking a C++ shared object and C executable

Post by Frank Pilhof » Tue, 25 Apr 2000 04:00:00



> I am building a C++ shared object using the SUN's workshop 5.0 compiler and
> an executable using the gcc 2.8.1 compiler. Every thing works
> just find until the moment I am trying to use an iostream object, from this
> moment on I get the unresolved symbol error.

> ld.so.1: ./a.out: fatal: relocation error: file ./liba.so: symbol
> __1cDstd2l6Frn0ANbasic_ostream4Ccn0ALchar_traits4Cc____pkc_2_: referenced
> symbol not found

 You must of course link in the SunWSPro library that contains the iolib
stuff. Compile a C++ program with SunWSPro, and use -v to show linker op-
tions to find out.
 Good luck with this, though. You're bound to get other stuff like opera-
tor new() that might clash with gcc runtime. Basically, it's impossible
to mix C++ code between compilers.

        Frank

--

 |                                      http://www.uni-frankfurt.de/~fp/ |
 +---- Life would be a very great deal less weird without you.  - DA ----+

 
 
 

1. linking C++ code to a shared object on AIX

Hi all,
        can anyone tell me if there is a way to link a shared object such that you

        call the linker for each object file requires as opposed to one call to
the linker
        and passing the link a complete list of object files.
        For example, in psuedo code I would like to do the following:

        for earch (list of object files to link)
                call linker with an object file

        as opposed to what is typcially done which is

        ld (list of object files).

        If there is a way to do this could you please provide an example.

        Many thanks.  Regards, John Andrusek

2. Cabletron E21xx NIC Problem

3. Diald and cable modem?

4. Dynamic linking of C++ shared objects

5. How to force an ARP Reply Packet ?

6. creating new shared object from existing shared objects ??

7. D-Link220E ethernet card problem

8. C++ and shared object problem.

9. crating a static executable from shared objects.

10. Making an executable shared object

11. How to link object files from gcc and absoft f90 into a executable file?

12. Problem with new and delete in shared object (dynamic link library) files.