C ++包含库 [英] C++ include libraries

查看:114
本文介绍了C ++包含库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,已经有一段时间了,我在#includes方面遇到了问题

Ok, so it's been a while, and i'm having problems with #includes

所以我在做

#include "someheader.h"

但这给了我

fatal error: someheader.h: No such file or directory

我想你可以说这是一个系统范围的库. 我正在运行arch linux,并从存储库中安装了该库,并且我认为.h文件位于/usr/include中.

It's a system wide library I guess you could say. I'm running arch linux and I installed the library from the repo, and I think the .h files are in /usr/include.

我可以将所有头文件复制到我的代码所在的文件夹中,但这可能是一个hack.

I could just copy all the header files into the folder my code is in but that would be a hack.

执行此操作的正确"方法是什么?

What is the "right" way to do this?

我不正确地说.h文件在/usr/include中,我的意思是库文件夹在其中 因此,埃米尔·柯米尔(Emile Cormier)的回答在一定程度上起作用了. 现在的问题是,头文件中包含一些包含,从我尝试访问的方法看来,这些包含没有发生 这给了我错误

I wasn't correct by saying the .h files were in /usr/include, what I meant was that the library folder was in there So, Emile Cormier's answer worked to a certain extent. The problem now is that there are some include in the header file and it seems from the methods I'm trying to access that those includes are not happening it's giving my the error

undefined reference to Namespace::Class::method()

好的,所以最后的答案是:

Ok so the final answer is:

#include <library_name/someheader.h>

并使用

g++ code.cpp -llibrary_name

推荐答案

有时,库的头文件安装在/usr/include/library_name中,因此您必须包括以下内容:

Sometimes, header files for a library are installed in /usr/include/library_name, so you have to include like this:

#include <library_name/someheader.h>

使用文件管理器(或控制台命令)在系统上找到标头文件,并查看是否应在标头的文件名前加上目录名.

Use your file manager (or console commands) to locate the header file on your system and see if you should prefix the header's filename with a directory name.

您收到的undefined reference错误是链接器错误.之所以收到此错误,是因为您没有与程序一起在libsynaptics中进行链接,因此链接器无法在程序中找到实现".您正在使用的libsynaptics函数.

The undefined reference error you're getting is a linker error. You're getting this error because you're not linking in libsynaptics along with your program, thus the linker cannot find the "implementation" of the libsynaptics functions you're using.

如果要使用GCC从命令行进行编译,则必须添加-lsynaptics选项才能在libsynaptics库中进行链接.如果使用的是IDE,则必须找到可以指定要链接到的库并添加突触的位置.如果使用的是makefile,则必须修改链接器标志列表,以便它添加-lsynaptics.

If you're compiling from the command-line with GCC, you must add the -lsynaptics option to link in the libsynaptics library. If you're using an IDE, you must find the place where you can specify libraries to link to and add synaptics. If you're using a makefile, you have to modify your list of linker flags so that it adds -lsynaptics.

还需要添加搜索路径的-L <path_to_library>标志,以便链接程序可以找到该库,除非该库安装在标准链接程序搜索路径之一中.

Also the -L <path_to_library> flag for the search path needs to be added, so the linker can find the library, unless it's installed in one of the standard linker search paths.

有关通过GCC链接到库的信息,请参见教程

See this tutorial on linking to libraries with GCC.

这篇关于C ++包含库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