11

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;
}
4
  • Can you give a short, complete example, along with the compiler error? In particular, I'm interested in the #include directive you are using which fails. Jul 26, 2013 at 17:33
  • 1
    #include < path as if working directory is usr/local/include >
    – A. H.
    Jul 26, 2013 at 17:41
  • If just Eclipse says so, but your project compiles without error, try re-indexing the project. Jul 26, 2013 at 18:14
  • Thank you for you help. It works. I also marked your answer as accepted! :-)
    – Moonlit
    Jul 26, 2013 at 18:23

2 Answers 2

15
  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.

3
  • thx, i'll try that. but to clarify: It's NOT true that the c++ compiler will recognize per default any header files in /usr/include, /usr/local/include, /usr/lib, etc... ? I always have to link the libraries with the -I compiler option?
    – Moonlit
    Jul 26, 2013 at 17:40
  • @user1291235 As Benjamin Lindley already mentioned it may depend on how you're specifying the #include statement. So show what you're doing in more detail please. Jul 26, 2013 at 17:45
  • @user1291235 And yes, it is true, but the compiler linker doesn't look up recursively there. Jul 26, 2013 at 17:53
0

You will have to put the header files that you want to use, in your project folder and then use #include in your .cpp file just like how you would do for any other header files.

2
  • why copy? it's only needed to tell the compiler where to look for the files (by using -I with g++ as an example)
    – stefan
    Jul 26, 2013 at 17:30
  • Actually i installed the library using make install and all the files where copied to /usr/local/lib and /usr/local/include, so i guess i do not have to put those files into the project?!
    – Moonlit
    Jul 26, 2013 at 17:31

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.