Click to See Complete Forum and Search --> : libs external & c++ ?
moxfalder
April 30th, 2008, 03:29 AM
Please explain me step by step how to include external libs by example sqlite or pcre ?
I just don't understand mechanism of including other libs except C/C++ family libs by
#include <iostream>
...
I'm really want to know, but no one tell me how !
Maybe nobody know !
Await on your help !
thnx !
Marc G
April 30th, 2008, 10:52 AM
You do this during the linking stage. For example, with gcc you would specify
-l<somelib> at the command line.
STLDude
April 30th, 2008, 11:33 AM
I just don't understand mechanism of including other libs except C/C++ family libs by
#include <iostream>
This does not include library, this is a header file (two different thinks entirely).
Now, to include third party library in Visual Studio, click on the Project (in Solution Explorer) with right mouse button, that will get you Context menu, select Properties, which will give you Dialog with many options. Expend Linker section and click on Input, you will see Additional Dependencies, type your library name there, also most likely you will need to add path that library. This is done in General section (under Linker), where you will see Additional Library Directories.
P.S. This is for VC++ 2003/2005. I think 2008 should be similar and I don't remember 6.
Cybrax
April 30th, 2008, 03:50 PM
Please explain me step by step how to include external libs by example sqlite or pcre ?
I just don't understand mechanism of including other libs except C/C++ family libs by
#include <iostream>
...
I'm really want to know, but no one tell me how !
Maybe nobody know !
Await on your help !
thnx !
As STLDude mentioned above the #include directive does not link a library
you can link a library in the source code by using
#pragma comment( lib, "WS2_32.lib" )
where WS2_32.lib is the name of the library you wish to link, in this case its the winsock2 library
this will do the same as mentioned above but a little easier to apply
Now behind the mechanics
A header file contains mostly the declarations of functions and variables in the library, thus merely saying whats inside the library and how you can access it.
the library itself the .lib file on a windows platform contains the definitions and source if you compare this to a class you have a .h file with functions and a .cpp file with the "actual code".
the .h file you include in other parts of the project to make the code in the .cpp file accessible
Now if you include a header file in your project it declares the functions for you that are exported by the library but it does not have the "actual code" that belong to it, thats why you link the library to your project so that the compiler can take that and put it inside the program
Dynamic Library
A dynamic link library (.dll) is a external binary that you have to supply along with your application, we all know the dll's in the windows folder for example. you can basicly compare it with an exe file with the exception you cannot run it like a normal program.
Win32 .dll
Unix .so
Static library
A static library is a binary file that is integrated into your binary, meaning no extra files are needed by your application (with the exception if the library does). Once compiled you do not need to send the library with the application.
Win32 .lib
Unix .a
To prevent people from taking the code you have written instead of giving them the .cpp file you give them a static (.lib) or dynamic (.dll) library wich contains the code, not only that its also very usefull to be able to create libraries for other reasons such as easy integration to other projects without having to include all the sources.
I remember doing a lot of research and mind crashing on trying to understand all this, it was pretty confusing how it all exactly works in the beginning but once you understand the basics it turns out to be pretty easy.
I hope this was useful for beginners.
moxfalder
May 3rd, 2008, 05:30 AM
Thanks allot for detail explain, really now some understanding goin to me.
I'd like read about this myself without stupid questions, but books what i have don't help me.
If anyone can recomend me some useful books like for beginner or from MUST HAVE i be thankful !
thnx !
exterminator
May 3rd, 2008, 07:49 AM
See the FAQ for book recommendations.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.