I am playing with creating exceptions in C++ and I have the following test code:
#include <iostream>
#include <stdexcept>
#include <new>
using namespace std;
class Myerror : public runtime_error {
private:
string errmsg;
public:
Myerror(const string &message): runtime_error(message) { }
};
int main(int argc, char *argv[]) {
throw Myerror("wassup?");
}
I am compiling this with:
icpc -std=c++11 -O3 -m64
Upon compilation I am getting this ld warning:
ld: warning: direct access in _main to global weak symbol __ZN7MyerrorD1Ev means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
I do not get this warning if I use g++ instead of icpc.
I have not been able to understand what this means, and what is causing this warning to generate. The code runs as expected, however I'd like to undesratand what is happening.
Try the following:
#include <iostream>
#include <stdexcept>
#include <new>
using namespace std;
class Myerror : public runtime_error {
public:
Myerror(const string &message) throw(): runtime_error(message) { }
virtual ~Myerror() throw() {}
};
int main(int argc, char *argv[]) {
throw Myerror("wassup?");
}
Why do you need unused string errmsg?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With