8

I want to compile a C program in gcc which has my 2 header files.

I am using the command:

gcc UDP_Receive.c -o UDP_Receive -lm

to compile it but I get an error stating "UDP_Data.h: No such file or directory"

How can I tell the compiler to include these header files?

Header Files:

#include "UDP_Data.h"

#include "Crypt.h"

Thanks, Ritesh

Community
  • 1
  • 1
Ritesh Banka
  • 173
  • 1
  • 1
  • 13
  • Dupe of http://stackoverflow.com/questions/973146/how-to-include-header-files-in-gcc-search-path – GrahamS Mar 02 '11 at 10:01

2 Answers2

7

Use -Idirectory to add include paths, or make your #include statement use relative paths.

EDIT: Also be aware that #include filenames are case sensitive on many platforms.

EDIT2: Use #include "UDP_Data.h" not #include <UDP_Data.h>

Erik
  • 88,732
  • 13
  • 198
  • 189
5

You have told the compiler to include that file, with a line like this:

#include "UDP_Data.h"

the problem is that the compiler can't find that file, and don't forget that some platforms are case sensitive when it comes to filenames so "UDP_data.h" is not the same file as "UDP_Data.h". The compiler will serach in a few places by default, but you will need to add extra directories to its search by using command line options. The exact option will depend on the compiler, for gcc it's:

-I<directory>
Skizz
  • 69,698
  • 10
  • 71
  • 108
  • @Jim: How would you get that error if that line wasn't in the source file? (Apart from extra command line options of course!) – Skizz Mar 02 '11 at 10:01