Omnimaga
General Discussion => Technology and Development => Computer Programming => Topic started by: Scipi on October 13, 2010, 11:27:35 pm
-
How do you add libraries to where you can just include the .h file? Im trying to link with allegoro for gui's and graphics and stuff.
And what exactly are pointers good for. I know what they do and what they are but what can they do that variables can't?
Thx.
-
I'm not sure I completely understand your first question, but if I do the answer will vary depending on which linker you're using. If you're compiling and linking in one step with g++, it'll look something like:
g++ -o progname progname.cpp -lallegro
The form for that last argument is -lNAME_OF_LIBRARY.
Pointers store the address of a variable, structure, etc. The most straightforward usage of them is to give functions access to large amounts of data without the tremendous (in some cases) overhead of actually passing all of that data.
-
Ok think I see the use of pointers a little.
I was really talking about how I would go about adding a library so I could just include it from anywhere with #include.
-
Pointers can be confusing at first, but once you use them a few times, you'll see they can be really useful. In C++, the need to use pointers is not as great as it is in C thanks to classes.
Okay, I see. #include isn't used to include libraries. It is used to include header files. For simplicity's sake, let's just say header files contain function prototypes. These prototypes are needed by the compiler to produce the object file. All the compiler does is make sure you're passing the correct types of arguments and using the return value appropriately. The linker is responsible for connecting these references to the actual functions.
So, simply put: you cannot include libraries at all. You have to include the relevant header files and link the library.
-
In visual studio, you can import a library from a header file like this:
#pragma comment (lib, "mylibrary.lib")
-
Pointers can be confusing at first, but once you use them a few times, you'll see they can be really useful.
Yeah they took me quite a bit to understand in Axe Parser x.x
-
Yeah I use MinGW as my compiler. Im still having problems with using allegro in my programs. I use Code::Blocks with MinGW. I think I might not have the dll file required. Though I haven't found any DL's.