Search code examples
c++visual-studiolinkerinclude

identify equal named functions from different additional dependencies


I have a C++ project in Visual Studio where libs (oldVersion.lib, newVersion.lib) are added via project properties -> Linker -> Input -> Additional Dependencies.

Both libs contain the same function (e.g. foo()). The functions are included by their header files and called via ::foo().

The code itself does not show an error but at runtime it is not clear if foo() from oldVersion or newVersion is executed.

Is it possible to differentiate between same named functions from the two different .libs? (Like aliases in C#)

What I tried:

  • Wrapping external libraries in namespaces
    Not working because in line coollib_coolthing(howcool); it is not clear where howcool (which would be foo) comes from.

  • namespace newVersion{
    #inlcude "newVersion.h"
    }
    

    Here, the newVersion namespace is added to the information from the .h file but newVersion::foo() still executes the first foo it can find somewhere.


Solution

  • I am sorry for that I should provide a better plan rather than a complicated method.

    Here is the method: Just tell the linker that the symbols in a library are known by some other name and use that name. You need to make a def file and provide the name translation in the EXPORTS section. The process would be to make a def file for one of the libraries then use this def file to build a lib file and then link with that lib file.

    Also, you could refer to this link for more information about this method which is provided by Jim Monte.