2

I am developing a C++ library that I want to pass on to my team. The library has just one class with a bunch of methods.

So, I have developed the class definition file (X.cpp) and a corresponding class declaration file (X.h).

Here are my questions --

  1. In Visual Studio 2005, whats is the most straight forward way to build this library as a DLL, such that I get the following files: X.lib : which I can pass to my team so they can link against my library X.dll : which I can pass to my team for run-time

  2. Instead of a DLL, should I rather be going the static library way ?? If so, how do I go about doing this in Visual Studio 2005 & will this give me a X.lib file that I can pass on to my team ?

Any explanations or references are very welcome.

Thank you very much.

4

4 回答 4

2

The easiest way to build a DLL, is New->Project->Win32 Console Application. Then on the dialog select DLL and select "Exports Symbols". This will synthesize a dll with a .h, and .cpp file which demonstrate how to export your classes. You can get rid of this .h/.cpp but first import your class add the appropriate #ifndef statements. Now as far as DLL versus Static library if its a single small class, that doesn't change particularly often you might be better off with a static library, its simple, its concise, it doesn't add another dependency which needs to be shipped with your product. A DLL is nice if the code in the .cpp file changes often (ie. the function implementations) because you can just swap in the new DLL.

于 2009-07-10T05:07:26.327 回答
1

From your description, it looks like you already have a Visual C++ project (correct me if I'm wrong). If so, when you go into project properties, under "General" you can find "Configuration Type" - switch it to "Static library" or "Dynamic library" as needed.

If you choose "Static library", then you will just get a .lib file that can be immediately used.

If you choose "Dynamic library", and you export any functions from your DLL (e.g. by marking them with __declspec(dllexport)), an export .lib will be generated automatically.

It's hard to tell which option is preferable without knowing the specifics of what you're doing. In general, I'd recommend defaulting to static libraries, because it's usually good enough, and there are more traps when dealing with DLLs (especially ones that export C++ symbols).

于 2009-07-10T05:05:54.800 回答
1

我认为,在大多数情况下,dll 是比静态库更好的选择,因为当您分发库的新版本时,您的团队不必重新编译他们的代码。

于 2009-07-10T10:03:36.650 回答
0

有时我也为此苦苦挣扎..因为我找不到难以捉摸的设置在 C++ 项目属性中的位置..所以我决定把它记下来作为我自己的理智作为博客文章

高温高压

于 2009-07-10T07:12:06.120 回答