Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Shared library compiled by Sun studio can't be used by G++

Reply
Thread Tools

Shared library compiled by Sun studio can't be used by G++

 
 
HelloLinux
Guest
Posts: n/a
 
      06-26-2008
The following is how I encouted my problems:

1) Compile print.cpp into libprint.so by Sun C++ 5.9.The command is:
CC -G -KPIC -o libprint.so print.cpp
It succeeds.

2)Compile debug.cpp into libdebug.so by g++ 3.4.6, debug.cpp calls a
function defined in libprint.so. The command is:
g++ -shared -fPIC -o libdebug.so debug.cpp -lprint -L.
It succeeds too.

3)Compile main.cpp into a.out. main.cpp use a function defined in
libdebug.so. The command is:
g++ -fPIC main.cpp -ldebug -L.
It failed.The error msg is like below.

Undefined first referenced
symbol in file
print(char const*) ./libdebug.so
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

What I can't understand is that why step 2 succeed but then step 3
failed.
Do I miss some option when invoking g++ in step 3?

Any help will be appreciated, Thank in advance!

The code are here.

//print.cpp
#include "stdio.h"
#include "print.h"
void print(const char *msg)
{
printf("print: %s\n",msg);
}


//debug.cpp
#include <iostream>
#include "print.h"
using namespace std;
void debug_oo(const char *msg)
{
cout << "debug_oo: " << msg << endl;
print("called from debug_oo()");
}


//main.cpp
#include "debug.h"
int main(char* agrc, char** argv)
{
debug_oo("wangding");
return 0;
}
 
Reply With Quote
 
 
 
 
HelloLinux
Guest
Posts: n/a
 
      06-26-2008
And my hardware is sparc, And OS is Solaris 10.
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      06-26-2008
HelloLinux wrote:
> The following is how I encouted my problems:
>
> 1) Compile print.cpp into libprint.so by Sun C++ 5.9.The command is:
> CC -G -KPIC -o libprint.so print.cpp
> It succeeds.
>
> 2)Compile debug.cpp into libdebug.so by g++ 3.4.6, debug.cpp calls a
> function defined in libprint.so. The command is:
> g++ -shared -fPIC -o libdebug.so debug.cpp -lprint -L.
> It succeeds too.
>

You can't mix libraries compiled with one C++ compiler with code
compiled with another. Well OK you can, provided the functions exported
by the library have C linkage (declared as extern "C").

--
Ian Collins.
 
Reply With Quote
 
HelloLinux
Guest
Posts: n/a
 
      06-26-2008
On Jun 26, 3:53*pm, Ian Collins <ian-n...@hotmail.com> wrote:
> HelloLinux wrote:
> > The following is how I encouted my problems:

>
> > 1) Compile print.cpp into libprint.so by Sun C++ 5.9.The command is:
> > CC -G -KPIC -o libprint.so print.cpp
> > It succeeds.

>
> > 2)Compile debug.cpp into libdebug.so by g++ 3.4.6, debug.cpp calls a
> > function defined in libprint.so. The command is:
> > g++ -shared -fPIC -o libdebug.so debug.cpp -lprint -L.
> > It succeeds too.

>
> You can't mix libraries compiled with one C++ compiler with code
> compiled with another. *Well OK you can, provided the functions exported
> by the library have C linkage (declared as extern "C").
>
> --
> Ian Collins.


Thanks a lots, I will try to find a way out to compile all my libs
using g++.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
global variable is shared in shared library ankugoe7@gmail.com C Programming 1 07-15-2008 04:26 PM
If I create a page, then it's compiled upon first request, where cani find the compiled code?? lander ASP .Net 5 03-05-2008 04:34 PM
Sun Updates Sun Java Availability Suite, Adds Sun Cluster Advanced Edition for Oracle Real Application Clusters Deployments technology_post@yahoo.com Java 0 04-05-2006 04:29 AM
g++ compiled C++ code called from gcc compiled C code Klaus Schneider C++ 1 12-02-2004 01:44 PM
template instance in shared library on sun 5.7 John Dumais C++ 1 07-09-2003 12:05 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57