I have a project using autoconf and automake with following structure:
- /
- src/
- class.h
- class.cpp
- test/
- class_unittest.cpp
- src/
In class_unittest.cpp I include class.h in the source file and on compile also the class.cpp file. In automake config for test I add ../src as a new include path in AM_CPPFLAGS = -I../src/ definition and refer to the class.cpp relatively in SOURCES definition.
It works great when I'm building the software from the root directory, but if I try to do a VPATH build by creating a dir foo in root and in the dir call ../config开发者_开发问答ure && make I will get missing header class.h errors when trying to compile class_unittest.cpp.
So how do I share the header for testing to avoid this problem?
You can use the srcdir variable to refer to the equivalent source directory in a VPATH build.
AM_CPPFLAGS = -I$(srcdir)/../src
精彩评论