Mail Archives: cygwin/2005/01/12/07:02:04
------=_20050112130122_33144
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
first of all, i want to apologize for cross-posing, but i think this
question is of interest for both lists.
now my problem:
i created a main program and a shared library, both written in c++, where
the source is parially taken from the "c++ dlopen mini howto".
find the sources in the attachments!
throwing an exception in the shared library results in a core dump of the
binary executable - but only for the cross-compiled version!
the native linux and cygwin compiled versions work.
so, could someone give me a hint, what's wrong with my cross-compiler?
my cross-compiler (verson 3.2.3) runs under linux and creates cygwin
executables.
thnx!
--
rainer hochreiter | web: www.hochreiter.at
lilienfelder str. 43 | e-mail: rainer AT hochreiter DOT at
a-3150 wilhelmsburg / austria | mobile: +43 664 2812175
------=_20050112130122_33144
Content-Type: application/octet-stream; name="configure.ac"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="configure.ac"
QUNfSU5JVChtYWluLmNwcCkKQUNfUFJFUkVRKDIuNTIpCkFNX0lOSVRfQVVU
T01BS0UoZGxsY3BwLCAwLjEuMCkKCkFDX0NBTk9OSUNBTF9CVUlMRApBQ19D
QU5PTklDQUxfSE9TVAoKQ1lHV0lOX1JPT1RfRElSPSIvb3B0L2N5Z3dpbi1j
cm9zcy1nY2MiCkNZR1dJTl9CSU5fRElSPSIkQ1lHV0lOX1JPT1RfRElSL2Jp
biIKQ1lHV0lOX0lOQ19ESVI9IiRDWUdXSU5fUk9PVF9ESVIvaTY4Ni1wYy1j
eWd3aW4vaW5jbHVkZSIKQ1lHV0lOX0xJQl9ESVI9IiRDWUdXSU5fUk9PVF9E
SVIvaTY4Ni1wYy1jeWd3aW4vbGliIgpBQ19TVUJTVChDWUdXSU5fQklOX0RJ
UikKQUNfU1VCU1QoQ1lHV0lOX0lOQ19ESVIpCkFDX1NVQlNUKENZR1dJTl9M
SUJfRElSKQoKQ0M9IiRDWUdXSU5fQklOX0RJUi9pNjg2LXBjLWN5Z3dpbi1n
Y2MiCkNYWD0iJENZR1dJTl9CSU5fRElSL2k2ODYtcGMtY3lnd2luLWcrKyIK
QVI9IiRDWUdXSU5fQklOX0RJUi9pNjg2LXBjLWN5Z3dpbi1hciIKTk09IiRD
WUdXSU5fQklOX0RJUi9pNjg2LXBjLWN5Z3dpbi1ubSIKUkFOTElCPSIkQ1lH
V0lOX0JJTl9ESVIvaTY4Ni1wYy1jeWd3aW4tcmFubGliIgpTVFJJUD0iJENZ
R1dJTl9CSU5fRElSL2k2ODYtcGMtY3lnd2luLXN0cmlwIgpETExUT09MPSIk
Q1lHV0lOX0JJTl9ESVIvaTY4Ni1wYy1jeWd3aW4tZGxsdG9vbCIKT0JKRFVN
UD0iJENZR1dJTl9CSU5fRElSL2k2ODYtcGMtY3lnd2luLW9iamR1bXAiCkFT
PSIkQ1lHV0lOX0JJTl9ESVIvaTY4Ni1wYy1jeWd3aW4tYXMiCkFDX1BBVEhf
UFJPRyhDUFAsIGNwcCwgJENZR1dJTl9CSU5fRElSL2k2ODYtcGMtY3lnd2lu
LWNwcCwgJENZR1dJTl9CSU5fRElSKQoKQUNfUFJPR19SQU5MSUIKQUNfUFJP
R19DQwpBQ19QUk9HX0NYWApBQ19QUk9HX0NQUAoKQUNfTElCVE9PTF9ETE9Q
RU4KQUNfUFJPR19MSUJUT09MCkFDX1NVQlNUKExJQlRPT0xfREVQUykKCkFD
X0hFQURFUl9TVERDCkFDX09VVFBVVChbTWFrZWZpbGVdKQo=
------=_20050112130122_33144
Content-Type: application/octet-stream; name="Makefile.am"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Makefile.am"
bm9pbnN0X0xUTElCUkFSSUVTCT0gbGliZXhjZXB0aW9uLmxhCmxpYmV4Y2Vw
dGlvbl9sYV9TT1VSQ0VTCT0gZXhjZXB0aW9uLmNwcApsaWJleGNlcHRpb25f
bGFfTERGTEFHUwk9IAoKbGliX0xUTElCUkFSSUVTCQk9IGxpYmNwcGRsbC5s
YQpsaWJjcHBkbGxfbGFfU09VUkNFUwk9IHRyaWFuZ2xlLmNwcApsaWJjcHBk
bGxfbGFfTERGTEFHUwk9IC12ZXJzaW9uLWluZm8gMTowOjEgLW5vLXVuZGVm
aW5lZApsaWJjcHBkbGxfbGFfTElCQURECT0gbGliZXhjZXB0aW9uLmxhCgpi
aW5fUFJPR1JBTVMJCT0gdXNlZGxsCnVzZWRsbF9TT1VSQ0VTCQk9IG1haW4u
Y3BwCnVzZWRsbF9MREFERAkJPSBsaWJleGNlcHRpb24ubGEK
------=_20050112130122_33144
Content-Type: text/x-c++; name="exception.cpp"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="exception.cpp"
#include "exception.hpp"
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
MyException::MyException(const std::string& reason) throw()
: reason_(reason)
{
cout << "create MyException with reason: " << reason_ << endl;
}
MyException::~MyException() throw() { }
const char* MyException::what() const throw() {
return reason_.c_str();
}
------=_20050112130122_33144
Content-Type: text/x-c-header; name="exception.hpp"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="exception.hpp"
#ifndef __CLASS_EXCEPTION_HPP__
#define __CLASS_EXCEPTION_HPP__
#include <string>
#include <stdexcept>
class MyException : public std::exception {
public:
MyException(const std::string& reason) throw();
virtual ~MyException() throw();
virtual const char* what() const throw();
private:
const std::string reason_;
};
#endif // __CLASS_EXCEPTION_HPP__
------=_20050112130122_33144
Content-Type: text/x-c++; name="main.cpp"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="main.cpp"
#include "polygon.hpp"
#include "exception.hpp"
#include <dlfcn.h>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
int main () {
cout << "C++ dlopen demo" << endl << endl;
try {
// load the library
#if defined(__CYGWIN__)
const std::string libname("cygcppdll-0.dll");
#else
const std::string libname("libcppdll.so");
#endif
cout << "Opening library " << libname << "..." << endl;
void* handle = dlopen(libname.c_str(), RTLD_LAZY);
if(handle == 0) {
cout << "dlopen() failed: " << dlerror() << endl;
return 1;
}
// load the symbols
cout << "Load symbols from library..." << endl;
create_t* create_triangle = (create_t*) dlsym(handle, "create");
destroy_t* destroy_triangle = (destroy_t*) dlsym(handle, "destroy");
if(create_triangle == 0 || destroy_triangle == 0) {
cout << "dlsym() failed: " << dlerror() << endl;
return 1;
}
// create instance of class
cout << "Create class instance..." << endl;
polygon* poly = create_triangle();
// use class
cout << "Use class..." << endl;
poly->set_side_len(7);
cout << "poly area is " << poly->area() << endl;
cout << "Create exception in class..." << endl;
poly->crash("throw exception");
// destroy class
cout << "Destroy class..." << endl;
destroy_triangle(poly);
// close library
cout << "Close library..." << endl;
dlclose(handle);
return 0;
} catch (const MyException& e) {
cout << "Caught MpException: " << e.what() << endl;
return 1;
} catch (const std::exception& e) {
cout << "Caught std::exception: " << e.what() << endl;
return 1;
} catch (...) {
cout << "Caught unknown exception" << endl;
return 1;
}
}
------=_20050112130122_33144
Content-Type: text/x-c-header; name="polygon.hpp"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="polygon.hpp"
#ifndef __CLASS_POLYGON_HPP__
#define __CLASS_POLYGON_HPP__
#include <string>
class polygon {
public:
polygon() : side_length_(0) { }
void set_side_len(double side_length) {
side_length_ = side_length;
}
virtual double area() const = 0;
virtual double crash(const std::string& reason) const = 0;
protected:
double side_length_;
private:
};
typedef polygon* create_t();
typedef void destroy_t(polygon*);
#endif // __CLASS_POLYGON_HPP__
------=_20050112130122_33144
Content-Type: text/x-c++; name="triangle.cpp"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="triangle.cpp"
#include "exception.hpp"
#include "polygon.hpp"
#include <cmath>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
class triangle : public polygon {
public:
virtual double area() const {
cout << "area()..." << endl;
return side_length_ * side_length_ * sqrt(3) / 2;
cout << "area()...done." << endl;
}
virtual double crash(const std::string& reason) const {
cout << "crash()...." << endl;
throw MyException(reason);
// NEVER REACH THIS
cout << "crash()...done." << endl;
}
};
// class factories
extern "C" polygon* create() {
return new triangle;
}
extern "C" void destroy(polygon* p) {
delete p;
}
------=_20050112130122_33144
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------=_20050112130122_33144--
- Raw text -