Glib - 来自glib的任何未定义的引用?

时间:2014-09-21 15:27:51

标签: c glib

我的S程序有问题。 我需要用这个命令编译它:

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。 有没有人有任何想法?

1 个答案:

答案 0 :(得分:5)

在'对象'之后加入由-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

可能有一些系统可以在链接命令行中的任意位置指定库,但是在目标文件之后的库中可以指定库。我一直致力于我曾经遇到过的所有系统。