I am trying to customize the build process using make files for the C ++ plugin I'm working on. I am wondering if there is a way to make g ++ compile the source files found in another directory. My motivation for this is to not specify a relative path for each source file, as I explain below.
The structure of my project looks like this:
MyPlugin --> src --> Foo.cpp --> Foo.h --> Bar.cpp --> Bar.cpp --> build --> Makefile
The following is a stripped-down version of my current Makefile:
SRC_PATH=../src OUT_PATH=../bin VPATH=${SRC_PATH} FILES=Foo.cpp Bar.cpp CC=g++ CFLAGS=-Wall -shared all: mkdir -p ${OUT_PATH} ${CC} ${CFLAGS} -I${SRC_PATH} ${FILES} -o ${OUT_PATH}/MyPlugin.so
By doing this, I try to avoid defining the FILES variable, as shown below:
FILES=../src/Foo.cpp ../src/Bar.cpp
When I tried to run make all , g ++ gave me an error. It appears that the path specified with the -I flag is only used to search for #include d files.
g++: Foo.cpp: No such file or directory g++: Bar.cpp: No such file or directory
I cannot use wildcards ( *.cpp ) because I do not always want all the files to be compiled. Another alternative is to cd in the src directory, as mentioned here , and run g ++ from there, but this only works for me if all the files are in the same one (I need the output file to be the only .so file). I also tried setting the PATH environment variable, but it showed no effect.
I went through the g ++ help system, make documentation, and looked at StackOverflow posts like https://stackoverflow.com/questions/10010741/g-compile-with-codes-of-base-class-in-a-separate-directory and gcc / g ++: "There is no such file or directory" , but could not find a solution that I could use. Could you suggest me a suitable approach to this problem?
Change Perhaps this example is misleading. In this stripped-down example, I have all the source files in one directory, but in my actual project, I have several subdirectories and several files in each directory. Thus, although the cd in the src directory works in my example above, it will not work in my actual project (or at least I would like to know how it will work).