From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12858 invoked by alias); 20 Apr 2004 09:06:39 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 12659 invoked from network); 20 Apr 2004 09:06:35 -0000 Received: from unknown (HELO gate.algorithm.aelita.com) (212.176.18.2) by sources.redhat.com with SMTP; 20 Apr 2004 09:06:35 -0000 Received: from bagman.edm.com ([10.30.32.14]) by gate.algorithm.aelita.com (Post.Office MTA v3.5.3 release 223 ID# 0-12345L500S10000V35) with ESMTP id com for ; Tue, 20 Apr 2004 13:06:35 +0400 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1251" Content-Transfer-Encoding: quoted-printable Subject: RE: Question about shared library for Solaris Date: Tue, 20 Apr 2004 09:06:00 -0000 Message-ID: <3F6F4712B759A34ABD453A8B39C10D62022B165D@bagman.edm.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: From: "Lev Assinovsky" To: "komiyama" , X-SW-Source: 2004-04/txt/msg00266.txt.bz2 When you linking g++ .o forget about ld. Use just g++! ---- Lev Assinovsky Aelita Software Corporation=20 (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 >=20 >=20 > Hi GCC experts, >=20 > I have a question about Shared library that compiled with Gcc=20 > for Solaris. >=20 > With above example code, >=20 > ---------- test1.h ----------------------------------------------- > class class1 { >=20 > public: > ~class1 (); >=20 > void func1 (); >=20 > }; > ---------- test1.cc ---------------------------------------------- > #include > #include "test1.h" >=20 > using namespace std; >=20 > void class1::func1 () { >=20 > throw runtime_error ("This is erro "); >=20 > } >=20 >=20 > class1::~class1 () { >=20 > cout << "Class1 destructor is called " << endl; >=20 > } > --------- main.cc ------------------------------------------------- > #include "test1.h" > #include >=20 > using namespace std; >=20 > class except_1 {}; >=20 > class class2 { >=20 > public: > ~class2 () { > cout << "Class2 destructor is called "<< endl; > } >=20 > void func1() { throw except_1 (); } >=20 >=20 > void func2 () { throw runtime_error ("Error from class2"); } >=20 > }; >=20 > int main () { >=20 > class2 test2; >=20 > try { > test2.func1(); > } > catch ( except_1& e ) { > cout << "Catch except1 " << endl; > } >=20 >=20 > try { > test2.func2(); > } > catch ( runtime_error& e ) { > cout << "Catch except2 " << e.what() << endl; > } >=20 > try { // This try block ignored (1) > class1 test; > test.func1(); > } > catch ( runtime_error& e ) { > cout << "Catch except2 "<< e.what () << endl; > } > } > ------------------------------------------------------------------- >=20 > When I create executable with Makefile1, the generated executable > is crashed with, >=20 >=20 > Catch except1 > Catch except2 Error from class2 > Abort <---- >=20 > It seems that try catch block (1) seems to ignored. >=20 > ---------- Makefile1 ---------------------------------------------- >=20 > SHARE_OBJ =3D test1.o >=20 >=20 > .cc.o : > g++ -g -fPIC -c -o $@ -save-temps $< >=20 >=20 > libshared.so: ${SHARE_OBJ} > /usr/ccs/bin/ld -G -o $@ ${SHARE_OBJ} >=20 > test: main.o libshared.so > g++ -v -o $@ $< -L. -L/usr/local/gcc/2.95.3/lib=20 > -lshared -lstdc++ >=20 > clean: > -/bin/rm *.o *.so >=20 > -------------------------------------------------------------- > --------- >=20 > But when I compiled with Makefile2, generated executable run without > any problems. >=20 > The only difference is when created shared library, in the=20 > failed case, > it directory called /usr/ccs/bin/ld ,but passed case it=20 > called /usr/ccs/bin/ld > through g++ compiler driver. >=20 > ( It seems that g++ called collect2 and collect2 called=20 > /usr/ccs/bin/ld) >=20 > 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 ) >=20 > Environemnt is > O.S : Solaris8 (Sparc) > Gcc : 2.95.3 >=20 >=20 > -------------------- Makefile2=20 > ---------------------------------------- > SHARE_OBJ =3D test1.o >=20 >=20 > .cc.o : > g++ -g -fPIC -c -o $@ -save-temps $< >=20 >=20 > libshared.so: ${SHARE_OBJ} > g++ -v -G -o $@ ${SHARE_OBJ} -lc >=20 > test: main.o libshared.so > g++ -v -o $@ $< -L. -L/usr/local/gcc/2.95.3/lib=20 > -lshared -lstdc++ >=20 > clean: > -/bin/rm *.o *.so >=20 > ---------------------------------------------------------------------- >=20 >=20 > Takeo Komiyama >=20 > -------------------------------------------------------------- > --------- > 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 > -------------------------------------------------------------- > --------- >=20 >=20