How to Use non standard Libraries?

Pages: 12
I will once again be using Dev C++. And once again, we are all very well aware that its terribly outdated, useless, defunct and has all hallmarks of a shit IDE. But nevertheless I will use it because the principal is the same for all IDE's.

Now suppose I want to use the GTK Graphical user interphase library to make GUI's.
The compiler must "know" about it because its not a standard library. (yes, GTK uses C code which is inappropriate for this forum but once again, the principal is the same)

For example, if it doesn't know about it and one were to use the header:

#include <gtk/gtk.h>

the compiler would send an error:

gtk/gtk.h: No such file or directory.


So how would one tell the compiler to recognize this library?

Apparently one must:
1) Install the library? However when I download the zip files there are no installation exe's??!
2) Link to its destination folder from the IDE "project options?

If Dirsch and ComputerGeek are reading this, they might smile due to this question being slightly similar to the question I posed in the thread:

http://www.cplusplus.com/forum/beginner/33274/page2.html

Ultimately, How do I make Dev link to this custom library?
For the purposes of this hypothetical question, I'll pretend that it's not hypothetical because I don't want to have to keep using some kind of future conditional tense :)

If you're happy using Dev-C++, would you consider switching to doing the whole thing manually?

If you were using gcc, for example, you could directly add the header search path for any given header to your command line.

I'll step back one; I was getting ahead of myself there. I will say some things that sound horribly obvious, for which I apologise, but I think it's a good idea to be thorough.

Note that you're not actually trying to link against a library here in this gtk.h stage; you're trying to compile (which is the stage before linking), and you've dictated that your code is to have the contents of gtk/gtk.h inserted, and the preprocessor is unable to find that file to insert it into your code.

If the compiler whinges that it can't find gtk/gtk.h, the obvious conclusion is that having wandered through the search path, there was no such file.

So, firstly go looking for that file yourself and confirm that it is actually on your system somewhere. You'd feel pretty silly if it wasn't there and you spent ages trying to insert it! :)

If it's not there, you need to download it from wherever it lives and put it in the right place (which is http://www.gtk.org/download-windows.html I believe - make sure you get the complete bundle http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.22/gtk+-bundle_2.22.1-20101227_win32.zip and read the readme file at the top level of that file). You're correct that there is no installer; it is up to you to put it somewhere sensible and then add the paths and the libraries to your compilation and linker settings. What counts as somewhere sensible? Really, just anywhere that you won't lose it and it won't get in the way. Make a new directory for this sort of thing, perhaps.

Here is a brief overview: once you've put it somewhere sensible, you will need to find the setting in your IDE that dictates the file search path. This will essentially be a big list of locations on your hard drive to look in when it is looking for a header file. Right now, it is running through this list and never finding gtk/gtk.h

For example, if you put the downloaded package in /home/user01/gtk the directory to add to the search path for header files would be /home/user01/gtk/include/gtk-2.0/

Once you have done this, expect it to work as far as the linker; the linker will then complain about "undefined references" or something similar. This will indicate that the compiler correctly understood the name and prototypes of all the functions, but now the linker cannot actually find the libraries (not header file, actual already compiled libraries) that contain those functions.

At this point, you will have to find the setting in your IDE that dictates which libraries you are linking against. You will need to add the names of each library in the gtk package, and add their location to the library search path. If you look in the zip file you downloaded, you'll see that they live in /lib at the top level, so if you put the downloaded package in /home/user01/gtk the directory to add to the search path for lib files would be /home/user01/gtk/lib/

Whilst I'm here, you meant "principle". :)

If you were using gcc, for example, you could do this:

g++ -I/home/user01/gtk/include/gtk-2.0/ -l/home/user01/gtk/lib/nameOfLibrary.a yourCodeFile.cpp

You can see there that the compiler/linker tool g++ has been specifically directed to the include directory /home/user01/gtk/include/gtk-2.0/ and the library file /home/user01/gtk/lib/nameOfLibrary.a

Essentially, this is all you do in your IDE when you add those parts to the appropriate text box in some menu somewhere.
Last edited on
I did all that:

1) Put the library package in an appropriate folder
2) (however the package I downloaded was different than yours, but it was a complete one)
3) Told the compiler to search for it. did this by doing project options> paramaters>add library or object. In that box however I dont know what to put because the entire package has hundreds of lib packages so I put all that I saw.
4) theres another option that has "library directories" "include directories" and "recource directories". Must I include anything there?

im sure your explanation is 100% correct and im sure it makes sense to the average c++ reader, but i still need a little bit more of an explicit explanation like points 1-7 type approach. kinda like the guys on the previous thread did (the link I provided in post 1). Ill still keep trying though :)
Last edited on
1) library directories - this needs to be the directory with the new libraries in (probably .lib files)

2) include directories - this needs to be the directory with the gtk/gtk.h path in (note, because the include is NOT gtk.h but gtk/gtk.h, you must include the directory with the gtk directory in it). As mentioned above, this will probably look something like this: /home/user01/gtk/include/gtk-2.0/

What error do you actually get now when you try to build?
Last edited on
i added the lib folder in library directory
I added C:\GTK\include\gtk-2.0 to include directory

Then it compiles forever and I have to cancel.

I installed the GTK package in C\GTK\ *the package*
The package includes bin etc include lib man manifest share src


Im really itching to get this to work!
Last edited on
If anyone wants to try doing it for themselves, heres the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_show(window);

  gtk_main();

  return 0;
}


