开发者

Does static library avoids name mangling issues?

开发者 https://www.devze.com 2023-03-13 01:29 出处:网络
I have a C++\\MFC application written in Visual Studio 2003 SP1 links to an external s开发者_如何学JAVAtatic library \"SomeExtStaticLib.lib\". I also include the header files provided with \"SomeExtSt

I have a C++\MFC application written in Visual Studio 2003 SP1 links to an external s开发者_如何学JAVAtatic library "SomeExtStaticLib.lib". I also include the header files provided with "SomeExtStaticLib.lib" to create the objects in my application.

SomeExtStaticLib.lib is a static library built with VC6.

Now, I am migrating my application to Visual Studio 2008.

I have very basic question.

Should I also migrate the "SomeExtStaticLib.lib" to VS2008 compiled one? When I tried to use this VC6 compiled "SomeExtStaticLib.lib" in my VC9 compiled application it did not give any linker errors. I was expecting at least some name mangling issues.

Are static libraries eliminating the name mangling issues?


The issue isn't one of static vs. dynamic linking, nor really of name mangling. The issue is one of binary compatibility for everything used in the interface. Thus, for example, unless I'm badly mistaken, the definition of std::string changed between VC6 and VC9, with a different layout. So if any of the code uses std::string, you'll have to recompile, or get strange and unexplicable errors at runtime.

In general, it's best to assume no binary compatibility as soon as different versions of the compiler, or even different compilation options are involved, unless the vendor guarantees otherwise. (Although some common sense is in order: you can freely mix options which only control warnings, for example. But beware of /Ds which cause added debugging code to be generated or not.)


If the application is unchanged it needs the same set of symbols from the library. And hence perhaps you can link to the library compiled with VC6.0. Name mangling is not the concern at all unless both the application and library are the same as the compatible(working) ones in VC6.0.

Should I also migrate the SomeExtStaticLib.lib to VS2008 compiled one?
There are compatibility problems between VC6.0 and visual 2008. So YES you should rebuild yor library with Visual 2008.

Just because you can link to the library as is doesn't mean it will work correctly.

Are static libraries eliminating the name mangling issues?
Not really. They are not doing anything special at all.


Static libraries have nothing to do with or without name mangling.... if your code is C++ there is mangling, and if its C (or extern "C" in C++) then there is no mangling. As long as the library and the code that link it agree, there's no problem to link in the library.

0

精彩评论

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