开发者

Strange linkage problem with Visual C++ 2005

开发者 https://www.devze.com 2023-01-09 03:27 出处:网络
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++ un

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


Where and how is the void addAccel(const Vec2 &a); function implemented? Are you sure that you are not missing Quark:: prefix on the implementation of the function?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号