DLL and compiler settings

Many articles and posts warn about compiler settings that can cause incompatibilities when linking and using DLLs.

If you use best practice when writing your C ++ DLL and export your functions using extern "C" and use only POD data types or stick to interface classes (pure virtual), what are the compiler options that may cause problems?

How do you know which compiler settings will cause problems? Will different compilers have different settings? Is there a list of available Visual C ++ compiler options?

+4
source share
1 answer

This is not a final list, but what I remember:

  • Linking to different versions, such as linking to the Visual C ++ debugging runtime in your main executable, and linking to the Visual C ++ version in the DLL that you import can also cause problems. (Code Generation -> Runtime Library)

  • Linking to different versions of the C ++ runtime (i.e., VC90 and VC100) is also impractical. (General tab โ†’ Platform Toolkit)

  • Remember the calls that the DLL uses (C / C ++ Advanced โ†’ Calling Convention tab)

  • When transferring structures between two modules, make sure that both modules have the same packaging (C / C ++ โ†’ Code Generation โ†’ Struct Member Alignment)

  • Not sure, but it sounds reasonable that they should have the same exception handling model (C / C ++ โ†’ Code Generation โ†’ Enable C ++ exceptions)

  • Same floating point model if you send floats to and from (C / C ++ โ†’ Code Generation โ†’ Floating Point Parameter)

  • Both modules have the same architecture, obviously (Intel x86, AMD x64, Itanium, ARM, etc.)

For the second part of the question here is the full documentation on all parameters of the compiler.

+6
source

Source: https://habr.com/ru/post/1468923/


All Articles