0

In MSVC it's possible to write:

// in Lib.h
#if USE_OLD_LIB

    #pragma comment(lib, "old_lib.lib")
    #include "old_lib.h"

#else

    #pragma comment(lib, "new_lib.lib")
    #include "new_lib.h"

#endif

How can I do this without having the pragma comment support in GCC?

Edit: I know it's possible to use a make file, but the USE_OLD_LIB conditional macro is connected to some logic inside another library like the following:

// in Lib2.h
#if OBJ_SIZE > 20
#define USE_OLD_LIB
#endif

So, it would be a hassle to use a make file for it.

5
  • 1
    How are you building with gcc? If you are using a makefile then you can set the define on the command line and have the makefile conditionally link in the appropriate lib.
    – kaylum
    Commented Jun 20, 2021 at 4:26
  • I know it's possible to use a makefile, the problem is the USE_OLD_LIB is connected to some logic in another library. like the following #if OBJ_SIZE > 20 #define USE_OLD_LIB #endif
    – modanashar
    Commented Jun 20, 2021 at 4:29
  • 1
    You should update your question with all the relevant facts and constraints.
    – kaylum
    Commented Jun 20, 2021 at 4:31
  • Is this impossible to do with GCC? Why is nobody answering this question?
    – modanashar
    Commented Jun 22, 2021 at 3:21
  • 1
    I'll say it - it is not possible with gcc.
    – kaylum
    Commented Jun 22, 2021 at 3:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.