c++ - Makefile does not find object file -


i want object files created in subdirectory , not makefile lives. so, saw answer, couldn't apply case, tried this:

objs    = main.o    io.o    alloc.o communication.o objsdir    =   obj source  = main.cpp  src/io.cpp  src/alloc.cpp   src/communication.cpp header =    headers/io.h    headers/alloc.h headers/communication.h out     =       test cxx     = ../../mpich-install/bin/mpic++ cxxflags    =   -i../../intel/mkl/include   -wl,--start-group    -wl,--end-group    -lpthread   -lm -ldl    -wall ldflags   =       ../../intel/mkl/lib/intel64/libmkl_scalapack_lp64.a       -wl,--start-group       ../../intel/mkl/lib/intel64/libmkl_intel_lp64.a ../../intel/mkl/lib/intel64/libmkl_core.a  ../../intel/mkl/lib/intel64/libmkl_sequential.a    -wl,--end-group ../../intel/mkl/lib/intel64/libmkl_blacs_intelmpi_lp64.a -lpthread       -lm     -ldl  all:    $(objsdir)  $(out)  $(objsdir):     mkdir   $(objsdir)  $(out): $(objs)     $(cxx)  $(objs) -o  $(out)  $(cxxflags) $(ldflags) #   make    -f  makefile    clean  # create/compile individual files >>separately<< $(objsdir)/main.o:    main.cpp     $(cxx)  -c  main.cpp    $(cxxflags)  $(objsdir)/io.o:    src/io.cpp     $(cxx)  -c  src/io.cpp  $(cxxflags)  $(objsdir)/alloc.o:    src/alloc.cpp     $(cxx)  -c  src/alloc.cpp   $(cxxflags)  $(objsdir)/communication.o:    src/communication.cpp     $(cxx)  -c  src/communication.cpp   $(cxxflags)  .phony: clean clean:     rm  -rf *.o 

and getting:

gsamaras@pythagoras:~/konstantis/cholesky$ make ../../mpich-install/bin/mpic++ -i../../intel/mkl/include        -wl,--start-group        -wl,--end-group        -lpthread       -lm     -ldl    -wall   -c -o main.o main.cpp make: *** no rule make target 'io.o', needed 'test'.  stop. 

i have src folder, .cpp files live (except main.cpp, lives in same directory makefile) , headers directory, header files live.


edit

i modified first 2 lines, such:

objsdir    =   obj objs    = $(objsdir)/main.o $(objsdir)/io.o $(objsdir)/alloc.o  $(objsdir)/communication.o 

and getting:

g++: error: obj/main.o: no such file or directory ... 

the problem lies fact object files still generated in main directory!

you want change lines invoke compiler from:

$(objsdir)/io.o:    src/io.cpp     $(cxx)  -c  src/io.cpp  $(cxxflags) 

to:

$(objsdir)/io.o:    src/io.cpp     $(cxx)  -c  src/io.cpp  $(cxxflags) -o $@ 

note $@ automatic variable corresponds target file being created. in above case obj/io.o. -o specifies output filename.

furthermore while unrelated question 1 of nice things placing build artifacts separate directory cleaning easier:

clean:     rm -rf $(objsdir) $(out) 

also, final note if ever wish parallel build have issue object files rely on build directory. there couple solutions including calling mkdir -p objs before every compiler invocation or setting directory dependency built if not exist.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -