[英]how to #include third party libraries
I have built and installed a library called OhNet . 我已经构建并安装了一个名为OhNet的库。 After make install
the corresponding header files of the framework have been installed under usr/local/include/ohNet
. make install
完成后,框架的相应头文件已安装在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. 现在我想在我的C ++项目中使用库(我正在使用eclipse)但是当我尝试包含一些头文件时,eclipse无法找到这些文件。 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? 据我所知,eclipse应默认搜索这些目录中的头文件(/ usr / include,/ usr / local / include,...)....我需要做什么才能使用该库? I am pretty new to C++ and haven't used third party sources before. 我是C ++的新手,之前没有使用过第三方资源。
Thank you. 谢谢。
--EDIT-- I simply want to write an easy "helloworld" programm to verify that i have included the framework correctly. --EDIT--我只想写一个简单的“helloworld”程序来验证我是否正确地包含了框架。 In order to do that i want to instatiate the class OpenHome::Net::DvDeviceStdStandard
. 为了做到这一点,我想实例化OpenHome::Net::DvDeviceStdStandard
。 see: ohNet C++ reference 请参阅: ohNet C ++参考
I can now include the header file using: #include <ohNet/OpenHome/Net/Core/DvDevice.h>
That works fine. 我现在可以使用以下内容包含头文件: #include <ohNet/OpenHome/Net/Core/DvDevice.h>
工作正常。 But how can i create an object of type OpenHome::Net::DvDeviceStdStandard
? 但是我如何创建OpenHome::Net::DvDeviceStdStandard
类型的对象? now? 现在? Eclipse says that this type cannot be resolved. Eclipse说这种类型无法解决。 :( :(
#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;
}
-I
compiler option to point to the 3rd party libraries directory ( -I/usr/local/include/ohNet
) 使用-I
编译器选项指向第三方库目录( -I/usr/local/include/ohNet
) #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!) 在你的头文件和编译单元中根据需要使用#include "[whatever you need from oHNet].h"
( 注意:你可能需要在第三方包含路径树中为子目录添加相对前缀pathes!) -L
linker option to specify a path to the 3rd party libs you need ( -L/usr/local/lib
probably) 使用-L
链接器选项指定所需的第三方库的路径(可能是-L/usr/local/lib
) -l
linker option to specify any concrete 3rd libs you need ( -l[oHNet]
probably) 使用-l
链接器选项指定所需的任何具体第三个库(可能是-l[oHNet]
) 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. 在目录中查看实际安装的内容,以便为[whatever you need from oHNet].h
和[oHNet]
,s。 like liboHNet.a
for the latter. 就像后者的liboHNet.a
一样。
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. 您没有在此明确标记[tag:Eclipse CDT],但转到Project-> Properties-> C ++ Builder-> Settings对话框并查找C / C ++ Includes和Linker Options。
您必须将要使用的头文件放在项目文件夹中,然后在.cpp文件中使用#include,就像对任何其他头文件一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.