1

I have a library in c one of the files has name something like this :

template.h

but inside the code call the header in this way

#include "template/template.h"

I have not file in this name template/template.h in the folder. Is that the same file or what that mean? because when run the code that call "template/template.h" I got on template/template.h: No such file or directory

lena
  • 730
  • 2
  • 11
  • 23
  • 1
    Do you have a folder named `template`? If not, remove the `template/`. – Bob__ May 28 '23 at 17:55
  • First of all please read [What is the difference between #include and #include "filename"?](https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename?rq=2) – Some programmer dude May 28 '23 at 17:57
  • 1
    Then please note that `#include "template/template.h"` will cause the compiler to search for the `template/template.h` directory-file pair. It's the actual hierarchy as laid out on the drive itself. – Some programmer dude May 28 '23 at 17:58
  • @Bob__ , Yes I have folder named template, yes now I understand that mean the folder name and the file name, is that correct? – lena May 28 '23 at 17:59
  • Where is the directory `template` located? In the same directory as the source-file you're trying to compile? In one of the system directories that the compiler automatically searches? Perhaps you need to tell the compiler where the `template` directory is located? For example with the `-I` (upper-case i) option (for GCC and Clang). – Some programmer dude May 28 '23 at 18:00
  • @Someprogrammerdude, yes in the same directory as the source-file – lena May 28 '23 at 18:03
  • 2
    Is the *file* `template.h` in the same directory, or the *sub-directory* `template`? Can you please [edit] your question to try and show the directory hierarchy? – Some programmer dude May 28 '23 at 18:06
  • 1
    Succinctly, if the header file is `/home/someone/project/template/template.h`, and your code contains `#include – Jonathan Leffler May 28 '23 at 18:45

2 Answers2

0

The difference between headers that look like

#include "template.h"

and those that look like

#include <template/template.h>

is that the earlier requires that header file to exist in the same folder as the source file while the later needs the header file added to the environment via adding the paths to the include and lib folders of the library associated with that header.

Son of Man
  • 1,213
  • 2
  • 7
  • 27
-1

First of all, you need to specify the file path correctly. If there is a file in a directory called "template" and the file name is 'template.h', then you will specify the name like this: #include <template/template.h> Also, you will write header in #include if it is in project files or in the compiler's 'include' Directory. Also, check spelling; there maybe some mistake or you have not mentioned the path correctly, like if you have a project and its path is "/project/template/template.h".

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 4
    [What is the difference between #include and #include "filename"?](https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename?rq=2) `#include – Some programmer dude May 28 '23 at 18:05