Pls compile and run that using the library downloaded from:

http://www.gtk.org/download-windows.html

download the all in one bundle ver 2.22 under "all in one bundle" paragraph.

Use any IDE you want and tell me what you did and ill do it in DEV C++
Last edited on
ok, I was about to say something about dev C++ because it is outdated, but I think the problem is that you need to link all the sub directories for gtk also.. .they are all in the bundle as well... Hold up... let me get a copy of dev c++
to compile you need to include all the files that is needed by gtk in the project... it compiles so long, because it's trying to spit out all the errors, when you cancel, you'll see a list of errors that are kind of confusing, but they include the file that missing... include all of these in your project and it will compile
.. replace "\gtk"with your location of gtk

\gtk\include\gtk-2.0
\gtk\include\glib-2.0
\gtk\include\cairo;\gtk\include\atk-1.0
\gtk\include\fontconfig
\gtk\include\freetype2
\gtk\include\gail-1.0
\gtk\include\gdk-pixbuf-2.0
\gtk\include\libpng14
\gtk\include\pango-1.0
\gtk\include\pixman-1
\gtk\lib\glib-2.0\include
\gtk\lib\gtk-2.0\include
under which option? Library directories?
Under library directories, I put in all \lib\ folders
Under include directories, I populated all \include\ folders (like you also posted).

When it copiles it gives me over 1000 error messages eventually saying:
[General Error] Too many messages; abort
There must be something terribly wrong with your code. Please fix it


LOL epic fail ;-)
Frustrating...

Browsing through these errors it points to all of them being syntax errors.
Hmmm, isnt that a tell tale sign that this code isnt supported or something isnt standard?
Last edited on
oh, btw, if you get far enough with this, you'll find that you will need to update gcc, because Dev C++ stopped in 1991, so the libs are old... You can continue to use it, but you are going to have to get MinGW and make it work for this version if you want to keep using Dev C++ and gtk

You'd probably be better using another env like Code::Blocks... i've only just used both dev c++ and codeblocks because of this, so I'm happy I got to try them out... thanks.
no... these are all includes, not libraries... i know it says lib, but gtk is calling them anyway, so I included like it asked. Went all the way on code::blocks and then realized that I was on the wrong thing, then went back to Dev-C++ and found that you can't get past the linker, but the compiler is fine... the linker is only bad, because it can't find something that is new
oh, you asked how to include... uh.. for Dev-C++

project->project options->directories->include directories

-- edit: the code is fine, it's actually included with gtk and I made it run fine with code::blocks
Last edited on
-- edit: it works see my post at #msg186428... I'm leaving the link for alternatives though

http://www.jasonbadams.net/20081218/why-you-shouldnt-use-dev-c/

that page explains why we shouldn't use dev-C++ and after trying to make that code work, I agree with them.. there is a wxDev-C++ they mention if you really want to use it.
Last edited on
I dont understand. Dev C++ can be as old as dust but why does that matter when it comes to using libraries such as GTK? Arent libraries independant of the IDE? The IDE just needs to know where is library and to use it... And it cant be done here...
Your IDE is completely independent of libraries. If your IDE makes it really difficult to control what your compiler and linker are doing, you should abandon it.
IDE is not, and never was the problem, not only for this specific question but for all questions asked.

Let me put it this way. The IDE you use... what would you explicitly do to make that above piece of code work? Just use that code and download the library from the site I provided.
What are your steps?
Example:
1) go to your IDE "options"
2) under "X" tab put all lib files
3) under tab "Y" put a, b and c include files.

Or just use any library for that matter. what would be done to make IDE recognise it, step by step? I tried exactly as specified in earleir instructions but they all failed.
I would type the following when it was time to build:

g++ -IIncludeDirectory -lnameOfLibrary cppFile

where there may be many -IIncludeDirectory, one for each include directory, and many -lnameOfLibrary, one for each library, and many cppFile, one for each cppFile
Like I said before, it compiled after I included the libraries..

all of the ones I listed above in project->project options->directories->include directories

you have to hit "add" or they won't load

Alternately, you can add them to the compiler if you are doing future projects with gtk...

After you get them compiled, linking is a prob

first you have to go to project->project options->Parameters

Under C++ Compiler you have to add

-mms-bitfields

Under linker add the lib /gtk/lib/gtk-win32-2.0.lib

-- replacing "/gtk" with the location of gtk

But the last thing I'm stuck on in DevC++. I did all this in Code::Blocks and did fine, but on Dev-C++ I got two errors

/mingw/lib/crt2.o(.text+0x28):crt1.c: undefined reference to `__dyn_tls_init_callback'
/mingw/lib/crt2.o(.text+0x5c):crt1.c: undefined reference to `__cpu_features_init'


.. oh, wait... I'm looking at the command line code now, I think I can figure out the prob.. well, I think I have to do something again. I may not be able to get to it tonight.
ok, ok... the problem was a library that was included with dev-C++

remove the following line from Tools->Compiler Options->Directories->Libraries

"C:\Dev-Cpp\lib"

oh... I have the gtk folder in my path, so if it asks you for a dll, you can put /gtk/bin in your path (/gtk being the location of gtk) or copy the dll to where your executable is...

So, in the end, works fine... I just jumped the gun with speculation from reading everyone else online. Can't believe everything online, just have to try a bunch of stuff sometimes.
Pages: 12