I would like to compile a code that consists of several .cpp files. Each file I would like to be compiled with different flags (for example -fopenmp for parallelization). The first target is the link between the output files into a universal executable.
For example
exec: $(OBJS)
$(CC) -I$(INCLDIR) -I$(INCLDIR) $(CFLAGS) -o exec $(OBJS) -L$(LIBPATH) $(LDFLAGS)
Let's assume that in objects some targets like these are included:
obj1.o: obj1.cpp $(INCLFILE)
$(CC) $(CFLAGS1) -c obj1.cpp -o obj1.o
obj2.o: obj2.cpp $(INCLFILE)
$(CC) $(CFLAGS2) -c obj2.cpp -o obj2.o
with CFLAGS1 or CFLAGS2 being -fopenmp. Even if I set CFLAGS1 or CFLAGS2 equal to -fopenmp but not setting CFLAGS equal to -fopenmp, an error appears about not finding the corresponding files. When I set CFLAGS equal to -fopenmp the problem dissappears. So, in the main executable target, should all the flags used by any function included? And then of course used in individual object?