Visual C 的奇怪链接问题++ 2005年
请帮助我,我有一个奇怪的问题,我无法以任何方式解决。
前提:我在 windows 7 x64 上使用 Visual C++ 2005,并且我确信我的代码没有致命缺陷,因为在 Linux 下使用 g++ 它运行得很好。
我正在开发一个应用程序,它使用我也开发的静态库。
在应用程序的链接阶段,我收到两个神秘的 LNK2019 错误。
这是该库的一个类的标头:
namespace sulfur
{
class Quark
{
public:
... various methods
void addAccel(const Vec2 &a);
... various methods
private:
... various data
};
}
显然,在 cpp 文件中,我提供了具有完全相同签名的 addAccel 实现。
当我尝试将应用程序与库链接时,会找到除 addAccel 之外的所有其他成员函数。
链接器搜索符号“?addAccel@Quark@@QAEXABV?$TemplateVec2@M@Atlax@@@Z”,
而在.lib文件中有(我使用dumpbin找到的)“?addAccel@Quark@sulfur@@” QAEXABV?$TemplateVec2@M@Atlax@@@Z”。这里唯一的区别是链接器搜索没有命名空间部分的损坏名称,我不知道为什么。
我尝试更改方法的名称、位置、调用约定和签名,但无济于事,总是出现相同的错误。
第二个错误非常相似。我在库中有另一个标头:
namespace sulfur
{
class Cluster
{
...
Quark *addQuark(sulfur::Feature feat, float x, float y, float m=0.1f, float aF=0.01f);
...
};
}
并提供了正确的实现文件。和以前一样,所有其他方法都正确链接,但 addQuark 没有。
链接器搜索“?addQuark@Cluster@sulfur@@QAEPAVQuark@@W4Feature@2@MMMM@Z”,
但库中有“?addQuark@Cluster@sulfur@@QAEPAVQuark@2@W4Feature@2@MMMM@Z” ”。
这次的区别是编译器搜索的版本中“@”之间缺少第一个“2”。
这不是我第一次使用 Visual Studio 构建此应用程序,除了这次与最后一次更改之外,它始终链接正常。
我没有任何线索 先感谢您
please help me, I have a strange problem which i can't sort out in any way.
Premise: I'm using visual c++ 2005 on windows 7 x64, and I'm sure that my code isn't fatally flawed because with g++ under Linux it runs nicely.
I am developing an application which uses a static library also developed by me.
In the link phase of the application i get two mysterious LNK2019 errors.
This is the header of one of the classes of the library:
namespace sulfur
{
class Quark
{
public:
... various methods
void addAccel(const Vec2 &a);
... various methods
private:
... various data
};
}
Obviously in the cpp file i provide an implementation for addAccel with exactly the same signature.
When I try to link the application with the library, ALL the other member functions are found, except for addAccel.
The linker searches for the symbol "?addAccel@Quark@@QAEXABV?$TemplateVec2@M@Atlax@@@Z"
while in the .lib file there is (which i found using dumpbin) "?addAccel@Quark@sulfur@@QAEXABV?$TemplateVec2@M@Atlax@@@Z". The only difference here is that the linker searches for a mangled name without the namespace part and I don't know why.
I've tried to change name, position, calling convention and signature of the metod but to no avail, always getting the same error.
The second error is very similar. I have another header in the library:
namespace sulfur
{
class Cluster
{
...
Quark *addQuark(sulfur::Feature feat, float x, float y, float m=0.1f, float aF=0.01f);
...
};
}
and a correct implementation file is provided. Like before, all the other methods are linked properly, but not addQuark.
The linker searches for "?addQuark@Cluster@sulfur@@QAEPAVQuark@@W4Feature@2@MMMM@Z"
but in the library there is "?addQuark@Cluster@sulfur@@QAEPAVQuark@2@W4Feature@2@MMMM@Z".
This time the difference is the absence of the first '2' between the '@' in the version which the compiler searches for.
This isn't the first time that I build this application with visual studio and it has always linked ok except for this time with the last changes.
I don't have any clue,
thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
void addAccel(const Vec2 &a);
函数在哪里以及如何实现?您确定函数的实现中没有缺少Quark::
前缀吗?Where and how is the
void addAccel(const Vec2 &a);
function implemented? Are you sure that you are not missingQuark::
prefix on the implementation of the function?嗯,我刚刚解决了这个问题。
这里有两个错误的类 Quark 和类 Cluster 的前向声明(在命名空间之外)。出于某种原因,g++ 对此表示同意,而 VC++ 对此的抱怨是正确的。
不管怎样,谢谢你。
Well, I've just solved the issue.
There where two erroneous forward declarations (outside of the namespace) of class Quark and class Cluster. For some reason g++ was ok with that, while VC++ was right to complain about it.
Thank you anyway.