* RE: Question about shared library for Solaris
@ 2004-04-20 16:46 lrtaylor
0 siblings, 0 replies; 3+ messages in thread
From: lrtaylor @ 2004-04-20 16:46 UTC (permalink / raw)
To: komiyama, gcc-help
As Les said, use g++ when linking C++ code. However, note that there
are problems on Solaris and Linux (those are the platforms that I have
experience on - don't know if the problem exists elsewhere) passing and
catching exceptions across library boundaries when building with GCC
2.95.X. Linking with g++ with takes care of some of the problems, but
you may still run into cases where the exceptions don't get caught and
the program aborts. I would highly recommend upgrading to a more recent
version of GCC if possible. That has fixed all of the problems we have
seen like this. However, you still need to link with g++.
Cheers,
Lyle
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of komiyama
Sent: Tuesday, April 20, 2004 12:39 AM
To: gcc-help@gcc.gnu.org
Subject: Question about shared library for Solaris
Hi GCC experts,
I have a question about Shared library that compiled with Gcc for
Solaris.
With above example code,
---------- test1.h -----------------------------------------------
class class1 {
public:
~class1 ();
void func1 ();
};
---------- test1.cc ----------------------------------------------
#include <stdexcept>
#include "test1.h"
using namespace std;
void class1::func1 () {
throw runtime_error ("This is erro ");
}
class1::~class1 () {
cout << "Class1 destructor is called " << endl;
}
--------- main.cc -------------------------------------------------
#include "test1.h"
#include <stdexcept>
using namespace std;
class except_1 {};
class class2 {
public:
~class2 () {
cout << "Class2 destructor is called "<< endl;
}
void func1() { throw except_1 (); }
void func2 () { throw runtime_error ("Error from class2"); }
};
int main () {
class2 test2;
try {
test2.func1();
}
catch ( except_1& e ) {
cout << "Catch except1 " << endl;
}
try {
test2.func2();
}
catch ( runtime_error& e ) {
cout << "Catch except2 " << e.what() << endl;
}
try { // This try block ignored (1)
class1 test;
test.func1();
}
catch ( runtime_error& e ) {
cout << "Catch except2 "<< e.what () << endl;
}
}
-------------------------------------------------------------------
When I create executable with Makefile1, the generated executable
is crashed with,
Catch except1
Catch except2 Error from class2
Abort <----
It seems that try catch block (1) seems to ignored.
---------- Makefile1 ----------------------------------------------
SHARE_OBJ = test1.o
.cc.o :
g++ -g -fPIC -c -o $@ -save-temps $<
libshared.so: ${SHARE_OBJ}
/usr/ccs/bin/ld -G -o $@ ${SHARE_OBJ}
test: main.o libshared.so
g++ -v -o $@ $< -L. -L/usr/local/gcc/2.95.3/lib -lshared
-lstdc++
clean:
-/bin/rm *.o *.so
-----------------------------------------------------------------------
But when I compiled with Makefile2, generated executable run without
any problems.
The only difference is when created shared library, in the failed case,
it directory called /usr/ccs/bin/ld ,but passed case it called
/usr/ccs/bin/ld
through g++ compiler driver.
( It seems that g++ called collect2 and collect2 called /usr/ccs/bin/ld)
So my questions are,
1: What does collect2 do when it passed data to /usr/ccs/bin/ld ?
2: Is it possible to work with only /usr/ccs/bin/ld ?
( Does not use g++ compiler driver when create shared object )
Environemnt is
O.S : Solaris8 (Sparc)
Gcc : 2.95.3
-------------------- Makefile2 ----------------------------------------
SHARE_OBJ = test1.o
.cc.o :
g++ -g -fPIC -c -o $@ -save-temps $<
libshared.so: ${SHARE_OBJ}
g++ -v -G -o $@ ${SHARE_OBJ} -lc
test: main.o libshared.so
g++ -v -o $@ $< -L. -L/usr/local/gcc/2.95.3/lib -lshared
-lstdc++
clean:
-/bin/rm *.o *.so
----------------------------------------------------------------------
Takeo Komiyama
-----------------------------------------------------------------------
Takeo Komiyama
Voice : +81-22-377-9767 Fax : +81-22-377-9709
ESLD design , CSG
Semiconductor Products Division , Nippon Motorola Ltd.
2-9-1 , Akedori, Izumiku, Sendai-shi, Miyagi-ken 981-32
Email : komiyama@sddc.sps.mot.com
-----------------------------------------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: Question about shared library for Solaris
@ 2004-04-20 9:06 Lev Assinovsky
0 siblings, 0 replies; 3+ messages in thread
From: Lev Assinovsky @ 2004-04-20 9:06 UTC (permalink / raw)
To: komiyama, gcc-help
When you linking g++ .o forget about ld.
Use just g++!
----
Lev Assinovsky
Aelita Software Corporation
(now is a part of Quest Software)
O&S InTrust Framework Division, Team Leader
ICQ# 165072909
> -----Original Message-----
> From: komiyama [mailto:komiyama@sddc.sps.mot.com]
> Sent: Tuesday, April 20, 2004 10:39 AM
> To: gcc-help@gcc.gnu.org
> Subject: Question about shared library for Solaris
>
>
> Hi GCC experts,
>
> I have a question about Shared library that compiled with Gcc
> for Solaris.
>
> With above example code,
>
> ---------- test1.h -----------------------------------------------
> class class1 {
>
> public:
> ~class1 ();
>
> void func1 ();
>
> };
> ---------- test1.cc ----------------------------------------------
> #include <stdexcept>
> #include "test1.h"
>
> using namespace std;
>
> void class1::func1 () {
>
> throw runtime_error ("This is erro ");
>
> }
>
>
> class1::~class1 () {
>
> cout << "Class1 destructor is called " << endl;
>
> }
> --------- main.cc -------------------------------------------------
> #include "test1.h"
> #include <stdexcept>
>
> using namespace std;
>
> class except_1 {};
>
> class class2 {
>
> public:
> ~class2 () {
> cout << "Class2 destructor is called "<< endl;
> }
>
> void func1() { throw except_1 (); }
>
>
> void func2 () { throw runtime_error ("Error from class2"); }
>
> };
>
> int main () {
>
> class2 test2;
>
> try {
> test2.func1();
> }
> catch ( except_1& e ) {
> cout << "Catch except1 " << endl;
> }
>
>
> try {
> test2.func2();
> }
> catch ( runtime_error& e ) {
> cout << "Catch except2 " << e.what() << endl;
> }
>
> try { // This try block ignored (1)
> class1 test;
> test.func1();
> }
> catch ( runtime_error& e ) {
> cout << "Catch except2 "<< e.what () << endl;
> }
> }
> -------------------------------------------------------------------
>
> When I create executable with Makefile1, the generated executable
> is crashed with,
>
>
> Catch except1
> Catch except2 Error from class2
> Abort <----
>
> It seems that try catch block (1) seems to ignored.
>
> ---------- Makefile1 ----------------------------------------------
>
> SHARE_OBJ = test1.o
>
>
> .cc.o :
> g++ -g -fPIC -c -o $@ -save-temps $<
>
>
> libshared.so: ${SHARE_OBJ}
> /usr/ccs/bin/ld -G -o $@ ${SHARE_OBJ}
>
> test: main.o libshared.so
> g++ -v -o $@ $< -L. -L/usr/local/gcc/2.95.3/lib
> -lshared -lstdc++
>
> clean:
> -/bin/rm *.o *.so
>
> --------------------------------------------------------------
> ---------
>
> But when I compiled with Makefile2, generated executable run without
> any problems.
>
> The only difference is when created shared library, in the
> failed case,
> it directory called /usr/ccs/bin/ld ,but passed case it
> called /usr/ccs/bin/ld
> through g++ compiler driver.
>
> ( It seems that g++ called collect2 and collect2 called
> /usr/ccs/bin/ld)
>
> So my questions are,
> 1: What does collect2 do when it passed data to /usr/ccs/bin/ld ?
> 2: Is it possible to work with only /usr/ccs/bin/ld ?
> ( Does not use g++ compiler driver when create shared object )
>
> Environemnt is
> O.S : Solaris8 (Sparc)
> Gcc : 2.95.3
>
>
> -------------------- Makefile2
> ----------------------------------------
> SHARE_OBJ = test1.o
>
>
> .cc.o :
> g++ -g -fPIC -c -o $@ -save-temps $<
>
>
> libshared.so: ${SHARE_OBJ}
> g++ -v -G -o $@ ${SHARE_OBJ} -lc
>
> test: main.o libshared.so
> g++ -v -o $@ $< -L. -L/usr/local/gcc/2.95.3/lib
> -lshared -lstdc++
>
> clean:
> -/bin/rm *.o *.so
>
> ----------------------------------------------------------------------
>
>
> Takeo Komiyama
>
> --------------------------------------------------------------
> ---------
> Takeo Komiyama
> Voice : +81-22-377-9767 Fax : +81-22-377-9709
> ESLD design , CSG
> Semiconductor Products Division , Nippon Motorola Ltd.
> 2-9-1 , Akedori, Izumiku, Sendai-shi, Miyagi-ken 981-32
> Email : komiyama@sddc.sps.mot.com
> --------------------------------------------------------------
> ---------
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Question about shared library for Solaris
@ 2004-04-20 6:38 komiyama
0 siblings, 0 replies; 3+ messages in thread
From: komiyama @ 2004-04-20 6:38 UTC (permalink / raw)
To: gcc-help
Hi GCC experts,
I have a question about Shared library that compiled with Gcc for Solaris.
With above example code,
---------- test1.h -----------------------------------------------
class class1 {
public:
~class1 ();
void func1 ();
};
---------- test1.cc ----------------------------------------------
#include <stdexcept>
#include "test1.h"
using namespace std;
void class1::func1 () {
throw runtime_error ("This is erro ");
}
class1::~class1 () {
cout << "Class1 destructor is called " << endl;
}
--------- main.cc -------------------------------------------------
#include "test1.h"
#include <stdexcept>
using namespace std;
class except_1 {};
class class2 {
public:
~class2 () {
cout << "Class2 destructor is called "<< endl;
}
void func1() { throw except_1 (); }
void func2 () { throw runtime_error ("Error from class2"); }
};
int main () {
class2 test2;
try {
test2.func1();
}
catch ( except_1& e ) {
cout << "Catch except1 " << endl;
}
try {
test2.func2();
}
catch ( runtime_error& e ) {
cout << "Catch except2 " << e.what() << endl;
}
try { // This try block ignored (1)
class1 test;
test.func1();
}
catch ( runtime_error& e ) {
cout << "Catch except2 "<< e.what () << endl;
}
}
-------------------------------------------------------------------
When I create executable with Makefile1, the generated executable
is crashed with,
Catch except1
Catch except2 Error from class2
Abort <----
It seems that try catch block (1) seems to ignored.
---------- Makefile1 ----------------------------------------------
SHARE_OBJ = test1.o
.cc.o :
g++ -g -fPIC -c -o $@ -save-temps $<
libshared.so: ${SHARE_OBJ}
/usr/ccs/bin/ld -G -o $@ ${SHARE_OBJ}
test: main.o libshared.so
g++ -v -o $@ $< -L. -L/usr/local/gcc/2.95.3/lib -lshared -lstdc++
clean:
-/bin/rm *.o *.so
-----------------------------------------------------------------------
But when I compiled with Makefile2, generated executable run without
any problems.
The only difference is when created shared library, in the failed case,
it directory called /usr/ccs/bin/ld ,but passed case it called /usr/ccs/bin/ld
through g++ compiler driver.
( It seems that g++ called collect2 and collect2 called /usr/ccs/bin/ld)
So my questions are,
1: What does collect2 do when it passed data to /usr/ccs/bin/ld ?
2: Is it possible to work with only /usr/ccs/bin/ld ?
( Does not use g++ compiler driver when create shared object )
Environemnt is
O.S : Solaris8 (Sparc)
Gcc : 2.95.3
-------------------- Makefile2 ----------------------------------------
SHARE_OBJ = test1.o
.cc.o :
g++ -g -fPIC -c -o $@ -save-temps $<
libshared.so: ${SHARE_OBJ}
g++ -v -G -o $@ ${SHARE_OBJ} -lc
test: main.o libshared.so
g++ -v -o $@ $< -L. -L/usr/local/gcc/2.95.3/lib -lshared -lstdc++
clean:
-/bin/rm *.o *.so
----------------------------------------------------------------------
Takeo Komiyama
-----------------------------------------------------------------------
Takeo Komiyama
Voice : +81-22-377-9767 Fax : +81-22-377-9709
ESLD design , CSG
Semiconductor Products Division , Nippon Motorola Ltd.
2-9-1 , Akedori, Izumiku, Sendai-shi, Miyagi-ken 981-32
Email : komiyama@sddc.sps.mot.com
-----------------------------------------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-04-20 16:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-20 16:46 Question about shared library for Solaris lrtaylor
-- strict thread matches above, loose matches on Subject: below --
2004-04-20 9:06 Lev Assinovsky
2004-04-20 6:38 komiyama
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).