g_utf8_collate()在ubuntu上的glib-2.0中找不到20.04.3(LTS)
我已经安装在Ubuntu中:
sudo apt-get install libglib2.0-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libglib2.0-dev-bin
但是这个小的测试代码无法链接:
cat -n test.c
1 #include <stdio.h>
2 #include <glib.h>
3
4 int main()
5 {
6 char *p1 = "foo";
7 char *p2 = "bar";
8 int rc = 0;
9
10 rc = g_utf8_collate(p1, p2);
11 printf("g_utf8_collate(p1, p2) = %d\n", rc);
12 }
cc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lm -L/usr/lib/x86_64-linux-gnu -lglib-2.0 test.c
/usr/bin/ld: /tmp/cc583STn.o: in function `main':
test.c:(.text+0x38): undefined reference to `g_utf8_collate'
collect2: error: ld returned 1 exit status
在我的所有其他系统(Suse Linux,FreeBSD)上,它链接了文件,OFC与其他-i
和-L
dirs。
I've installed in my Ubuntu:
sudo apt-get install libglib2.0-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libglib2.0-dev-bin
but this small test code fails to link:
cat -n test.c
1 #include <stdio.h>
2 #include <glib.h>
3
4 int main()
5 {
6 char *p1 = "foo";
7 char *p2 = "bar";
8 int rc = 0;
9
10 rc = g_utf8_collate(p1, p2);
11 printf("g_utf8_collate(p1, p2) = %d\n", rc);
12 }
cc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lm -L/usr/lib/x86_64-linux-gnu -lglib-2.0 test.c
/usr/bin/ld: /tmp/cc583STn.o: in function `main':
test.c:(.text+0x38): undefined reference to `g_utf8_collate'
collect2: error: ld returned 1 exit status
On all my other systems (SuSE Linux, FreeBSD) it links file, ofc with other -I
and -L
dirs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
pkg-config
存在以为依赖项提供正确的编译器和链接标志,以便您不必手动指定它们。Try
pkg-config
exists to provide the right compiler and linker flags for dependencies, so that you don’t have to specify them manually.我知道源文件和链接器选项的顺序确实很重要。它这样的工作正常:
I got to know that the order of the source file and the linker options do matter. It works fine like this: