Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » pkg-config -- solved
pkg-config -- solved [message #233377] Tue, 28 April 2009 21:23 Go to next message
David Hart is currently offline David HartFriend
Messages: 4
Registered: July 2009
Junior Member
It took me a week to track this down, trashing my eclipse CDT
installation and re-installing several times. But I finally found the
solution with some help from Google searches.

I'm trying to learn how to program GTK+ using eclipse on Ganymede as
my development platform. I found out that other developers were able to
make this work, so I just kept trying things (and learning a bit about
eclipse as a side-effect).

Here is the code I'm trying:

============================================================ ================
Name : helloworld.c
Author : dph
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style

============================================================ ================

#include <gtk-2.0/gtk/gtk.h>

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

/* Initialize GTK+ and all of its supporting libraries. */
gtk_init (&argc, &argv);

/* Create a new window, give it a title and display it to the user. */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello World");
gtk_widget_show (window);

/* Hand control over to the main loop. */
gtk_main ();
return 0;

I'm using Fedora Linux as my development platform. The gtk.h header file
is in a non-standard location, that is why the "gtk-2.0" prepends the
"gtk/gtk.h". Simply putting "gtk/gtk.h" would be more cross-platform

Anyway, I had a HARD time getting eclipse to find the directories. From
the command-line I would enter:
gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0`
`pkg-config --libs gtk+-2.0`
and it would compile and link. So I knew the code was good.

On ubantu forums I found the answer:

as follows (modified slightly because of references to previous posts,
to split the `pkg-config --cflags out for the pre-processor and to
split out the `pkg-config --libs gtk+-2.0` for the linker, and to update
for Ganymede):

In the eclipse CDT perspective create a simple C project (well, it will
become a C GTK+ project shortly):
* Create an new (clean) project by selecting from the menu bar:
File -> New -> C -> C Project
* Click Next
* Expand "Executable"
* Select "Hello World ANSI C Project"
* Select "Linux GCC" if not already highlighted (not sure about other
vendor toolchains)
* For a "Project Name" I entered "helloworld"
* Click Finish
* Expand "helloworld" in the Project Explorer
* Expand "src"
* Double left-click on helloworld.c to bring up the editor
* Replace the code:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */

with the above GTK+ code

Now, let's use the two variables we created to allow us to use the
includes and libraries:
* From the menu bar select Window -> Preferences
* Expand the C/C++ category
* Select Build Variables
* Click on Add to define a variable
The "Define a New Build Variable" dialog box is displayed
* Enter as follows:
Name: gtk+-cflags
Value: `pkg-config --cflags gtk+-2.0`
(note backwards single quotes (upper-left on your PC keyboard)
are important)
* Click on Add to define another variable
Name: gtk+-libs
Value: `pkg-config --libs gtk+-2.0`
(note backwards single quotes (upper-left on your PC keyboard)
are important)
* Repeat if you want to set up one for c++ as well using the c++
variables. I have not tried this yet. If someone wants to try this,
please post your findings.
* Click Apply
* Click OK to make these variables available for all C projects
you create:

Now you have two compiler variables you can apply to any GTK+ C project.
* Highlight and left-click on your C GTK+ helloworld project in the
Project Explorer
* Select Properties
* Expand "C/C++ Build", and select "Settings"
* Select the "Tool Settings" tab
* Expand "GCC C Compiler"
* Select "Miscellaneous"
* On my default Ganymede CDT installation the "other flags" field
-c -fmessage-length=0
* Add the following variable to the end of "other flags":
* Expand "GCC C Linker"
* Select "Miscellaneous"
(not the compiler Miscellaneous, but the linker Miscellaneous)
* On my default Ganymede CDT installation the "Linker flags" field
the "Linker flags" field is empty
* Add the following variable to "Linker flags":
* Now that you have set up your project to use these variables you
can apply them by clicking Apply, followed by OK.

Now, just build your project. It works. Now you can apply this to your
other C GTK+ projects. You are using pkg-config.

If you have other include files and libraries to add to your project, I
suspect you can just create some variables for them (with their unique
pkg-config commands) and add them to the project the same way.

Have fun with GTK+.

Re: pkg-config -- solved [message #1710976 is a reply to message #233377] Mon, 12 October 2015 06:13 Go to previous message
IEEE 754 is currently offline IEEE 754Friend
Messages: 1
Registered: October 2015
Junior Member
Hey Man,

Thanks a lot for posting this. I was getting some nasty linker errors in eclipse and this helped me solve it.

For those who get linker errors in OpenCV program compilation (Eclipse/Ubuntu) -
This thing works for the error too.
Just appropriately rename the flags and in the value field, instead of gtk+, use opencv.

Previous Topic:launch failed.binary not found
Next Topic:How to "add-symbol-file" when remote-debug using CDT?
Goto Forum:

Current Time: Fri Sep 30 21:41:29 GMT 2022

Powered by FUDForum. Page generated in 0.04372 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top