473,624 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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("wangd ing");
return 0;
}
Jun 27 '08 #1
3 1826
And my hardware is sparc, And OS is Solaris 10.
Jun 27 '08 #2
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.
Jun 27 '08 #3
On Jun 26, 3:53*pm, Ian Collins <ian-n...@hotmail.co mwrote:
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++.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2190
by: Simon | last post by:
Hello. I wanna use my dynamic shared library(built with C language) with php script. (PHP version is 4.0.6) So I making a shared library(*.so) in Solaris environment(2.7) and it is successful. Php script can load my library successfully. And Now I port my library to HP(HP-UX 11.0) and IBM(AIX 4.1.3) system.
0
2265
by: Phil | last post by:
I realize this is the php group, but I have a question that recurses back to my php install. My objective is a pure 64 bit shared object installation of php 5.0 on UltraSparc Solaris 9 compiled with the Sun Compiler version 8. My problem is that EVERYTHING builds great EXCEPT that the 6b distribution of JPEG will NOT build a shared object, thus gd cannot include support for JPEG, thus php loses that functionality.
5
10514
by: Oliver | last post by:
Hi, I have a problem with a shared library of mine. I compile the *.o files and then generate the .so lib with: cc -shared libjava_vrpn.so *.o When I then run my program I get an error for an unresolved symbol. The symbols it's looking for are in another library called libvrpn.a, but for some unknown reason the compiler does not uses this library when I tell him to used.
1
4412
by: AH | last post by:
I have two functions in my shared library which are declared as follows: void setName(const std::string& str); std::vector<std::string> getInfo(); Since the code is compiled and in shared library. Every thing is great if the customer of my shared library is using the same compiler version (and same STL version). I am wondering if the customer changes their compiler version (or STL version) which may have same interface
2
2031
by: santa19992000 | last post by:
Confusing th eword with "library", "shared library" and how to use these things in real C project, is there any small example I can take a look. Thanks.
9
4175
by: Invalidlastname | last post by:
Hi, We developed some assemblies which use EnterpriseServices queued components. In order to use EnterpriseServices, these assemblies need to be installed into GAC. I used the pre-build and post-build events to automate GAC installation processes and the asp.net application has "copy to local" set to false for the references of these shared assemblies. However, every time we made the changes to the shared assemblies, we had to restart...
7
5202
by: Steve | last post by:
Hi, We have an application framework library that gets statically linked to any applications we produce. (Windows apps, but I don't think that matters here). The framework is based heavily on the STL and the API uses many STL constructs. Because of the static linking, and the fact that both app and framework are built by the same compiler, we don't have any problems.
8
2075
by: bonk | last post by:
Is it generally OK for an EXE that has MFC linked statically to load an use another DLL wich has MFC linked as shared DLL ? To be more specific: I have an EXE that links a lib. Let's call it mylib.lib. That Lib as well as the EXE have MFC linked statically. Then in a completely different project I have a regular DLL, wich is compiled with the /CLR switch and therefore needs the special CRT libs as
3
3268
by: Bala | last post by:
Hello, I am trying to create a shared library on solaris. The inputs to this library is a source file and then 2 static libraries. I need to call code within the shared library in another application which in turn will use the static libraries for further processing. This is the command i am using to build the shared library
0
8174
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8624
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7164
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.