I've worked with a couple of Visual C++ compilers (VC97, VC2005, VC2008) and I haven't really found a clearcut way of adding external libraries to my builds. I come from a Java background, and in Java libraries are everything!
我曾经使用过几个Visual C ++编译器(VC97,VC2005,VC2008),我还没有真正找到一种向我的构建添加外部库的清晰方法。我来自Java背景,在Java库中是一切!
I understand from compiling open-source projects on my Linux box that all the source code for the library seems to need to be included, with the exception of those .so files.
Also I've heard of the .lib static libraries and .dll dynamic libraries, but I'm still not entirely sure how to add them to a build and make them work. How does one go about this?
In I think you might be asking the mechanics of how to add a lib to a project/solution in the IDEs...
In 2003, 2005 and 2008 it is something similar to:
from the solution explorer - right click on the project select properties (typically last one) I usually select all configurations at the top... Linker Input
从解决方案资源管理器 - 右键单击项目选择属性(通常是最后一个)我通常选择顶部的所有配置...链接器输入
Additional dependencies go in there
I wish I could do a screen capture for this.
In VC6 it is different bear with me as this is all from memory
project settings or properties and then go to the linker tab and find where the libs can be added.
Please excuse the haphazard nature of this post. I think that is what you want though.
Libraries in C++ are also considered helpful, but the way you integrate them is different to Java because the compiler only has to see the interface of the library, which is usually declared in header files. In Java, the compiler will have to inspect the actual libraries because Java doesn't have this distinction between an externally visible header file and the generated object code providing the implementation.
What you normally do is build the libraries separately, once, and put the generated lib/dll files plus the header files into a place that projects requiring the library can access. A common idiom is to put the header files into
include, the static libraries into
lib and the dynamic libraries into
bin subdirectories for your compiled library.
您通常做的是单独构建库,一次,并将生成的lib / dll文件和头文件放入需要库可以访问的项目的位置。一个常见的习惯用法是将头文件放入include,将静态库放入lib,将动态库放入bin子目录中,用于编译库。
The reason you have found that most C++ libraries are provided in source code form and not in precompiled form is that every C++ compiler has a certain freedom as to how to mangle symbol names etc and the resulting object code isn't portable across compilers, let alone operating systems. So shipping the compiled code doesn't make sense for a lot of applications. You'll occasionally find it with closed-source C++ libraries on Windows (C libraries are an entirely different matter), but then the vendor will have to provide a compiled version for each and every build type (Release, Debug, 32 bit, 64 bit etc) and target compiler (various versions of Visual Studio require different binaries, then there is Borland and a bunch of other compilers) and it quickly becomes a nightmare to support...
您发现大多数C ++库以源代码形式提供而不是以预编译形式提供的原因是每个C ++编译器都有一定的自由来如何破坏符号名称等,并且生成的对象代码不能跨编译器移植,让单独的操作系统。因此,运送已编译的代码对于许多应用程序来说没有意义。您偶尔会在Windows上使用闭源C ++库找到它(C库是完全不同的事情),但供应商必须为每种构建类型提供编译版本(Release,Debug,32 bit,64比特等)和目标编译器(各种版本的Visual Studio需要不同的二进制文件,然后是Borland和一堆其他编译器),它很快成为支持的噩梦......
When you take a library and build it as a dynamic library on Windows (ie, a DLL), the compiler/linker will normally generate a static 'import' library for it (same name, just with a .lib extension). When you link your project against the dynamic library, you specify the .lib file as a library dependency. Linking your application against said import library allows the linker to record the dependency on the .dll file and also which symbols it should expect the library to provide.
Making them work - in the sense of your program finding them on Windows - usually requires that the .dll file is either in the same directory as the executable or accessible via the 'PATH' environment variable and its equivalent in Visual C++.
使它们工作 - 在程序中在Windows上找到它们 - 通常要求.dll文件与可执行文件位于同一目录中,或者通过'PATH'环境变量及其在Visual C ++中的等效文件可访问。
Ok. typically you don't want to load dynamic libraries by hand, but if you do, look into LoadLibrary. you then have to call other functions to get function pointer addresses and so forth. Typically how it works, is even .dll files have .lib files for them.. so when they are needed, they just automatically load.
how you specifiy .lib files /static libraries is under Properties/Linker/Input->Additional Dependencies. in the gui.
如何指定.lib文件/静态库位于Properties / Linker / Input-> Additional Dependencies下。在gui。
if you are scripting this.. well. you just specifiy the .lib files on the command line at link time.
For adding libraries, this is very simple (if that's what you mean) Project -> properties -> configure properties -> Linker -> Input -> additional libraries. Go stand on one of the libraries in there and press enter. You freed up a space to add a library, eay as pie :)
对于添加库,这非常简单(如果这就是你的意思)项目 - >属性 - >配置属性 - >链接器 - >输入 - >其他库。站在其中一个库上,按回车键。你释放了一个空间来添加一个库,就像馅饼一样:)
For adding external libraries or library directories in a VC++ project follow these steps:
1- Go to your project properties (that can be done by right clicking on the project in your solution)
2- Select 'Linker' > 'General' > Additional Library Directories
3- Click on the empty bar in front of 'Additional Library Directories' and VS allows you to add directories to its default ones into which it searches for the required libraries.
What do you mean "add them to a build"?
In VC, within a solution, you can have a project whose output is a library (static or dynamic) and then another project that depends upon the output and uses it (ie, links to it).
In our code base, we typically have a separate solution for each library or set of libraries and then link them into target projects. Most of our target projects are managed assemblies - those that need unmanaged functionality are usually written in managed C++ or C++/CLI and link in unmanaged static libraries. We've found that this has been the easiest to maintain since the unmanaged libraries change the least.
在我们的代码库中,我们通常为每个库或一组库提供单独的解决方案,然后将它们链接到目标项目中。我们的大多数目标项目都是托管程序集 - 那些需要非托管功能的程序通常用托管C ++或C ++ / CLI编写,并链接到非托管静态库中。我们发现这是最容易维护的,因为非托管库的变化最小。