Amateur library include question

Started by
6 comments, last by Run_The_Shadows 18 years ago
I'm trying to write programs using a library I have downloaded and installed. However, although I have "#include"ed the libraries (ie. #include <ga/ga.h>) just like some examples I've seen, it still doesnt find the library. I think it's because in the makefile for the examples they somehow point to my /usr/local/lib and /usr/local/include directories... or something. I don't really get makefiles or including libraries, so I'm having a tough place trying to start. So the question is: How do I get my program to "see" these libraries? Do I have to do it in a makefile, or can you specify a path in the program itself? Thanks!
Advertisement

A couple quick questions will help us give you a hand: Are you getting compiler errors or linker errors? Can it not find the .h files or the .lib files? Also what compiler/IDE are you using?

Typically there is a setting in your development environment where you can set a list of directories for the compiler and linker to search. It's been way too long since I've used makefiles to remember where you can reference search directories. :)

In Linux (I'm guessing from the paths in your example) and similar environments the options you need to pass to your compiler to make it work often come from another program.

For example, to use libpng, you could add `pkg-config libpng --cflags` to the options to your compiler when compiling, and `pkg-config libpng --libs` when linking.

Sometimes a library will also come with a libname-config script too, which works much the same as above.

The best place to find the answer is to check the documentation that came with the library, it probably says how to use it.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
You downloaded a library that does not provide precompiled binaries. You need to compile them yourself. In this case, the author only provides makefiles(useful on *nix variants, not so much on Windows).

However, I spent 3 seconds on the library's webpage and found this which appears to be readymade project files for a couple major compilers.
Enjoy.

This is, of course, assuming that you're using Windows and getting confused about exactly how makefiles work and why they aren't working and oh god I've included the header file but nothing is happening!

Don't panic, this happens to all Windows programmers who start digging around in open source libraries for the first time.
haha actually I'm using linux. I've installed the library and as far as I know it copied everything to the right directories... I just don't know what they are and how to use them. I've looked at the sample programs (in fact, its what I've been basing my work on so far just to get things to compile/work. I'm using g++ to compile it and it gives me a TON of compile errors. As if its looking for functions used by the library and not finding them.

The examples use #include <ga/ga.h> and such and they work fine, but when I do it things seem to go awry, as if the program I'm using doesn't know where to find ga.h, but theirs does somehow (once again, probably because they do something in the makefile to point to the library, but not sure on that)
Quote:Original post by matrisking
haha actually I'm using linux. I've installed the library and as far as I know it copied everything to the right directories... I just don't know what they are and how to use them. I've looked at the sample programs (in fact, its what I've been basing my work on so far just to get things to compile/work. I'm using g++ to compile it and it gives me a TON of compile errors. As if its looking for functions used by the library and not finding them.

The examples use #include <ga/ga.h> and such and they work fine, but when I do it things seem to go awry, as if the program I'm using doesn't know where to find ga.h, but theirs does somehow (once again, probably because they do something in the makefile to point to the library, but not sure on that)


Have you read the documentation?
Yup, as far as I know nothing on there corresponds to my issue. Hm.....
Quote:Original post by matrisking
Yup, as far as I know nothing on there corresponds to my issue. Hm.....


Well, without providing any sort of error messages or specifics, we're all sort of stuck guessing at what is wrong. I'm going to bet that you are downloading galib, #include'ing the header, and getting puzzled because things don't work.

This is, to repeat, because galib does not ship with precompiled binaries. You need to either:
a)build the source to create it's binary
or
b)include all of galib's source files and headers into your own project

If you simply try to #include the header, it will not work because there are no function definitions to match the declarations in the header.

This topic is closed to new replies.

Advertisement