When I use the code #include <ofstream.h> in my .h file I get this error:
"fstream.h" file not found
I use the Clion in os x.
In C++ you should not include files (system-files), which ends with .h, instead do #include <fstream>
see: http://en.cppreference.com/w/cpp/io/ofstream
Related
I am trying to compile the a program in Linux and the program contains the following header files:
#include <iostream>
#include <vector>
#include "Minuit2/FCNBase.h"
#include "FunctionMinimum.h"
#include "MnMigrad.h"
etc. The source file is in
home/christian/code
and the header files are all in
/home/christian/root/include/Minuit2
I am trying to compile by running the following command:
g++ -I /Minuit2 niminimzationExample.cpp -o niminimzationExample -L/Minuit2/lib -lMinuit2
But I get the following error message:
In file included from niminimzationExample.cpp:9:0:
/home/christian/root/include/Minuit2/FCNBase.h:13:10: fatal error: Minuit2/MnConfig.h: No such file or directory
#include "Minuit2/MnConfig.h"
Because the compiler cannot find MnConfig.h which is the first header file inside of FCNBase.h. I have also tried to run
g++ -I /home/christian/root/include/Minuit2 niminimzationExample.cpp -o niminimzationExample -L/Minuit2/lib -lMinuit2
But I still get the same error. What is the write way to include the header files?
Thanks.
If your header is at
/home/christian/root/include/Minuit2/FCNBase.h
Your #include or compile option is wrong.
Currently you are telling the compiler to search for
/Minuit2/Minuit2/FCNBase.h
or
/home/christian/root/include/Minuit2/Minuit2/FCNBase.h
You should specify an option
-I /home/christian/root/include
To have the compiler search for Minuit2/FCNBase.h in the directory /home/christian/root/include.
If you don't want to change the option, you should change the #include to
#include "FCNBase.h"
To have the compiler search for FCNBase.h in the directory /home/christian/root/include/Minuit2.
I downloaded id3lib and placed the directory in my main.cpp directory but both g++ and visual studio give file/directory not founds and "undefined" errors
Here is my main.cpp:
#include <iostream>
#include <id3lib-3.8.3/include/id3/tag.h>
int main() { std::cout << "hi"; }
g++ main.cpp gives:
main.cpp:2:46: fatal error: id3lib-3.8.3/include/id3/tag.h: No such file or
directory
#include <id3lib-3.8.3/include/id3/tag.h>
if I use "" instead of <>, i get this error:
id3lib-3.8.3/include/id3/tag.h:32:30: fatal error: id3/id3lib_frame.h: No
such file or directory
#include <id3/id3lib_frame.h>
It's not enough to put it beside your main file. As you can see in your first approach when you used #include with <> it can't find it, that's because (copied from here) :
For #include <filename> the preprocessor searches in an implementation
dependent manner, normally in search directories pre-designated by the
compiler/IDE. This method is normally used to include standard library
header files.
You didn't tell your compiler where to look for id3lib-3.8.3/include/id3/tag.h so <> will not work for you.
Then you tried "". it found id3lib-3.8.3/include/id3/tag.h but in the tag.h there is #include <id3/id3lib_frame.h>, So back to problem with first approach, right?
What you need to do is that you need to tell your compiler/IDE where to look for these files. In visual studio click right on your project file, then properties->C/C++->General->Additional Include Directories and add the include library ($(ProjectDir)id3lib-3.8.3/include/ or maybe $(SolutionDir)id3lib-3.8.3/include/) to it. Then your first approach should work fine.
I have a file structure like this:
main.cpp --> #include <headers/f1/v.h>
headers/f1/v.h --> #include <headers/f1/i.h>
headers/f1/i.h
headers is a directory of external library.
Compiled with 'g++ main.cpp' and got file not found error:
In file included from main.cpp:11:
./headers/f1/v.h:32:10: fatal error: 'headers/f1/i.h' file not found
#include <headers/f1/i.h>
Very new to c++. Really can't figure it out. What has been wrong here? Thanks!
When including your own headers, in the same build tree, you should use quotes not angle brackets:
#include "headers/f1/v.h"
If you do get into the situation that you need <> for local files, for whatever reason, you could add the directory to your compiler's include path:
g++ main.cpp -I .
where . is the POSIX convention for "this directory".
Further reading:
What is the difference between #include <filename> and #include "filename"?
I just moved all my header files to be in the include directory of my project, rather than having both .cpp and .h in the src directory. I'm using YouCompleteMe in vim and now when I open vim, it tells me that my header files cannot be found on the side to alert me of compiler errors. Specifically, it gives me errors on the #include "my_header.h" of my_header.h file not found and errors on each method saying use of undeclared identifier. However, the code compiles just fine. And the auto-completion works fine. It seems that clang cannot find where my header files are located now since I moved them ../include. If I change my #include line to be #include "../include/my_header", all of the errors to away. But it seems better to only have #include "my_header.h" in all of my .cpp files or #include <my_header.h>.
Can anyone help me solve this issue?
I am trying to build some code written in C++ for getting an image via Kinect and I get the following error:
You must include nuiapi.h rather than including nuisensor.h directly.
but I already included windows.h and NUIAPI.h... windows.h was included before nuiapi.h in the source file. Can anyone tell me what is wrong?
here is the code in my source file .cpp
#include <Windows.h>
#include "Kinect.h"
#include <NuiApi.h>
#include <NuiImageCamera.h>
#include <NuiSensor.h>
kinectcamera::~Kinectcamera()
{
SafeRelease<IMediaObject>(&pDMO);
SafeRelease<INuiAudioBeam>(&pAudio);