"Include can't be found", how to fix it? - c++

I am developing using OpenSceneGraph. I installed it from a user-runnable installer.
When I try to compile an application using OpenSceneGraph, I have this error :
Lexical or preprocessor error : Include cannot be found for all <osg/*> includes like <osg/AnimationPath>.
The file is available here /Library/Frameworks/osg.framework/Versions/92/Headers/XXXX So following this solution on how to "add existing frameworks" to the new Xcode, I added osg.framework to the project.
any idea is a welcome.
I am using :
IDE Xcode 4.5
Clang 4.1
OS X Mountain Lion

When compiling you will have to add the include files using the -I option of the compiler and also possibly add library directory using the -L option of the compiler(the options may be a bit different if you are using compiler different from gcc).
I guess both library and the include directories for this product should be subdirectories of the install destination you have chosen. For the include directory of course look for directories containing some kind of header files .h or .hpp and for the libraries look for .lib or .dll doesn't the library documentation mention what includes and libraries you need and where you can find them?
EDIT: you will also have to tell xcode where to search for your includes. I tried googling it and here is one of many results on how to add a directory to the include path of a project.
You will have to located which directory to add to the include path. It seems they set some environment variables in the official documentation for that.
Hope this helps.

You'll need to add /Library/Frameworks to the "Frameworks search path" in the project settings.

Related

How can I install and use C++ libraries on eclipse?

I want to use libosmium library. Could someone please tell me how do I set up this library after I download it?
All I need to know is the standard way of installing external libraries. I can't really find very clear instructions online.
I'm coding with C++ using the eclipse IDE version 4.18.0.
For includes: right click on your project and go to Properties>>C/C++ Build>>Settings>>GCC C++ Compiler >> Includes
you must add the include path for the external library (where the header reside). This information is needed by the Eclipse indexer (code completion etc.) and the compiler
For libraries: right click on your project and go to Properties>>C/C++ Build>>Settings>>GCC C++ Linker >> Libraries you must add the library search path (option -L) and the library you want to link against (option -l). This info is needed for the linker.
Source: http://wiki.eclipse.org/CDT/User/FAQ#How_do_I_add_an_external_library_to_my_C.2B.2B_project.3F
Eclipse-CDT Setting Pictures
Include path settings:
Library & library search path settings
You can also use pkg-config plug in
https://marketplace.eclipse.org/content/pkg-config-support-eclipse-cdt
Here is a link to a similar question with answers: Problems importing libraries to my c++ project, how to fix this?
As specified in the other answer, you can usually add a library by looking at the project properties:
Properties>>C/C++ Build>>Settings>>GCC C++ Compiler>>Includes
However if you're using a makefile project, the Makefile itself must know about the location of libraries. In this case, in order to avoid an "Unresolved inclusion" warning in the header, you may also want to tell eclipse where the header files are. This way the autocomplete & "Open Declaration" will work. This is found in:
Properties>>C++ General>>Preprocessor Includes Paths, Macros etc.
In my case I couldn't figure out how to add a custom configuration and updated the default configuration. I added a path for the Android NDK under the GNU C++ -> CTD User Setting Entries

Using ITK with xcode

I am working on an xcode project that requires me to use ITK (a c++ library), I have went through with the installation of ITK, by doing
ccmake InsightToolkit-4.13.1
and then configuring and generating the files, then runing
make
make install
but I do not know how to import the library into the xcode project, where I get the following error every time I try building it:
'itkImage.h' image file not found
I would like to know how could I import it and share it with other people on different computers.
The #include directive comes with two flavors:
With quotes (#include "file.h")
With ankle brackets (#include <file.h>)
The first usually refers to files relative to your project directory. The second is for system libraries.
You can influence the search path in the project setting:
double-click on the project in the project explorer
Click on Build settings
Click on your target
Click on All to view also hidden options
In the section Search Paths you can then update the header search path to include the absolute path of you rlibrary headers. Attention: you have to do this for the Debug and for the Release builds:
This will solve the error that you have reported.
Remark: be careful, because after this is solved, you could experience some other issues related to the good use of the library, as pointed out by drescherjm in the comments (link about registration of custom classes to the library's fatories if Cmake is not used to compile the project)

How to add Eigen library to c++ project

Probably a dumb / simple question, but I have not been able to find an answer. I have no clue how adding libraries works with CodeBlocks c++. I downloaded the .zip file from http://eigen.tuxfamily.org/index.php?title=Main_Page and extracted the files into my directory. How can I use this library now in my project?
Add one line of code to your source file where you want to use Eigen.
#include "Eigen/Dense"
Put Eigen (extracted zip file) in a directory where you put your existing working header file.
Personally I had no idea how to install eigen on code blocks, but those are the steps I made and it worked:
unpack the ZIP into some arbitary folder
go to codeblocks Settings-> complier-> Search Directories-> Add-> enter the address of the folder you chose in (1)-> o.k
declare #include "Eigen/Dense" before the main function.
I learned the steps from here
This one was a tricky one for me. I am using Code::Blocks Ver 17.12.
a) I downloaded Eigen 3.3.5 (http://eigen.tuxfamily.org/index.php?title=Main_Page). The zip file downloaded is named as "eigen-eigen-b3f3d4950030"
b) Extracted the file to my project folder.
c) Changed the name of the extracted file from "eigen-eigen-b3f3d4950030" to "Eigen3" (you can choose any name).
d) Inside this folder, you will find other folders such as bench, blas, cmake, debug....
Now you have to add the library files for your project (so that the compiler knows where to look for the required library files).
e) In codeblocks, click on Settings --> Compiler --> Search Directories --> Compiler
Click Add and add the Eigen3 folder (the downloaded and extracted folder which was renamed in previous step 'c').
Once added, click on Linker tab (just beside 'Compiler' tab) and add the same path to Eigen3 folder.
f) Now click on Build Options tab, which is found besides 'Search Directories' tab.
g) Tick the "Explicitly add currently compiling file's directory to compiler search dirs"
h) Tick the "Explicitly add project's top-level directory to compile search dirs"
i) Click OK.
Now your build should work and the compiler knows how to search for Eigen libraries.
Any issues, just post it here.
Best wishes
Shre
in my radio astronomy project i install Eigen by the following command:
sudo apt-get install libeigen3-dev
my cmake automatically find the eigen header which i used. it is a sample of my header
#include <eigen3/Eigen/Core>
It's a template library. You can put it anywhere as long as it's in the path (accessible).
Just include the proper headers and it should work. No need to link anything, everything is in the headers.

setup include path in eclipse CDT in mac os (headers from framework)

for example I need to include a header
#include <OpenGL/glext.h>
while it is actually a header file glext.h under OpenGL.framework/Headers/.
Therefore it is no way to give eclipse a physical path about "OpenGL/glext.h", and I always get unresolved inclusion warning.
I can still build and run them (with managed makefile project) but it is impossible to browse the functions or definitions from those "resolved" header files.
is there any solution?
While not ideal, my solution to this has been to create a folder "/Developer/Framework Headers" (though the name isn't important), and link from e.g. "/System/Library/Frameworks/Foo.framework/Headers" to "Foo" under said folder. Then in Eclipse I add "/Developer/Framework Headers" to a project's includes.
I say not ideal because apart from having to create links for the frameworks you need and add an include to each project, Eclipse seems to have trouble in certain cases such as nested frameworks (e.g. CoreGraphics beneath ApplicationServices), but YMMV.
Yes there is one. Right click on the project in "Project Explore" window and click on the "property". In there Open "C/C++ General" column and choose "Path and symbols". Now you see all of the include library path for this project. If your using C then add the OpenGL library into GNU C, or if you use C++ then add it into GNU C++. Unfortunately you have to do this for every new project. I have been searching for a while how to do this by default but nothing really useful. Hope this help you get rid of those annoying yellow wave lines.
Since current Eclipse CDT releases don't perform sub-framework header inclusion correctly, you can avoid sub-framework problems (like those generated by the CoreServices header files) by creating symbolic links to the include directories of each sub-framework. I elaborated on this subject, which stems from danhan answer on this question, in this blog post.
In order to automate this process, I've created a Z shell script which automates this process and creates the symlink to the specified frameworks' header directory, together with the links to the include directory of each one of their sub-frameworks. The script can be found in this GitHub repository.
Hope this helps.

Including Libraries C++

How do I properly include libraries in C++? I'm used to doing the standard libraries in C++ and my own .h files.
I'm trying to include wxWidgets or GTK+ in code::blocks and/or netbeans C/C++ plugin. I've included ALL libraries but I constantly get errors such as file not found when it is explicitly in the include!
One error: test1.cpp:1:24: wx/msw/wx.rc: No such file or directory : Yes the .h file library is included; what am I missing?
Do I need to be importing other things as well? Is there a tutorial for this? Obviously my shoddy textbook hasn't prepared me for this.
Firstly, header files are not the same thing as libraries. A header is a C++ text file containing declarations of things, while a library is a container for compiled, binary code.
When you #include a header file, the compiler/IDE needs to know where to find it. There is typically an IDE setting which tells the compiler where to look, or you can do it from the command line, normally using the -I switch. It sounds to me as if you have not set up the path to search for header files on in your IDE.
This means that test.cpp included "wx/msw/wx.rc" but that file cannot be found by your compiler. How to fix this depends on your compiler, but you need to find where wxwidgets is installed and add that to your "Include Paths" so that your compiler knows where to search for it. You can also put a more complete path to it in the include directive.
If the files are present in the same directory as test1.cpp, then probably you use the wrong kind of include. #include <...> is usually used for code that resides outside of the directory that your project is in. #include "..." is for includes inside your project directory (and then if they aren't found there, search in the same places as #include <> would).
It is quite an old question and this didn't really answer it for me.
I reinstalled wxwidgets into the root directory as someone suggested that being in a directory with a space in the name may be part of the problem.
Then I went into project > build options > search directories and removed all entries pointing to original install.
And this fixed the problem