- 浏览: 204980 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
xiegqooo:
fbb_11 写道如果以前都正常,而突然不正常了,正常的思路应 ...
思考才能有效的解决问题----<WEB应用在捕捉异常并处理时,请不要使用System.exit(1)!!!! > -
ilotuo:
Nice! Thank for sharing your ex ...
Ogre xcode build error: Reference to 'FileInfo' is ambiguous -
Stark_Summer:
赞 就是感觉过于概念了。还是不能很明白
ANSI和Unicode中的汉字编码 (转) -
landerson:
旧版的ANTTASK.JAR与新版的ANT-TASK.JAR ...
ant 优化android 项目编译第二波,simple编译项目只需1分钟 -
luopenger:
taskdef com.android.ant.SetupTa ...
使用ant优化android项目编译速度,提高工作效率
A library is a package of code that is meant to be reused by many programs. Typically, a C++ library comes in two pieces: 1) A header file that defines the functionality the library is exposing (offering) to the programs using it. Some libraries may be split into multiple files and/or have multiple header files. Libraries are precompiled for several reasons. First, since libraries rarely change, they do not need to be recompiled often. It would be a waste of time to recompile the library every time you wrote a program that used them. Second, because precompiled objects are in machine language, it prevents people from accessing or changing the source code, which is important to businesses or people who don’t want to make their source code available for intellectual property reasons. There are two types of libraries: static libraries and dynamic libraries. A static library (also known as an archive) consists of routines that are compiled and linked directly into your program. When you compile a program that uses a static library, all the functionality of the static library becomes part of your executable. On Windows, static libraries typically have a .lib extension, whereas on linux, static libraries typically have an .a (archive) extension. One advantage of static libraries is that you only have to distribute the executable in order for users to run your program. Because the library becomes part of your program, this ensures that the right version of the library is always used with your program. Also, because static libraries become part of your program, you can use them just like functionality you’ve written for your own program. On the downside, because a copy of the library becomes part of every executable that uses it, this can cause a lot of wasted space. Static libraries also can not be upgraded easy — to update the library, the entire executable needs to be replaced. A dynamic library (also called a shared library) consists of routines that are loaded into your application at run time. When you compile a program that uses a dynamic library, the library does not become part of your executable — it remains as a separate unit. On Windows, dynamic libraries typically have a .dll (dynamic link library) extension, whereas on Linux, dynamic libraries typically have a .so (shared object) extension. One advantage of dynamic libraries is that many programs can share one copy, which saves space. Perhaps a bigger advantage is that the dynamic library can be upgraded to a newer version without replacing all of the executables that use it. Because dynamic libraries are not linked into your program, programs using dynamic libraries must explicitly load and interface with the dynamic library. This mechanisms can be confusing, and makes interfacing with a dynamic library awkward. To make dynamic libraries easier to use, an import library can be used. An import library is a library that automates the process of loading and using a dynamic library. On Windows, this is typically done via a small static library (.lib) of the same name as the dynamic library (.dll). The static library is linked into the program at compile time, and then the functionality of the dynamic library can effectively be used as if it were a static library. On Linux, the shared object (.so) file doubles as both a dynamic library and an import library. Installing and using libraries Now that you know about the different kinds of libraries, let’s talk about how to actually use libraries in your program. Installing a library in C++ typically involves 4 steps: 1) Acquire the library. The best option is to download a precompiled package for your operating system (if it exists) so you do not have to compile the library yourself. If there is not one provided for your operating system, you will have to download a source-code-only package and compile it yourself (which is outside of the scope of this lesson). On Windows, libraries are typically distributed as .zip files. On Linux, libraries are typically distributed as packages (eg. .RPM). Your package manager may have some of the more popular libraries (eg. SDL) listed already for easy installation, so check there first. 2) Install the library. On Linux, this typically involves invoking the package manager and letting it do all the work. On Windows, this typically involves unzipping the library to a directory of your choice. We recommend keeping all your libraries in one location for easy access. For example, use a directory called C:\Libs, and put each library in it’s own subdirectory. 3) Make sure the compiler knows where to look for the header file(s) for the library. On Windows, typically this is the \include subdirectory of the directory you installed the library files to (eg. if you installed your library to C:\libs\SDL-1.2.11, the header files are probably in C:\libs\SDL-1.2.11\include). On Linux, libraries are typically installed to /usr/include, which should already be part of your include file search path. However, if the files are installed elsewhere, you will have to tell the compiler where to find them. 4) Tell the linker where to look for the library file(s) for the library. As with step 3, this typically involves adding a directory to the list of places the linker looks for libraries. On Windows, this is typically the /lib subdirectory of the directory you installed the library files to. On Linux, libraries are typically installed to /usr/lib, which should already be a part of your library search path. Once the library is installed and the IDE knows where to look for it, the following 3 steps typically need to be performed for each project that wants to uses the library: 5) If using static libraries or import libraries, tell the linker which library files to link. 6) #include the library’s header file(s) in your program. This tells the compiler about all of the functionality the library is offering so that your program will compile properly. 7) If using dynamic libraries, make sure the program know where to find them. Under Linux, libraries are typically installed to /usr/lib, which is in the default search path. On Windows, the default search path includes the directory the program is run from, directories set by calling SetDllDirectory(), the Windows, System, and System32 directories, and directories in the PATH environment variable. The easiest way to use a .dll to copy the .dll to the location of the executable. Since you’ll typically distribute the .dll with your executable, it makes sense to keep them together anyway. Steps 3-5 involve configuring your IDE — fortunately, almost all IDEs work the same way when it comes to doing these things. Unfortunately, because each IDE has a different interface, the most difficult part of this process is simply locating where the proper place to perform each of these steps is. Consequently, in the next few lessons in this section, we’ll cover how to do all of these steps for both Visual Studio Express 2005 and Code::Blocks. If you are using another IDE, read both — by the time you’re done, you should have enough information to do the same with your own IDE with a little searching. http://www.learncpp.com/cpp-tutorial/a1-static-and-dynamic-libraries/
2) A precompiled binary that contains the implementation of that functionality pre-compiled into machine language.
发表评论
-
Ogre xcode build error: Reference to 'FileInfo' is ambiguous
2013-12-07 15:59 2145When update Ogre source to the ... -
C++ Header File Include Patterns
2012-08-01 16:04 875http://www.eventhelix.com/r ... -
cmake command
2012-02-27 15:27 992http://www.cmake.org/cmake/help ... -
CMAKE
2012-02-27 13:00 857http://www.cs.swarthmore.edu/~a ... -
MakeFile
2012-02-27 13:00 564http://web.cs.swarthmore.edu/~n ... -
LUA tutorial
2012-02-27 13:00 652http://lua-users.org/wiki/Tutor ... -
Robust Design Techniques for C Programs
2012-01-16 11:03 621http://www.freetype.org/david/r ... -
GDB调试精粹及使用实例
2012-01-09 00:58 727一:列文件清单 1 ... -
gdb cannot exec /bin/sh on android local terminal
2012-01-08 23:52 1454http://letsgoustc.spaces.liv ... -
GCC-makefile写法
2012-01-06 17:54 807http://liudefang111.blog.163.co ... -
gcc 编译多个文件
2012-01-06 17:51 995一. 常用编译命令选 ... -
gcc编译选项
2012-01-06 17:49 1843转载自http://blogold.chinaunix. ... -
c语言分配内存空间
2011-12-25 17:52 1192有人给对齐原则做过总 ... -
C tutorial pointer to pointer
2011-12-15 23:54 681http://www.eskimo.com/~scs/ccla ...
相关推荐
If both static and dynamic libraries are found it will by default pick the static library. If you switch on the advanced options in CMake you may overrule this setting by manually changing the ...
在动态库(dynamic libraries)和静态库(static libraries)使用模板(template)
Microsoft Visual C ++对静态和动态库的简单介绍。
给大家介绍一下在动态库(dynamic libraries)和静态库(static libraries)使用模板(template)的用法和解决方案。
Java libraries for static and dynamic program analysis
Topics covered include: compiling C and C++ programs using header files and libraries, warning options, use of the preprocessor, static and dynamic linking, debugging, optimization, platform-specific ...
THIS CHAPTER SHOWS YOU HOW TO PERFORM THE ...”pay careful attention to Section 2.3,“Writing and Using Libraries,”for information about static versus dynamic linking that you might not already know.
This book is for people who wish to learn how to create effective and dynamic websites. This may include webmasters or graphic designers who are already creating static websites but wish to take their...
Author Kyran Dale teaches you how to leverage the power of best-of-breed Python and Javascript libraries to do so, using engaging examples and stressing hard-earned best-practice., You'll learn how ...
Learn new utility libraries that vastly simplify animations in Java. * Effects: Learn how to create, customize, and use static and animated effects—the mainstays of Filthy Rich Clients. <br>...
Get introduced to static and dynamic analysis methodologies and build your own malware lab Analyse destructive malware samples from the real world (ITW) from fingerprinting and static/dynamic analysis...
IDR (Interactive Delphi Reconstructor) – a decompiler of executable files (EXE) and dynamic libraries (DLL), written in Delphi and executed in Windows32 environment. The program firstly is intended ...
Handle behavior ignored by the standard--including issues related to dynamic libraries, static objects, and threading Achieve binary compatibility between dynamically loading components Understand ...
Understand how to create and learn static and dynamic probabilistic models Successfully cluster high-dimensional data and evaluate model accuracy Discover how artificial neural networks work and how ...
Building and using libraries (both static and dynamic) are then investigated. Coverage testing and profiling are explored, using the gcov and gprof utilities, as is application bundling and ...
Static, dynamic and interactive visualizations Data experiences with real-world datasets and data sources Intro to Data Science sections: AI, basic stats, simulation, animation, random variables, data...
Where JavaScript and dynamic HTML have brought desktop application features to the web browser, XMPP brings new communications possibilities to the Web. XMPP has many common social web features ...
binary code, dynamic link libraries, static link libraries, source code, examples and applications, include files, documentation, web pages, tutorials, Makefiles and other scripts, and any other ...