2014-09-21 49 views
0

我的S程序有問題。 我需要這個命令來編譯:Glib - undefined引用任何來自glib的東西?

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 

我有很多這樣的錯誤消息:

/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 

我與Ubuntu 12.04的工作。 有沒有人有任何想法?

+0

你確定這些庫已經安裝,並且位於你的'PATH'中嗎? – Apoorv 2014-09-21 15:30:37

+2

將對象和源文件之後的庫鏈接到* last *。 – 2014-09-21 15:31:03

+0

沒有關於庫本身的任何錯誤消息,*之前*所有特定的錯誤消息? – 2014-09-21 15:34:45

回答

4

在「對象」文件(或源文件,當您編譯源代碼並一次全部鏈接)後面包含由-l指定的庫。

您有:

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 

您需要:

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 

可能有一些系統,你可以在連接命令行中的任意位置指定庫,但「庫的目標文件後, '一直在我所遇到的所有系統上工作。

+0

謝謝喬納森,它的工作原理! – Poisson 2014-09-21 15:51:40