c++异常和ld符号警告
C++ exception and ld symbol warning
我正在玩c++中创建异常,我有以下测试代码:
#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?");
}
我正在编译这个:
icpc -std=c++11 -O3 -m64
在编译时,我得到这个旧警告:
ld: warning:直接访问_main中的全局弱符号__ZN7MyerrorD1Ev意味着弱符号不能在运行时被覆盖。这可能是由于不同的翻译单位使用不同的可见性设置编译。
如果我使用g++而不是icpc,则不会得到此警告。
我一直无法理解这意味着什么,以及是什么导致了这个警告的产生。代码按预期运行,但是我想理解正在发生的事情。
尝试如下:
#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?");
}
为什么需要未使用的字符串errmsg?
相关文章:
- 获取隐式转换溢出从无符号到已签名的警告
- 将无符号转换为复杂<int>原因符号转换警告
- 如何解决隐式转换丢失整数精度:'size_t'(又名"无符号长")到'int'警告?
- Clang 给了我符号更改的警告,但代码仍然产生正确的输出
- 与 string.size() 比较时 int 的符号性显示警告
- 符号可见性和 gcc 警告
- C++ 如何禁用具有不同符号变量比较的特定行的编译器警告?
- 是否有 GCC 警告,用于使用 C 库中的符号而不是通过命名空间 std?
- C++ 斯特劳斯特鲁普的"std_lib_facilities.h"字符串结构 – 警告:无符号表达式的比较
- 即使启用了 Wextra,gcc 也不会给出将无符号整数< 0 进行比较的警告
- 如何禁用特定符号的 Visual Studio 警告
- g++ 在不使用 -Wconvert 的情况下将 double/float 转换为无符号整数时发出警告
- -在无符号字符上使用运算符 <<= 时的转换警告
- 当将负文字作为无符号参数传递时,可以g++警告
- 警告 C4018:">=":VSC++ 2010 中的有符号/无符号不匹配
- 严格的混叠警告,创建对无符号字符数组 + 偏移量的uint32_t引用
- 警告:有符号和无符号整数表达式之间的比较
- 断言(true)警告有符号/无符号不匹配
- 警告 1 警告 C4244:"参数":从"time_t"转换为"无符号 int",可能会丢失数据以及其他错误
- c++异常和ld符号警告