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.
Eclipse is popular for Java project development. It also supports C/C++, PHP, Python, Perl, and other web project developments via extensible plug-ins. Eclipse is cross-platform and runs under Windows, Linux and Mac OS.
Eclipse reads which version of gtk to use in it's init file. The init file can be in two different locations.
SWT is the layer between PlatformUI and the underlying GTK3 or GTK4(experimental) of the system. It can be launched to use GTK3 or GTK4, but cannot use them both at the same time. Communication from Java (SWT layer) to C (native GTK layer) occurs through calls defined in OS.java.
Right click the Eclipse project and select properties. From the Configuration drop down, select [ All configurations ]
. Then on the Tool Settings tab select GCC C Compiler
(default) and add the following to the end Command line pattern
(Expert settings) box:
`pkg-config --cflags --libs gtk+-2.0`
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With