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.
Related
So there are 1 files that I want to link together, Core.h and Events.h.
Core.h is in a folder called DevEngine and the Events.h file is in a folder called Events witch is inside DevEngine.
Here are the file directorys:
Core.h = src/DevEngine/Core.h
Events.h = src/DevEngine/Events/Events.h
I have added a #include "DevEngine/Core.h" : Cannot open include file: 'DevEngine/Core.h': No such file or directory DevEngine. I don't know where I have went wrong.
I have tried: #include "../DevEngine/Core.h". That still gives me a error.
You can do #include "../Core.h".
You can also set the directories the compiler uses to search for the header files (-I option in gcc) and then use paths to those files relative to one of those directories. (See for example gcc documentation on search paths.)
This could be done differently depending on the way you are building the project.
For Visual Studio, look in this thread.
For CMake, use include_directories.
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'm fairly new to programming using linux so forgive me for any dumb errors I might make in my question but basically I am trying to compile using the terminal (C++) and my code in a .txt file however I keep getting a fatal error that my header file can't be found? When I try to type
g++ -o test main.cpp header.h
I get the error stating "header.h: no such file or directory" in the terminal. I've ensured that both the cpp and header files are in the same directory but no luck there. I've also used
#include <"header.h">
in my main.cpp and header file to try different fixes. I've researched and looked at different answers but no fixes either. Any suggestions?
#include <"header.h">
Use either
#include <header.h>
will lookup the standard include directories for these header files first
or
#include "header.h"
will lookup all include directory pathes specified with the preprocessor options
but don't mix these up.
Also you don't need to specify the header in the compiler command line
g++ -o test main.cpp header.h
# ^^^^^^^^ omit this
That's what the #include statement in your code is for.
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 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?