Suppose you have have a makefile
containing two targets as in the following:
# targetA
X86CPPTARGET += targetA
targetA,SRCS = FILEA.cpp FILEB.cpp commonFile.cpp
targetA.so,DEPSOL = libUsedByCommon1.cpp
targetA,CPPFLAGS += -Ifakeinclude -std=c++11
# tartargetBgetA
X86CPPTARGET += targetB
targetB,SRCS = FILEC.cpp FILED.cpp commonFile.cpp
targetA.so,DEPSOL = libUsedByCommon2.cpp
targetB,CPPFLAGS += -std=c++11
targetA
and targetB
share a file, namely, commonFile.cpp
which contains a number of #include
d headers.
commonFile.o
is created only once by GNU make and reused during the compilation of targetB
.
The CPPFLAGS present in targetA
makes the compiler use an include that contains more symbols that the one that is in the default include directory. libUsedByCommon2
does not export all the additional symbols that are contained in the header in the fakeinclude
directory and at link time, this results in undefined reference
.
The workaround I am usingat the moment is to create a symbolic link to commonFile.cpp
and use that in my makefile
in only one of the target.
# targetA
X86CPPTARGET += targetA
targetA,SRCS = FILEA.cpp FILEB.cpp commonFile.cpp
targetA.so,DEPSOL = libUsedByCommon1.cpp
targetA,CPPFLAGS += -Ifakeinclude -std=c++11
# tartargetBgetA
X86CPPTARGET += targetB
targetB,SRCS = FILEC.cpp FILED.cpp **commonFile_symbolic_link.cpp**
targetA.so,DEPSOL = libUsedByCommon2.cpp
targetB,CPPFLAGS += -std=c++11
Is there a cleaner solution to this problem?
Is there a way to force GNU make to recompile commonFile.cpp
when a different include path is being used?