1

all, I was compiling a C program with OpenMP. It's my first time to use makefile. When excuting "make", the gcc reports the error make: * No rule to make target omp.h', needed bysmooth.o'. Stop. However the omp.h is in the /usr/lib/gcc/i686-linux-gnu/4.6/include/omp.h , I am wondering how to fix it. Could anyone help me? Thank you.

CC=gcc
CFLAGS = -fopenmp

all: smooth

smooth: smooth.o ompsooth.o
    $(CC) $(CFLAGS) -o smooth smooth.o ompsmooth.o

ompsmooth.o: ompsmooth.c assert.h stdio.h stdlib.h omp.h ompsmooth.h
    gcc $(CFLAGS) ompsmooth.c

smooth.o: smooth.c ompsmooth.h omp.h stdio.h stdlib.h string.h sys/types.h sys/stat.h     fcntl.h
    gcc $(CFLAGS) smooth.c

clean:

    rm *.o
    rm smooth
Robert
  • 2,189
  • 6
  • 31
  • 38

1 Answers1

5

Unless you're expecting your standard header files to change, the simplest solution is just to remove them from the prerequisite list(s).

If you don't want to do the above, then you'll either need to specify the complete path to omp.h, or use the VPATH mechanism.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • So, just like this?ompsmooth.o: ompsmooth.c gcc $(CFLAGS) ompsmooth.c smooth.o: smooth.c gcc $(CFLAGS) smooth.c – Robert Feb 17 '13 at 18:54
  • what ever started this practice anyhow? the old X sources were even worse. – technosaurus Feb 17 '13 at 18:56
  • You got it. If the header files do change, then make won't know it should rebuild your source, but so it goes. A variety of build tools know how to automatically scan your .c file and create header dependencies for you, but not the default make you get with Linux. If you prefer to get gung-ho about it, you can find a way to twist old make's arm into doing this for you: http://scottmcpeak.com/autodepend/autodepend.html – Ron Burk Feb 17 '13 at 18:57
  • @Robert: Sort of. You'll probably want to retain the dependency on **your** header files (ompsmooth.h, etc.), otherwise stuff won't be recompiled if you change them. On an unrelated note, you can simplify the rule with *automatic variables*: `gcc $(CFLAGS) $<`. – Oliver Charlesworth Feb 17 '13 at 18:58
  • @technosaurus: What practice? – Oliver Charlesworth Feb 17 '13 at 18:58
  • @OliCharlesworth: using individual headers as dependencies. I get wanting to rebuild if they change, but there has to be a better way... $INC_PATH/*.h maybe? ... or just omission. The old xfree86 sources used makedeps to add a ton of header dependencies to each object, some of which are unnecessary and caused build failure for no reason. – technosaurus Feb 17 '13 at 19:10
  • @technosaurus, this style makes sense for complex pieces of code with constantly evolving data structures and many things implemented as macros or static functions in the headers. XFree86 sounds like a good candidate for being such kind of code. Nowadays generation of monstrous Makefiles with huge header dependency lists is simply automated by `GNU autotools`. – Hristo Iliev Feb 18 '13 at 13:33