Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a project to build that should run on two different versions of same software.
Ex:
Dependencies: file.h and file.lib are present in Software v1.0 and Software v2.0.
funtion1( int a, int b, int c); is defined in Software v1.0
funtion1( int a, int c); is defined in Software v2.0

I want the project to build by picking the right version of the file for compiling respective functions in the code.

Issue faced: In project options, I set the library and include path of file.h and file.lib.
It will pick the wrong version of the file for the funtions (because, selection is based on precedence)

Please suggest me a way by which i should be able to build the project.
I am using static libraries only for this project.

Regards
Draj
Posted

Hi, Draj!

If you can, I'd suggest the use of namespaces, and relative paths.

C++
namespace prod1
{
#include "../prod1/file.h"
}
namespace prod2
{
#include "../prod2/file.h"
}

int main(int argc, char **argv)
{
    prod1::function1(1, 2, 3);
    prod2::function1(4, 5);
}

If the .LIB files conflict, this solution may not help you: that depends on your code.
You can wrap the .lib files in your own source:

C++
// a.h
int Function1V1(int a, int b, int c);

// a.cpp
#include "../v1/file.h"
#pragma comment( lib, "../v1/file.lib" ) 
int Function1V1(int a, int b, int c)
{
    return funtion1(a, b, c);
}

// b.h
int Function1V2(int a, int b);

// b.cpp
#include "../v2/file.h"
#pragma comment( lib, "../v2/file.lib" ) 

int Function1V2(int a, int b)
{
    return funtion1(a, b);
}



Otherwise, assuming each of these products provides a DLL and not only a LIB, you'll have to use late binding (LoadLibrary() and GetProcAddress()).

If you only have static libraries, you can wrap each of them in a DLL of your own, renaming the encapsulated functions, and refer to your own DLLs in your program.

See also How to build an image (DLL/EXE) when two of its included libraries have the same symbol (say function/variable) using VC++[^]

Hope this helps,
Pablo.
 
Share this answer
 
Comments
RedUnited 2-Jun-12 4:42am    
I used LoadLibrary() and GetProcAddress()and it worked well.
Sorry for late reply.
Thanks lot! :)
You may add additional project configurations. Assuming you have configurations for debug and release builds of version 1, create copies of them and indicate version 2 in the names. Then you can use different include and library directories or add link against different libraries.

For all configurations, you should also add an additional definition for the version (command line option). This definition can be used in the source to compile version depend blocks or exclude them:
C++
#ifndef MY_APP_VERSION
#error MY_APP_VERSION not defined
#endif

// Include version specific header files
//  and link against version specific libraries
#if MY_APP_VERSION == 1
#include ".\v1.file.h"
#pragma comment(lib, ".\v1\my.lib")
#else
#include ".\v2.file.h"
#pragma comment(lib, ".\v2\my.lib")
#endif

// Call version specific function
#if MY_APP_VERSION == 1
function1(a, b, c);
#else
function1(a, b);
#endif
 
Share this answer
 
Comments
RedUnited 2-Jun-12 4:43am    
I used LoadLibrary() and GetProcAddress()and it worked well.
Thanks a lot for your inputs :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900