简体   繁体   English

Visual C ++ 2005的奇怪链接问题

[英]Strange linkage problem with Visual C++ 2005

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. 前提:我在Windows 7 x64上使用Visual c ++ 2005,并且我确定我的代码没有致命缺陷,因为在Linux下使用g ++可以很好地运行。

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. 在应用程序的链接阶段,我收到两个神秘的LNK2019错误。

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. 显然,在cpp文件中,我提供了具有完全相同签名的addAccel的实现。

When I try to link the application with the library, ALL the other member functions are found, except for addAccel. 当我尝试将应用程序与库链接时,找到所有其他成员函数,除了addAccel。

The linker searches for the symbol "?addAccel@Quark@@QAEXABV?$TemplateVec2@M@Atlax@@@Z" 链接器搜索符号“?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". 而在.lib文件中(我使用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. 像以前一样,所有其他方法都已正确链接,但未正确链接addQuark。

The linker searches for "?addQuark@Cluster@sulfur@@QAEPAVQuark@@W4Feature@2@MMMM@Z" 链接器搜索“?addQuark @ Cluster @ sulfur @@ QAEPAVQuark @@ W4Feature @ 2 @ MMMM @ Z”

but in the library there is "?addQuark@Cluster@sulfur@@QAEPAVQuark@2@W4Feature@2@MMMM@Z". 但是库中有“?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. 这次的区别是编译器搜索版本中的“ @”之间没有第一个“ 2”。

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. 这不是我第一次使用Visual Studio构建此应用程序,它始终与ok链接在一起,除了这次与最近的更改。

I don't have any clue, thank you in advance 我没有任何线索,请先谢谢

Where and how is the void addAccel(const Vec2 &a); void addAccel(const Vec2 &a); function implemented? 功能实现了吗? Are you sure that you are not missing Quark:: prefix on the implementation of the function? 您确定您不会在函数实现上缺少Quark::前缀吗?

Well, I've just solved the issue. 好吧,我已经解决了这个问题。 There where two erroneous forward declarations (outside of the namespace) of class Quark and class Cluster. 那里有Quark类和Cluster类的两个错误的前向声明(在命名空间之外)。 For some reason g++ was ok with that, while VC++ was right to complain about it. 出于某种原因,g ++可以接受,而VC ++可以抱怨。 Thank you anyway. 还是要谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM