I'm fiddling around with the C/C++ version of Eclipse to build a simple GTK app. However, I can't seem to be able to compile a GTK sample from within Eclipse. I can compile a simple Hello World style test app, so I know the tool chain itself is working. However, the moment I start adding GTK into the mix the compiler comes up with errors. The funny thing is that I can compile the examples outside the Eclipse environment just fine. E.g., I'm using the examples on this page and following the instructions given there let me build a working binary.
I think the first problem is that the main GTK include file is referenced differently when I try to compile within Eclipse. The non-Eclipse version I can compile with (as in the example):
#include <gtk/gtk.h>
However, within Eclipse this doesn't work. I need to change it to:
#include <gtk-2.0/gtk/gtk.h>
The include file can then be found but the compilation process then starts to throw errors about the GtkWidget type. E.g.:
#include <gtk-2.0/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;
}
Results in these errors:
make all
Building file: ../src/main.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/main.d" -MT"src/main.d" -o"src/main.o" "../src/main.c"
../src/main.c: In function ‘main’:
../src/main.c:7: error: ‘GtkWidget’ undeclared (first use in this function)
../src/main.c:7: error: (Each undeclared identifier is reported only once
../src/main.c:7: error: for each function it appears in.)
../src/main.c:7: error: ‘window’ undeclared (first use in this function)
../src/main.c:9: warning: implicit declaration of function ‘gtk_init’
../src/main.c:11: warning: implicit declaration of function ‘gtk_window_new’
../src/main.c:11: error: ‘GTK_WINDOW_TOPLEVEL’ undeclared (first use in this function)
../src/main.c:12: warning: implicit declaration of function ‘gtk_widget_show’
../src/main.c:14: warning: implicit declaration of function ‘gtk_main’
make: *** [src/main.o] Error 1
Not sure how to go about this. Any assistance would be very much appreciated.
Right click the Eclipse project and select properties. From the Configuration drop down, select
[ All configurations ]
. Then on the Tool Settings tab selectGCC C Compiler
(default) and add the following to the endCommand line pattern
(Expert settings) box:Do the same thing for the
GCC C Linker
option.If you don't want to start your include paths with gtk-2.0 than also add the include directory (/usr/include/gtk-2.0) like aardvark suggested.
Try adding the gtk directory to the build path:
Go into project Properties -> C/C++ build -> Settings -> Tool settings -> Directories and add it under Include paths.
A long waited relief considering the pkg-config support for Eclipse CDT is coming soon.
The support is under development and will be integrated to CDT around August or so.
The most important feature is that an easy to use user interface allows to select the required packages.
Project website: http://code.google.com/p/pkg-config-support-for-eclipse-cdt/
Update: Feel free to test the beta version:
http://marketplace.eclipse.org/content/pkg-config-support-eclipse-cdt
Feedback is appreciated!