0

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?

Barry
  • 286,269
  • 29
  • 621
  • 977
dimpep
  • 63
  • 1
  • 6
  • Please provide a [minimal, complete, verifiable example](http://www.stackoverflow.com/help/mcve). In particular, how is `OBJS` defined? What is `INCLFILE`? etc. – Barry Jun 25 '15 at 19:42
  • You need to provide the -fopenmp flag for linking the programm, too. That way the linker knows that it needs OpenMP runtime library as well. Have a look at the answer here: http://stackoverflow.com/questions/12002304/how-to-compile-openmp-using-g – Hauke S Jun 25 '15 at 19:42
  • So, the first target is the linking target? – dimpep Jun 25 '15 at 20:26
  • Yes "exec:" is where the object files are linked to build the executable. – Hauke S Jun 25 '15 at 20:36
  • Thank you for all the answers – dimpep Jul 17 '15 at 07:58

0 Answers0