g_utf8_collat​​e()在ubuntu上的glib-2.0中找不到20.04.3(LTS)

发布于 2025-01-31 18:55:11 字数 892 浏览 3 评论 0原文

我已经安装在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青萝楚歌 2025-02-07 18:55:11

尝试

cc $(pkg-config --cflags --libs glib-2.0) test.c

pkg-config存在以为依赖项提供正确的编译器和链接标志,以便您不必手动指定它们。

Try

cc $(pkg-config --cflags --libs glib-2.0) test.c

pkg-config exists to provide the right compiler and linker flags for dependencies, so that you don’t have to specify them manually.

放肆 2025-02-07 18:55:11

我知道源文件和链接器选项的顺序确实很重要。它这样的工作正常:

cc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include test.c -lm -L/usr/lib/x86_64-linux-gnu -lglib-2.0

I got to know that the order of the source file and the linker options do matter. It works fine like this:

cc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include test.c -lm -L/usr/lib/x86_64-linux-gnu -lglib-2.0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文