0

I have a bunch of C files and header files in the folder. When I compile the C files with MinGW compiler, it shows that there is no such file or directory. But I have all the files in the same folder. How do I get them to compile?

I have attached the code for your reference (file computil.c):

#include <stdio.h>
#include <computil.h>
#include <dataio.h>

int getc_skip_marker_segment(const unsigned short marker, unsigned char **cbufptr, unsigned char *ebufptr)
{
  int ret;
  unsigned short length;

  ret = getc_ushort(&length, cbufptr, ebufptr);
  if(ret)return(ret);
  length -= 2;
  if(((*cbufptr)+length) >= ebufptr)
  {
    fprintf(stderr, "ERROR : getc_skip_marker_segment : ");
    fprintf(stderr, "unexpected end of buffer when parsing ");
    fprintf(stderr, "marker %d segment of length %d\n", marker, length);
    return(-2); }(*cbufptr) += length; return(0);
  }
}

I am compiling it with gcc -c computil.c.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Sathish
  • 11
  • 2
  • 1
    Try posting some code. May it helps. Also, put the full error message too. – Jack Nov 02 '12 at 04:53
  • When compiling the file, the error dislpays computil.c:18:22: fatal error: computil.h: No such file or directory compilation terminated.But i am having the computil.h file in the same directory. – Sathish Nov 02 '12 at 05:04
  • @Sathish Please edit your question and post the code in the question. Also post the command you are using to compile. – CCoder Nov 02 '12 at 05:16
  • 1
    Note that if `computil.h` and `dataio.h` files are in the same directory, there is no reason to use `<>` instead of `""` check out http://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename – Jack Nov 02 '12 at 05:39

2 Answers2

1

I believe you are going to have to add the current directory to the list of "standard places" that gcc uses. When you use instead of "computil.h", a Unix-style compiler won't look in the current directory.

For a quick fix to that, add -I. to the gcc command line. (dash, capital eye, period): gcc -I. computil.c

If that's an application include file intended to be found where the source files are found, then you should change the include line to: #include "computil.h"

That's one of the valuable nuances from Classic C that got lost in the ANSI standardization process. Standard C lets the compiler decide if there's a difference or between <> bracketed and "" quoted headers. It makes a difference in Unix and GNU ("GNU's Not Unix!"), well, pretty much is Unix only better in places.

Mike Housky
  • 3,959
  • 1
  • 17
  • 31
  • Thank you Mike Housky! I have Stepped up, but there are some internal errors i will look over it. – Sathish Nov 02 '12 at 05:50
  • We cant able to compile the file without main function? – Sathish Nov 02 '12 at 05:58
  • Yes you need a `main` function, because that's the point where the program should start. If you don't have that, the compiler doesn't know what should happen if you start the program. – Juri Robl Nov 02 '12 at 08:02
0

To put it simple, #include <header.h> means "search in the compiler's own library directories, while #include "header.h means "search in the same directory as the .c file that made the #include".

I don't believe gcc has any library headers named computil.h and dataio.h, so the code won't compile.

Lundin
  • 195,001
  • 40
  • 254
  • 396