LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Compiling a C program with openGL, GLEW and GTK in ubuntu. (https://www.linuxquestions.org/questions/linux-newbie-8/compiling-a-c-program-with-opengl-glew-and-gtk-in-ubuntu-930027/)

sanehussain 02-18-2012 04:13 AM

Compiling a C program with openGL, GLEW and GTK in ubuntu.
 
I am writing a C program, which uses openGL and GTK for the GUI(There are 2 separate windows). It also uses GLEW. Currently I am using the following command to compile it:

gcc `pkg-config --cflags --libs gtk+-2.0` main.cpp -o hello -lglut -lGL -lGLEW

And these are the errors I am getting:

/tmp/cca4mYJB.o: In function `initGuiWindow()':
main.cpp:(.text+0xf8): undefined reference to `gtk_builder_new'
main.cpp:(.text+0x11a): undefined reference to `gtk_builder_add_from_file'
main.cpp:(.text+0x11f): undefined reference to `gtk_widget_get_type'
main.cpp:(.text+0x136): undefined reference to `gtk_builder_get_object'
main.cpp:(.text+0x142): undefined reference to `g_type_check_instance_cast'
main.cpp:(.text+0x15c): undefined reference to `gtk_builder_connect_signals'
/tmp/cca4mYJB.o: In function `show()':
main.cpp:(.text+0x175): undefined reference to `gtk_widget_show'
/tmp/cca4mYJB.o: In function `on_btn_color_color_set(_GtkColorButton*, void*)':
main.cpp:(.text+0x9b6): undefined reference to `gtk_color_button_get_color'
/tmp/cca4mYJB.o: In function `on_circ_segments_value_changed(_GtkSpinButton*, void*)':
main.cpp:(.text+0xb9a): undefined reference to `gtk_spin_button_get_value'
/tmp/cca4mYJB.o: In function `guiSetStatusbarText(char const*)':
main.cpp:(.text+0xc29): undefined reference to `gtk_statusbar_push'
/tmp/cca4mYJB.o: In function `get_statusbar()':
main.cpp:(.text+0xc4b): undefined reference to `gtk_builder_get_object'
/tmp/cca4mYJB.o: In function `get_message_context_id(_GtkStatusbar*)':
main.cpp:(.text+0xc66): undefined reference to `gtk_statusbar_get_context_id'
/tmp/cca4mYJB.o: In function `clear_statusbar_text_private(_GtkStatusbar*, int)':
main.cpp:(.text+0xc94): undefined reference to `gtk_statusbar_remove'
/tmp/cca4mYJB.o: In function `guiInit(int*, char**)':
main.cpp:(.text+0xcb8): undefined reference to `gtk_init'
/tmp/cca4mYJB.o: In function `guiMainIteration()':
main.cpp:(.text+0xccc): undefined reference to `gtk_main_iteration_do'
/tmp/cca4mYJB.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0xcef): undefined reference to `operator new[](unsigned int)'
collect2: ld returned 1 exit status


I don't know what mistake I am making. Can somebody please help me out?

Dark_Helmet 02-18-2012 09:07 PM

Well, because nobody else has responded...

Quote:

gcc `pkg-config --cflags --libs gtk+-2.0` main.cpp -o hello -lglut -lGL -lGLEW
Quote:

Code:

main.cpp:(.text+0xcef): undefined reference to `operator new[](unsigned int)'

I don't use gcc to compile C++ code. When I say "gcc" I mean the specific executable--not the compiler collection.

I always use g++ to compile C++ code. The g++ executable should come with your gcc install. And, given that the linker is complaining about the "new" operator (a fundamental C++ operator), it seems like there's a basic/fundamental issue (e.g. using an incorrect compiler).

Try with g++ and see where it gets you.

There may be some relationship between gcc and g++ (apart from being in the same compiler collection). For instance, g++ may simply be gcc with a specific set of command line options automatically applied. Though, I'm not familiar enough with them to say there is or is not such a relationship.


All times are GMT -5. The time now is 04:35 PM.