如何#include第三方库 [英] how to #include third party libraries

查看:550
本文介绍了如何#include第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已建立并安装了一个名为 OhNet 的程式库。在 make install 之后,已经在 usr / local / include / ohNet 下安装了框架的相应头文件。现在我想在我的C + +项目中使用库(我使用eclipse),但是当我尝试包括一些头文件,eclipse不能找到这些文件。
至于我知道eclipse应该搜索头文件在这些目录(/ usr / include,/ usr / local / include,...)默认....我必须做什么使用图书馆?
我对C ++非常新,并且之前没有使用第三方来源。



谢谢。



- EDIT--
我只想写一个简单的helloworld程序来验证我已经包含了正确的框架。为了做到这一点,我想创建类 OpenHome :: Net :: DvDeviceStdStandard 。请参阅: ohNet C ++参考



现在我可以使用下面的头文件:
#include< ohNet / OpenHome / Net / Core / DvDevice.h> 但是如何创建一个类型 OpenHome :: Net :: DvDeviceStdStandard 的对象?现在? Eclipse说这个类型不能被解决。 (

  #include< iostream> 
#include< ohNet / OpenHome / Net / Core / DvDevice。 h>

使用命名空间std;

int main(){

OpenHome :: Net :: DvDeviceStdStandard device; //类型无法解析
cout<<!!! Hello World !!!< return 0;
}
pre>

解决方案


  1. 使用 -I 编译器选项指向第三方库目录( -I / usr / local / include / ohNet

  2. 使用 #include[任何你需要从oHNet] .h在您的头文件和编译单元(注意:你可能需要把相对的前缀pathes

  3. 使用 -L 链接器选项指定第三方的路径lib

  4. 使用 -l <​​/ code> linker选项指定您需要的任何具体的第3个库( -l [oHNet] 可能)

在目录中查看实际安装在那里的内容,以便为 [任何你需要从oHNet] .h [oHNet] ,s.th.



您没有在这里明确标记[tag:Eclipse CDT],因为 liboHNet.a 但是转到Project-> Properties-> C ++ Builder-> Settings对话框并找到C / C ++ Includes和链接器选项。


I have built and installed a library called OhNet. After make install the corresponding header files of the framework have been installed under usr/local/include/ohNet. Now I want to use the Library in my C++ project (i am using eclipse) but when i try to include some header files, eclipse is not able to find the files. As far as i know eclipse should search for header files in these directories (/usr/include , /usr/local/include ,...) by default.... What do i have to do to use the library? I am pretty new to C++ and haven't used third party sources before.

Thank you.

--EDIT-- I simply want to write an easy "helloworld" programm to verify that i have included the framework correctly. In order to do that i want to instatiate the class OpenHome::Net::DvDeviceStdStandard. see: ohNet C++ reference

I can now include the header file using: #include <ohNet/OpenHome/Net/Core/DvDevice.h> That works fine. But how can i create an object of type OpenHome::Net::DvDeviceStdStandard ? now? Eclipse says that this type cannot be resolved. :(

#include <iostream>
#include <ohNet/OpenHome/Net/Core/DvDevice.h>

using namespace std;

int main() {

    OpenHome::Net::DvDeviceStdStandard device; //type cannot be resolved
    cout << "!!!Hello World!!!" << endl;
    return 0;
}

解决方案

  1. Use the -I compiler option to point to the 3rd party libraries directory (-I/usr/local/include/ohNet)
  2. Use #include "[whatever you need from oHNet].h" in your header files and compilation units as needed (Note: you might need to put relative prefix pathes for subdirecories in the 3rd party include paths tree here!)
  3. Use the -L linker option to specify a path to the 3rd party libs you need (-L/usr/local/lib probably)
  4. Use the -l linker option to specify any concrete 3rd libs you need (-l[oHNet] probably)

Look in the directories what actually was installed there to figure what to place for [whatever you need from oHNet].h and [oHNet], s.th. like liboHNet.a for the latter.

You didn't tag [tag:Eclipse CDT] explicitly here, but go to the Project->Properties->C++ Builder->Settings Dialog and look for C/C++ Includes and Linker Options.

这篇关于如何#include第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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