I'm trying to build a simple gtk+ example in Eclipse.
#include <gtk-2.0/gtk/gtk.h>
#include <glib-2.0/glib.h>
int main (int argc, char *argv[])
{
/*-- Declare the GTK Widgets used in the program --*/
GtkWidget *window;
/*-- Initialize GTK --*/
gtk_init (&argc, &argv);
/*-- Create the new window --*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*-- Display the window --*/
gtk_widget_show(window);
/*-- Start the GTK event loop --*/
gtk_main();
/*-- Return 0 if exit is successful --*/
return 0;
}
My console output after I build the project is...
make all
Building file: ../src/gtkTest.c
Invoking: GCC C Compiler
gcc -I/usr/local/include -O0 -g3 -Wall -c -fmessage-length=0 `pkg-config --cflags --libs gtk+-2.0` -MMD -MP -MF"src/gtkTest.d" -MT"src/gtkTest.d" -o "src/gtkTest.o" "../src/gtkTest.c"
Finished building: ../src/gtkTest.c
Building target: testParallel
Invoking: GCC C Linker
gcc `pkg-config --cflags --libs gtk+-2.0` -o "testParallel" ./src/gtkTest.o
./src/gtkTest.o: In function `main':
gtkTest.c:(.text+0x1e): undefined reference to `gtk_init'
gtkTest.c:(.text+0x28): undefined reference to `gtk_window_new'
gtkTest.c:(.text+0x38): undefined reference to `gtk_widget_show'
gtkTest.c:(.text+0x3d): undefined reference to `gtk_main'
collect2: error: ld returned 1 exit status
But if I compile it with following command in the command line, it builds successfully.
gcc -o main ../src/gtkTest.c `pkg-config gtk+-2.0 --cflags --libs`
What is the difference between the 2 commands? And how can I do it in Eclipse?