我收到虚拟析构函数引起的链接器警告。我的环境是KEIL编译器v6.5(clang)。
Warning: L6439W: Multiply defined Global Symbol __clang_call_terminate defined in invalid_group(new.cpp.o) rejected in favor of Symbol defined in .text.__clang_call_terminate(cxa_handlers.cpp.o).
我将虚拟析构函数添加到接口后立即收到此警告。例如:
class IInterface {
virtual ~IInterface(){}
virtual void doSomething() const = 0;
}
一旦我实现了这个接口的一个派生类,我就会得到上面提到的警告。一旦我删除虚拟析构函数,警告就会消失。
我尝试了很多东西,找出原因,但没有成功......
有人知道如何修复此警告吗?
谢谢!
编辑:抛出此警告的完整示例:
class IInterface {
public:
virtual ~IInterface();
virtual void doSomething() = 0;
};
IInterface::~IInterface() {
}
class SomeClass : public IInterface {
public:
virtual void doSomething();
};
void SomeClass::doSomething() {
}
int main() {
}
答案 0 :(得分:3)
我询问了ARM的支持并得到了这个警告是虚假的信息。所以它似乎是当前ARM clang编译器工具链实现的一个问题。
尽管如此,感谢大家对此主题的回应。
答案 1 :(得分:2)
如果在标题中定义函数,则每次将其包含在文件中时都会发出该函数。要消除这种变暖,你需要在声明之外定义你的方法
//This program calculates the roots of a quadratic equation.
#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main()
{
double a, b, c, root1, root2, disc, imaginarypart, realpart;
ofstream output ("E:result5.dat");
cout<< " This program calculates the roots of a quadratic equation. ";
cout << " ax^2 + bx + c = 0\n\n";
cout << "enter values for a, b, and c.";
cin >> a;
cin >> b;
cin >> c;
disc = (pow(b,2) -4*a*c);
if ( a == 0.0 && b == 0.0)
cout << "the equation has no real roots.";
else if ( a == 0.0 )
cout << " The equation is linear and has a single root x = " << -c/b <<endl;
else
{
if (disc > 0.0 )
{
root1 = (-b +sqrt((b*b) -4*a*c))/2*a;
root2 = (-b -sqrt((b*b) -4*a*c))/2*a;
cout << "The too roots are real and are X1 = " << root1 << " and X2 = " << root2 << endl;
}
else if (disc == 0.0)
{
cout<< "both roots are the same and are equal to " << -b/(2*a) << endl;
}
else
{
realpart = -b/(2*a);
imaginarypart = sqrt(-disc)/(2*a);
cout << " The roots are imaginary = " << endl;
cout << "x1 =" << realpart << "+" << imaginarypart << "i" << endl;
cout << "x2 =" << realpart << "-" << imaginarypart << "i" << endl;
}
system ("pause");
}
return 0;
}
答案 2 :(得分:0)
如前所述,这是一个链接器错误,已在ARM Compiler v6.11(10/25/2018)中修复。
发行说明:
[SDCOMP-30157]在某些情况下,从COMDAT ELF节组中丢弃节后,链接器可能会错误地报告警告:L6439W:为支持在()中定义的符号而拒绝了invalid_group()中定义的乘法定义的全局符号。此问题已解决。