62887

Glib — undefined reference to anything from glib? [duplicate]

Question:

This question already has an answer here:

<ul><li> <a href="/questions/9253200/undefined-reference-to-pthread-create-linker-command-option-order-libraries" dir="ltr" rel="nofollow">Undefined reference to 'pthread_create' — linker command option order (libraries before/after object files?) [duplicate]</a> <span class="question-originals-answer-count"> 2 answers </span> </li> </ul>

I have a problem with my S program. I need to compile it with this command:

gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 \ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wall -Wextra -g -std=c99 -lm *.c \ -o generator1_1

I have many error messages like this:

/home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:153: undefined reference to `g_hash_table_lookup' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:171: undefined reference to `g_hash_table_insert' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:172: undefined reference to `g_array_append_vals' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:179: undefined reference to `g_array_append_vals' /tmp/ccVqEbsM.o: In function `main': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:238: undefined reference to `g_hash_table_new_full' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:239: undefined reference to `g_hash_table_new_full' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:263: undefined reference to `g_hash_table_destroy' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/main.c:264: undefined reference to `g_hash_table_destroy' /tmp/cc2UG2Wy.o: In function `fillVFile': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/reader.c:47: undefined reference to `g_strdup' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/reader.c:51: undefined reference to `g_ptr_array_add' /tmp/cctOiTOl.o: In function `calculRegles': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:23: undefined reference to `g_hash_table_get_values' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:48: undefined reference to `g_list_length' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:57: undefined reference to `g_list_sort' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:82: undefined reference to `g_hash_table_new' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:85: undefined reference to `g_array_new' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:110: undefined reference to `g_hash_table_lookup' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:116: undefined reference to `g_hash_table_lookup' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:121: undefined reference to `log2' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:125: undefined reference to `g_array_append_vals' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:128: undefined reference to `g_hash_table_insert' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:139: undefined reference to `g_array_sort' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:167: undefined reference to `g_hash_table_lookup' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:176: undefined reference to `g_hash_table_lookup' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:198: undefined reference to `g_hash_table_destroy' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:199: undefined reference to `g_array_free' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/regles.c:205: undefined reference to `g_list_free' /tmp/cczRKfT8.o: In function `cstSequence1': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence1.c:19: undefined reference to `g_array_new' /tmp/cczRKfT8.o: In function `dstSequence1': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence1.c:26: undefined reference to `g_array_free' /tmp/cczRKfT8.o: In function `hashSeq1Fct': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence1.c:97: undefined reference to `g_str_hash' /tmp/cczRKfT8.o: In function `eqSeq1Fct': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence1.c:113: undefined reference to `g_str_equal' /tmp/cc7ZNuaW.o: In function `cstSequence2': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence2.c:22: undefined reference to `g_array_new' /tmp/cc7ZNuaW.o: In function `dstSequence2': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence2.c:29: undefined reference to `g_array_free' /tmp/cc7ZNuaW.o: In function `hashSeq2Fct': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence2.c:131: undefined reference to `g_str_hash' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence2.c:132: undefined reference to `g_str_hash' /tmp/cc7ZNuaW.o: In function `eqSeq2Fct': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence2.c:152: undefined reference to `g_str_equal' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/sequence2.c:153: undefined reference to `g_str_equal' /tmp/ccY2cdEJ.o: In function `foncteurRetireDoublonsSeq1': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/utils.c:29: undefined reference to `g_array_remove_index' /tmp/ccY2cdEJ.o: In function `foncteurRetireDoublonsSeq2': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/utils.c:52: undefined reference to `g_array_remove_index' /tmp/ccY2cdEJ.o: In function `retireDoublonsLignesSeq1': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/utils.c:66: undefined reference to `g_hash_table_get_values' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/utils.c:68: undefined reference to `g_list_foreach' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/utils.c:70: undefined reference to `g_list_free' /tmp/ccY2cdEJ.o: In function `retireDoublonsLignesSeq2': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/utils.c:75: undefined reference to `g_hash_table_get_values' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/utils.c:77: undefined reference to `g_list_foreach' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/utils.c:79: undefined reference to `g_list_free' /tmp/cc8GGinx.o: In function `cstVFile': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/vfile.c:15: undefined reference to `g_ptr_array_sized_new' /tmp/cc8GGinx.o: In function `dstVFile': /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/vfile.c:26: undefined reference to `g_free' /home/cyrine/Bureau/Seq_GLib2_1_1_Triche/vfile.c:29: undefined reference to `g_ptr_array_free' collect2: ld returned 1 exit status make: *** [all] Error 1

I work with Ubuntu 12.04. Does anyone have any idea?

Answer1:

Include the libraries, specified by -l, after the 'object' files (or source files when you compile the source and link all at once).

You have:

gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \ -lglib-2.0 \ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wall -Wextra -g -std=c99 \ -lm *.c -o generator1_1

You need:

gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wall -Wextra -g -std=c99 \ *.c -lglib-2.0 -lm -o generator1_1

There may be a few systems where you can specify libraries at arbitrary positions in the linking command line, but 'libraries after object files' has always worked on all the systems I've ever come across.

Recommend

  • How to create a categorical variable in R with unequal categoris [closed]
  • Install Play! with activator on linux
  • GIS sample data for testing performance
  • How do I get GDB to break on a GLib assertion failure?
  • error could not find the main class program will exit after netbeans
  • Cross domain ajax request returning XML: Origin http://… is not allowed by Access-Control-Allow-Orig
  • Not able to install a python module “Pycrypto-2.3”
  • Precedence and associativity of operators in C [duplicate]
  • How does “\\x” work in a String?
  • compilation error on clock_gettime and CLOCK_MONOTONIC
  • C++ Variable expressions for defining array size?
  • Is aliasing of pointers between aggregate C structs and their members standards-compliant?
  • How to initialize only few elements of an array with some values?
  • Removing spaces and special characters from string
  • variadic scanf in C
  • Multiple declarations and definitions
  • How to initialize a struct using the c style while using the g++ compiler?
  • Is it possible to pass a block of code as a macro argument?
  • Why does C++ not support Variable-length arrays? [duplicate]
  • Using an openmp pragma inside #define [duplicate]
  • In C, can you have a 128-bit bitfield [duplicate]
  • sdcc not accepting code
  • unary minus for 0x80000000 (signed and unsigned)
  • _iVar vs. iVar_ for variable naming [closed]
  • How to change the compiler of VS?
  • Is the integer width relevant in bitfield declaration?
  • Implicit declaration of scandir; alphasort is undeclared
  • In C,why is definition of a global variable in a separate statement raising warning,but is OK for a
  • Installing Perl6 and Panda on Ubuntu 15.10. Problems with bootstrap.pl
  • Can my PDF ping my server when it is opened?
  • Angular2 - Template reference inside NgSwitch
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • Android full screen on only one activity?
  • Accessing IRQ description array within a module and displaying action names
  • output of program is not same as passed argument
  • Javascript Callbacks with Object constructor
  • Where to put my custom functions in Wordpress?
  • Akka Routing: Reply's send to router ends up as dead letters
  • unknown Exception android
  • Checking variable from a different class in C#