step
step

Reputation: 93

Compiling a C++ library both as a static lib and dynamic dll with VS

I need to compile an existing C++ library both as a lib and a dll, and then use the static and dynamic libraries in different applications. I use VS2010.

What I can't do is to edit all the header files in order to add __declspec(dllexport) instructions to export, as the library must be kept as it is.

Under Mac I was able to compile and use a dylib without problems, but I know that VS is lacking in this regard.

In VS is it feasible to compile a static lib first and then a dll in order to have functions "exported" (i.e. linkable from an application at compilation time)? In other words, can I use the static lib as if was the export lib generated with __declspec(dllexport)? Are there better workarounds?

Upvotes: 3

Views: 2151

Answers (1)

Sergey Podobry
Sergey Podobry

Reputation: 7189

I need to compile an existing C++ library both as a lib and a dll, and then use the static and dynamic libraries in different applications. I use VS2010.

Create configurations for that. For example Release LIB, Release DLL, etc.

What I can't do is to edit all the header files in order to add __declspec(dllexport) instructions to export, as the library must be kept as it is.

Simply add module definition file (*.def) with a list of exported functions.

In other words, can I use the static lib as if was the export lib generated with __declspec(dllexport)?

No, those libs are different. When you build a DLL you get a binary and a lib files.

Upvotes: 2

Related Questions