I have a folder named apt-util with header files in include directory. When I tried to compile the source code in which I include these files, it is saying :
parseFile.C:17:36: error: apt_util/unicode_utils.h: No such file or directory
In my code, I included this file like this:
#include <apt_util/unicode_utils.h>
How to resolve this error?
I am using Linux OS and compiling using g++.
If you reference a header with a relative path, use " instead of <>
#include "apt_util/unicode_utils.h"
You also seem to have a wrong path : apt_util instead of apt-util.
Give your compiler a hint about the base path of your include directories, e.g.
gcc -I/usr/local/src ...
If the directory apt_util is a subdirectory of your current working directory shouldn't you be using #include "apt_util/unicode_utils.h" instead?
Related
#include<apis/api1/api.h>
throws No such file or directory
i even tried moving api.h and api.cc to the main project directory and using
#include<api.h>
does the same thing even though it is in the exact same directory that the other classes use
i tried adding /apis/api1 to the compiler search path
that just crashes the compiler can someone tell me what to type into the compilers compilation line
#include <api.h>
is the way you include a system header. (That is, the header for a library installed on your system.) It does not search in the directory of the source file or in directories specified in -I command line arguments.
#include "api.h"
is the way you include your own headers. (But it will also search library header locations if it doesn't find the header locally.)
I have a pretty basic question. If I have a .cpp and .h file in a different location than my project, how can I reference it by saying #include " ".
I am trying to use wxMathPlot.cpp/.h and it references wxWidget cpp files.
mathplot.cpp(19): fatal error C1083: Cannot open include file: 'wx/window.h': No such file or directory
So say my wxMathPlot.cpp is located in C:\Users\Owner\Desktop and my wx/window.h is in C:\Users\Owner\Documents
#include "../Documents/wxMathPlot.h"
Should work. To elaborate:
When you use an include such as #include "header.h" the same directory as the file is searched.
When you use an include such as #include <header.h> a specific directory is searched, chosen by your compiler, which is where you will find most standard library header files.
You can reference it by using its full path or by referencing through one or more ..'s in your path (that means "go up one level"), or you can specify the directory in which the header file resides in the 'header file search path' (the 'include path') and then just use the filename.
However, using the full path is not recommended because if you move the header file relative to the file it is being referenced from, then it will not work anymore.
Look at this SO question for a nice answer as well.
For CPP files you need add those files in your project. If you are using Visual Studio you can add the cpp file by right clicking on your working project and selecting add existing item. If you want to refer a .h file you need include this, e.g
#include "../Documents/wx/Windows.h"
It is always good to use relative path rather than using absolute path.
Hi i would like to include a external library call NTL. its in the path as followed:
#include "WinNTL-5_4_2/include/NTL/tools.h"
My file is key.cpp and its reside in the same folder as NTL . but when i compile, it came up with another error which is ..
In file included from keygen.cpp:6:0:
WinNTL-5_4_2/include/NTL/tools.h:5:24: fatal error: NTL/ctools.h: No such file or directory
compilation terminated.
As its need another file call ctools.h, how do i includes tools.h to make ctools.h work also
I tried type
me#ubuntu:~/GG$ g++ keygen.cpp -o keygen -l WinNTL-5_4_2/include/
keygen.cpp:6:23: fatal error: NTL/tools.h: No such file or directory
but it doesnt work still.
Based on the error message, you should try changing your include to:
#include "NTL/tools.h"
and make sure that WinNTL-5_4_2/include is in your compiler's search path for include files.
You need to add the root directory as part of your project's search path for include files. It depends on your environment exactly how to do this, but there are usually two search paths -- one for include files and another for compiled libraries. Set that with the directory that contains the WinNTL-5_4_2 directory and you should be golden.
You had to add "fullpath/WinNTL-5_4_2/include" in you include path of your compiler (either by -I for gcc or in the include path list of a visual studio project)
Expecting that ctools.h exists in ".../WinNTL-5_4_2/include/NTL"
In my current project I have separated my class files and my header files. My project structure currently looks like this:
Project
Source
src
class1.cpp
class2.cpp
main.cpp
Header
include
class1.h
class2.h
My problem is that I do not know how to include the header files into the class files. Am I unable to link to headers that are not at the same level or in a child folder? Or is there some way to go from the project root and work my way down? For instance:
#include "Project/Headers/include/class1.h" inside the class1.cpp file
Assuming you want class1.cpp to include class1.h you would do something like this
#include "../../Header/class1.h"
The .. tells the tells the OS to jump 1 directory up when the compiler asks for the file.
You need to indicate the include path <the directory containing Project> to your compiler so that the compiler is able to find the included headers. Using gcc, you could use -I option, and using visual studio, you could use /I.
I had a very similar problem where my compiler could not find the header with a code::blocks C++ project (same file structure as OP) .
This worked for me:
#include "../include/class1.h"
I'm quite new in C++ after few years in Java and eclipse, I got little bit confusing using code::blocks, no autogenerate setter/getter and also implement interface :D.
I wanna ask about code structure in code::blocks, I create new console application, my header will be put to Headers/include folder called Employee.h, then .cpp will be put to src folder.
Now I create main class (I put outside of src folder) who will call the header, I just append the include code like this :
#include "Employee.h"
sure then the errors appeared after compiling:
error : Employee.h: No such file or directory.
how to link the header to the main class properly?
this is my folder structure :
updated :
It works, my include folder needs to be added on build options.
Really thanks
You need to add your include directory to your compiler's include path. This is going to be compiler-specific. e.g., if your structure is:
code
code/src
code/include
and you're running g++ from a terminal in the 'code' directory, you'd need to run (assuming your .cpp is Employee.cpp):
g++ -Iinclude src/Employee.cpp
I suspect you're running some sort of IDE, though: if so, do a search in its help for "include path" and it should tell you how to set it up correctly.
If you want to include your employee.h you must #include "employee.h" not Employee.h. Those are two different files.
You shouldn't be adding include paths to your build options for header files that are actually part of your project. It didn't find the header file from the EmployeeTest.cpp because you didn't use the full relative path.
You need:
#include "include/Employee.h"
You should only be adding include paths to your compiler for additional libraries that aren't added to the typical /usr/local/include or /usr/include directories.