G 文件的问题
有一个:
GFile* gf = g_file_new_for_path(file_path);
我的代码中 。但是当我尝试编译它时,我看到错误:
未定义的引用:'g_file_new_for_path'
在包含部分中我有 #include
这段代码有什么问题?
I have a:
GFile* gf = g_file_new_for_path(file_path);
in my code. But when i try to compile it, I see error:
Undefined reference to: 'g_file_new_for_path'
In include section I have #include <gio/gio.h>
What's wrong in this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我重新标记了你的问题,这不是 GTK+,这是 gio。
正如您根据评论发现的那样,您的问题是由于没有与正确的库链接所致。这是因为在 C 中,仅包含标头并不会告诉编译器在哪里可以找到实现该标头中声明的内容的代码。为此,您通常需要链接到正确的库(或直接编译代码,就像在自己的项目中所做的那样)。
顺便说一下,推荐的引用库的方法是使用诸如 pkg-config。然后编译看起来像这样:
你需要仔细检查上面的内容,我在输入此内容时不在 Linux 中,所以我无法验证确切的包名称。
I re-tagged your question, this is not GTK+, it's gio.
As you've discovered according to your comment, your problem was due to not linking with the proper libraries. This is because in C, merely including a header doesn't tell the compiler where to find the code that implements the things declared in that header. To do that, you typically need to link with the proper libraries (or compile the code directly, as you do inside your own projects).
The recommended way, by the way, to reference the libraries is using a tool such as pkg-config. Then the compilation would look something like this:
You need to double-check the above, I'm not in Linux as I type this so I can't verify the exact package names.