From: komiyama <komiyama@sddc.sps.mot.com>
To: gcc-help@gcc.gnu.org
Subject: Question about shared library for Solaris
Date: Tue, 20 Apr 2004 06:38:00 -0000 [thread overview]
Message-ID: <4084C567.2000701@sddc.sps.mot.com> (raw)
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
-----------------------------------------------------------------------
next reply other threads:[~2004-04-20 6:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-20 6:38 komiyama [this message]
2004-04-20 9:06 Lev Assinovsky
2004-04-20 16:46 lrtaylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4084C567.2000701@sddc.sps.mot.com \
--to=komiyama@sddc.sps.mot.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).