I am trying to build a static library as a release others can use (and they should be able to use it whether they debug their own code or not). My library on the other hand should not contain any debug symbols or so. I only want to release the headers and the .lib file (no .dll or so).
The User of the lib should be able to use his runtime-environment and build flavor (debug or release) without any hassle.
Is this even possible with Visual Studio ?
[==> I already have read, that some users switch over to build this kind of lib with gcc]
I have tried several cases and I always get something like "_ITERATOR_DEBUG_LEVEL" conflicts or so. Static linking of the runtime libraries seems not the solution too, but what else ? Is it possible to switch off all references and let the project incorporating the library decide what runtime to use ?
Even if this question is similar to the follwing I haven't found the correct answer there: Pure static C Library (no dependency of MSVC C runtime) or here Microsoft Visual Studio ~ C/C Runtime Library ~ Static/dynamic linking
CodePudding user response:
The solution is as follows (as stated by @drescherjm and @Eljay):
You can build static libraries (.lib files) with VisualStudio (currently VS2019) that are usable within debug and release environments if only "C ABI" is used and exposed to the "outside" (the header file(s)).
"C ABI" does NOT mean, that no C functionality may be used, it means that no "std::*" functions/containers/etc. may be used.
Neither as function parameters nor as class members.
#ifndef LIB_STATIC_H__
#define LIB_STATIC_H__
#include <stdint.h>
class MyLib
{
public:
MyLib();
~MyLib();
uint64_t TestFunc(char* param, uint32_t x);
};
#endif
This will work, but this NOT:
#ifndef LIB_STATIC_H__
#define LIB_STATIC_H__
#include <stdint.h>
#include <string>
class MyLib
{
public:
MyLib();
~MyLib();
uint64_t TestFunc(char* param, uint32_t x);
private:
std::string m_MyString;
};
#endif