Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 code/library in non C++11 program

Assume that I compile the code in C++11 (I'll use Lambdas) to ".o" or library ".a". And I have a program, where I will include previous library and header file, that I can't compile with C++11, but old one ( C++98 ). Will it compile and work fine?

like image 880
WaciX Avatar asked Feb 16 '23 15:02

WaciX


1 Answers

It will work fine if:

  1. the (public) header doesn't use any C++11 features
  2. the ABI hasn't changed
    • consult your platform/compiler on this one
  3. no common dependency has changed
    • as per the GCC document linked by Vaughn Cato, this includes the standard library. Anything that generates different code or object layouts when compiled with C++11, and is used by both library and client may be a problem ... even if it isn't used in the interface itself.

If point 3 is your only issue, you may be able to get around it by compiling a dynamic library (depending on platform a .so, or a .dynlib, or a DLL as Adrian suggests) with all dependencies statically linked internally and not exported. It's a bit hairy though.

like image 187
Useless Avatar answered Feb 28 '23 00:02

Useless