過程中發現了錯誤的目標文件首先讓我介紹我的文件夾結構的GNU-make編譯
| SourceCode folder
| | Build folder
| | | makefile
| | | buildrules.mak
| | Integration_Tests folder
| | | Subsystem_1_Test folder
| | | | buildfiles folder
| | | | test.cpp
| | | | makefile
| | Subsystem_1 folder
| | | buildfiles folder
| | | source1.cpp
| | | source2.cpp
| | | source3.cpp
| | | makefile
| | Subsystem_2 folder
| | | buildfiles folder
| | | source4.cpp
| | | source5.cpp
| | | source6.cpp
| | | makefile
所以在生成文件夾將通過調用較低編譯文件的所有子系統和集成測試生成文件。每個子系統創建一個可執行文件,每個子系統測試創建一個可執行文件buildfiles文件夾存儲依賴文件,目標文件和最終的可執行代碼。這些都是由makefile在構建時填充的。
集成測試使用下的測試子系統代碼構建和構建子系統爲好,但在本地子系統文件夾中。每個子系統集成測試的生成文件使用vpath來設置子系統文件夾的路徑。即,對於子系統測試VPATH是:
vpath = ../../Subsystem_1
我沒有在我面前確切的代碼,但編譯行基本上是定義爲以下,其中生活在buildrules.mak和所有使用makefile文件
./buildfiles/%.o : %.cpp
compile the code
所以我看到的問題是,當我建立我的集成測試,而應該在技術上建立和鏈接罰款,這似乎是找到目標文件中Subsystem_1 /構建文件的文件夾,並說,子系統代碼被構建並且只構建test.cpp。
這是一個錯誤,因爲測試有建立定義定義,它需要重新構建子系統正確的測試。
現在,如果子系統尚未建成,即沒有目標文件,然後我的集成測試將建立文件,預計在把目標文件在本地集成測試構建文件的文件夾。
我相信這是由於在VPATH集成測試make文件被設置。它似乎搜索子系統1文件夾的對象文件,並不幸找到它們。
如果我在構建Subsystem_1文件夾並且測試已經建好,我沒有看到任何問題,這大概是因爲Subsystem_1中的vpath沒有測試的路徑,它不應該這樣做。
我似乎無法弄清楚如何解決這個問題本質上是一個文件路徑問題。看起來我需要更具體地瞭解哪些buildfiles文件夾需要在編譯行中匹配,但我沒有路徑。
我不能用戶$(CURDIR),因爲這是一個絕對路徑,我被告知,我不得不使用相對路徑。我想有問題的路徑有空格和括號。在使用它之前我可能會逃脫它們,但有人告訴我必須用相對路徑做所有事情。
我在buildrules.mak一個變量,它是從執行作出buildrules.mak目錄的相對路徑。
BUILD_FOLDER_PATH := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
有沒有一種方法來解析$(CURDIR)讓我像sourcecod一個共同的文件夾:這是使用實現的呢?然後,可以這樣做:
$(BUILD_FOLDER_PATH)/../[path extracted from $(CURDIR)]/buildfiles
所以,如果$(CURDIR)爲C:/ A/B /源碼/ Integration_Tests/Subsystem_Test然後我可以提取 「/ Integration_Tests/Subsystem_Test」 出它放入上述路徑。
如果還有其他方法可以做到這一點,我也樂於接受建議。
謝謝!
編輯: 測試的Makefile
# used when make is executed without any arguments, must be first thing in the file
all: default
##########################################################################
# #
# Source Files #
# #
##########################################################################
# These files are not shared with other processes
CPP_SRC := \
cmdclientmq.cpp \
cmdservermq.cpp \
ConvertUTF.cpp \
crcutil.cpp \
deka_cpu.cpp \
deka_debug.cpp \
deka_file.cpp \
deka_mutex.cpp \
deka_sem.cpp \
deka_serial.cpp \
deka_sharedMem.cpp \
deka_thread.cpp \
deka_time.cpp \
deka_timer.cpp \
encryptionutils.cpp \
exec_client.cpp \
logclient.cpp \
procstatus.cpp \
syserror.cpp
# These files are shared with other processes
EXPORTED_SRC :=
# These files are analyzed by the manifest tool
# Not all header files are listed because the manifest tool automatically checks if there is a .h file
# with the same name as a .cpp file
MANIFEST_SRC := \
$(CPP_SRC) \
$(EXPORTED_SRC)
##########################################################################
# #
# makefile includes #
# #
##########################################################################
# Basic compiler definitions, must be listed after source files
include ../../build/buildrules.mak
##########################################################################
# #
# build flags #
# #
##########################################################################
# Position Independent Code flag
GCC_FLAGS += -fPIC
##########################################################################
# #
# Subsystem build paths #
# #
##########################################################################
# directory include paths need for files external to the current subsystem
INCDIRS := \
$(EXECUTIVE_INC_PATH) \
$(LOGGER_INC_PATH) \
$(OS_INTERFACE_INC_PATH) \
$(SYSERROR_INC_PATH) \
$(SYSTEMDEFS_INC_PATH) \
$(UTILITIES_INC_PATH)
# list of directories in the current subsystem
VPATH := \
$(EXECUTIVE_PATH)/exec_client \
$(EXECUTIVE_PATH)/exec_core \
$(LOGGER_PATH)/main \
$(OS_INTERFACE_PATH) \
$(SYSERROR_PATH) \
$(UTILITIES_PATH)
##########################################################################
# #
# Targets #
# #
##########################################################################
# default target to build and link the subsystem code
default: $(LIB_DIR)/libpycommon.a
@echo
@echo Common Library default: Done.
@echo ----------------------------------------------------------------------------
@echo
# remove the subsystem build folders and create the neccessary directories
clean: REMOVE_INTEGRATION_DIRS CREATE_INTEGRATION_OUTPUT_DIRS
@echo
@echo Common Library clean: Done.
@echo ----------------------------------------------------------------------------
@echo
##########################################################################
# #
# Build Rules #
# #
##########################################################################
# Do not build archives or call ranlib in parallel:
# http://www.gnu.org/software/make/manual/make.html#Archive-Pitfalls
.NOTPARALLEL:
$(LIB_DIR)/libpycommon.a: $(LIB_DIR)/libpycommon.a($(CPP_OBJS))
$(RANLIB) $(LIB_DIR)/libpycommon.a
buildrules.mak
# get relative path to the current makefile by examining the $(MAKEFILE_LIST), which is
# dynamically updated. Determine the number of words in $(MAKEFILE_LIST) and grab the
# last word. Then extract the directory path up to the found last word.
# the include order is important, do not adjust
include $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))toolset.mak
include $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))common.mak
##########################################################################
# #
# Build rules for creating subsystem and project folder structure #
# #
##########################################################################
CREATE_SUBSYSTEM_OUTPUT_DIRS :
[email protected] Creating directory: $(BUILD_PATH)
[email protected] -p $(BUILD_PATH)
[email protected] Creating directory: $(DEP_DIR)
[email protected] -p $(DEP_DIR)
[email protected] Creating directory: $(OBJ_DIR)
[email protected] -p $(OBJ_DIR)
[email protected] Creating directory: $(LINT_DIR)
[email protected] -p $(LINT_DIR)
[email protected] Creating directory: $(CCK_DIR)
[email protected] -p $(CCK_DIR)
[email protected] Creating directory: $(UNCRUST_DIR)
[email protected] -p $(UNCRUST_DIR)
[email protected] Creating directory: $(MET_DIR)
[email protected] -p $(MET_DIR)
REMOVE_SUBSYSTEM_DIRS :
[email protected] ----------------------------------------------------------------------------
[email protected] Removing directory: $(BUILD_PATH)
[email protected] ----------------------------------------------------------------------------
[email protected] -rf $(BUILD_PATH)
[email protected]
CREATE_PROJECT_OUTPUT_DIRS :
[email protected] Creating directory: $(IMAGE_DIR)
[email protected] -p $(IMAGE_DIR)
[email protected] Creating directory: $(PROJECT_OBJ_DIR)
[email protected] -p $(PROJECT_OBJ_DIR)
REMOVE_PROJECT_OUTPUT_DIRS :
[email protected] Removing directory: $(DIALYSIS_DIR)
[email protected] -rf $(DIALYSIS_DIR)
[email protected] Removing directory: $(ETC_DIR)
[email protected] -rf $(ETC_DIR)
[email protected] Removing directory: $(IMAGE_DIR)
[email protected] -rf $(IMAGE_DIR)
[email protected] Removing directory: $(PROJECT_OBJ_DIR)
[email protected] -rf $(PROJECT_OBJ_DIR)
[email protected] Removing directory: $(TAR_DIR)
[email protected] -rf $(TAR_DIR)
[email protected] Removing directory: $(QUAL_DIR)
[email protected] -rf $(QUAL_DIR)
[email protected] Removing directory: $(PYTHON_OUT)
[email protected] -rf $(PYTHON_OUT)
##########################################################################
# #
# Integration Build Rules #
# #
##########################################################################
CREATE_INTEGRATION_OUTPUT_DIRS :
[email protected] Creating directory: $(BUILD_PATH)
[email protected] -p $(BUILD_PATH)
[email protected] Creating directory: $(DEP_DIR)
[email protected] -p $(DEP_DIR)
[email protected] Creating directory: $(OBJ_DIR)
[email protected] -p $(OBJ_DIR)
[email protected] Creating directory: $(LIB_DIR)
[email protected] -p $(LIB_DIR)
[email protected] Creating directory: $(PYTHON_OUT)
[email protected] -p $(PYTHON_OUT)
REMOVE_INTEGRATION_DIRS :
@echo Removing directory: $(BUILD_PATH)
@rm -rf $(BUILD_PATH)
@echo
##########################################################################
# #
# Unit Test Build Rules #
# #
##########################################################################
CREATE_UNIT_TEST_OUTPUT_DIRS :
[email protected] Creating directory: $(BUILD_PATH)
[email protected] -p $(BUILD_PATH)
[email protected] Creating directory: $(DEP_DIR)
[email protected] -p $(DEP_DIR)
[email protected] Creating directory: $(OBJ_DIR)
[email protected] -p $(OBJ_DIR)
REMOVE_UNIT_TEST_DIRS :
@echo Removing directory: $(BUILD_PATH)
[email protected] -rf $(BUILD_PATH)
@echo
##########################################################################
# #
# Create dependancy files from all cpp files #
# #
##########################################################################
# convert the file extensions from .o to .d and strip the relative path and add the dependancy path
DEP_OBJS = $(patsubst %.o, $(DEP_DIR)/%.d, $(Call_OBJ))
##########################################################################
# #
# Create object files from all cpp files #
# #
##########################################################################
# convert the file extensions from .cpp to .o
Cxx_OBJS = $(CPP_SRC:.cpp=.o)
# strip the relative path and add the object path
CPP_OBJS = $(patsubst %.o, $(OBJ_DIR)/%.o, $(Cxx_OBJS))
##########################################################################
# #
# Create object files from all exported files #
# #
##########################################################################
# Files needed by other subsystems
# convert the file extensions from .cpp to .o
Exx_OBJS = $(EXPORTED_SRC:.cpp=.o)
# strip the relative path and add the path to the subsystem object folder
EXPORTED_OBJ = $(patsubst %.o, $(OBJ_DIR)/%.o, $(Exx_OBJS))
# strip the relative path and add the project object folder
EXPORTED_OUT = $(patsubst %.o, $(PROJECT_OBJ_DIR)/%.o, $(Exx_OBJS))
##########################################################################
# #
# List of files within the subsystem #
# #
##########################################################################
# create the list of all files associated with this subsystem
Call_OBJ = $(Cxx_OBJS) $(Exx_OBJS)
##########################################################################
# #
# Files needed by Lint #
# #
##########################################################################
# convert the file extensions from .o to .lob and strip the relative path and add the lint path
LINT_OBJS = $(patsubst %.o, $(LINT_DIR)/%.lob, $(Call_OBJ))
##########################################################################
# #
# Interface Rules to create dependancy files from project source code #
# #
##########################################################################
# function used to create dependancy files
define DEPENDS_COMMAND
@echo
@echo ----------------------------------------------------------------------------
@echo -Depend: [email protected]
@echo ----------------------------------------------------------------------------
@$(CC_DEP) -MM -MT '$(OBJ_DIR)/$*'.o $(INCDIRS) $< > $ [email protected]
@$(SED) 's,\($*\)\.o[ :]*,\1.o $(LINT_DIR)/\1.lob [email protected] : ,g' < [email protected] > [email protected];
@rm -f [email protected]
endef
# rule to create dependency for C++ code
$(DEP_DIR)/%.d: %.cpp
$(DEPENDS_COMMAND)
##########################################################################
# #
# Interface Rules to compile project source code #
# #
##########################################################################
# function used to compile code
define COMPILE_COMMAND
@echo
@echo ----------------------------------------------------------------------------
@echo -Compiling: [email protected]
@echo ----------------------------------------------------------------------------
@$(CC) $(CPU_GCC_FLAGS) $(GCC_FLAGS) $(INCDIRS) $< -o [email protected]
endef
# build object files in subsytem ojbect folder for all cpp files
$(OBJ_DIR)/%.o: %.cpp
@$(COMPILE_COMMAND)
##########################################################################
# #
# Build exported object files and copy them to the build folder #
# #
##########################################################################
# move shared object files to the proper directory
$(EXPORTED_OUT): $(PROJECT_OBJ_DIR)/%.o : $(OBJ_DIR)/%.o
@echo
@echo Copying Shared File $< to [email protected] ...
@cp $< [email protected]
##########################################################################
# #
# Build Rules to link files to create the final executable #
# #
##########################################################################
# Commands for linking final executable [LINK_DB_LIBS vs LINK_LIBS]
define LINK_EXECUTABLE
@echo
@echo "**********************************"
@echo "**** Linux Linking [email protected]"
@echo "**********************************"
$(CC) $^ $(LINK_LIBS) $(LIB_FLAGS) -o $(IMAGE_DIR)/[email protected]
@$(DEKA_TOOLS)/imagecrc.exe $(IMAGE_DIR)/[email protected] 2>&1
@echo
@echo LINK_EXECUTABLE Completed
@echo ----------------------------------------------------------------------------
endef
# Commands for linking final executable for subsystems using the database [LINK_DB_LIBS vs LINK_LIBS]
define LINK_DB_EXECUTABLE
@echo
@echo "********************************************"
@echo "**** Linux Linking [email protected]"
@echo "********************************************"
@$(CC) $^ $(LINK_DB_LIBS) $(LIB_FLAGS) -o $(IMAGE_DIR)/[email protected]
@$(DEKA_TOOLS)/imagecrc.exe $(IMAGE_DIR)/[email protected] 2>&1
@echo
@echo LINK_DB_EXECUTABLE Completed
@echo ----------------------------------------------------------------------------
endef
define LINK_EXECUTABLE_INTEGRATION
@echo
@echo "**********************************"
@echo "**** Linux Linking [email protected]"
@echo "**********************************"
$(CC) $^ $(LINK_LIBS) $(LIB_FLAGS) -o $(PYTHON_OUT)/[email protected]
@$(DEKA_TOOLS)/imagecrc.exe $(PYTHON_OUT)/[email protected] 2>&1
@echo ----------------------------------------------------------------------------
endef
define LINK_EXECUTABLE_UNIT_TEST
@echo
@echo "**********************************"
@echo "**** Linux Linking [email protected]"
@echo "**********************************"
$(CC) $^ $(LINK_LIBS) $(LIB_FLAGS) $(CANTPP_LIB) -L$(GCC_LIB_PATH) -o $(OBJ_DIR_UT)/[email protected]
@echo ----------------------------------------------------------------------------
endef
##########################################################################
# #
# Build rules for Lint of C++ files #
# #
##########################################################################
# function used to lint C++ files
define LINT_COMMAND
@echo
@echo ----------------------------------------------------------------------------
@echo -Lint: $<
@echo ----------------------------------------------------------------------------
[email protected]$(LINT) -dRELEASE_BUILD -u -b $(LINT_SYS_DIRS) $(INCDIRS) $(LINT_RULES) '-passes(2)' '-oo([email protected])' '-os($(@D)/$(*F).txt)' $<
@$(PYTHON) $(LINT_PYTHON_SCRIPT) --out $(@D)/$(*F).txt --src $(CURDIR)/$<
endef
# rule to create lint output for C++ code
$(LINT_DIR)/%.lob: %.cpp
@$(LINT_COMMAND)
lint: $(LINT_OBJS)
@echo
@echo lint: Done.
@echo ----------------------------------------------------------------------------
lintclean:
@rm -rf $(LINT_DIR)
@mkdir $(LINT_DIR)
@echo
@echo lintclean: Done
@echo ----------------------------------------------------------------------------
##########################################################################
# #
# Build rules for Uncrustify of C++ files #
# #
##########################################################################
uncrustify: $(UNCRUST_DIR)
@python $(UNCRUST_PYTHON_FILE) $(UNCRUST_EXECUTABLE) -nooverwrite
@echo
@echo uncrustify: Done
@echo ----------------------------------------------------------------------------
uncrustifyclean:
@rm -rf $(UNCRUST_DIR)
@mkdir $(UNCRUST_DIR)
@echo
@echo uncrustifyclean: Done
@echo ----------------------------------------------------------------------------
##########################################################################
# #
# Build rules for Understand CodeCheck of C++ files #
# #
##########################################################################
codecheck.udb: $(CCK_DIR)
@echo
@cp -rf $(UND_RULES_ARCHIVE) $(UND_RULES)
@$(UND) create -db [email protected] -languages c++
@$(UND) -db [email protected] settings -c++MacrosAdd RELEASE_BUILD=1
@$(UND) add $(CURDIR) -db [email protected]
[email protected]$(UND) remove unittest -db [email protected]
@$(UND) analyze -all -db $(CURDIR)/[email protected] > $(CCK_DIR)/analyze.log 2>&1
@$(UND) -db $(CURDIR)/[email protected] codecheck -html $(CCK_RULES_FILE) $(CCK_DIR) > $(CCK_DIR)/codecheck.log 2>&1
@$(UPERL) $(UND_PERL_SCRIPT) $(CURDIR) -db [email protected]
@rm [email protected]
@echo
@echo codecheck: Done
@echo ----------------------------------------------------------------------------
codecheckclean:
@rm -rf $(CCK_DIR)
@mkdir $(CCK_DIR)
@echo
@echo codecheckclean: Done
@echo ----------------------------------------------------------------------------
##########################################################################
# #
# Build rules for Metrics/Complexity of C++ files using Understand #
# #
##########################################################################
metric.udb: $(MET_DIR)
@echo
@$(UND) create -db [email protected] -languages c++
@$(UND) -db [email protected] settings -c++MacrosAdd RELEASE_BUILD=1
@$(UND) settings -metricsShowDeclaredInFile on -db [email protected]
@$(UND) settings -metrics MaxNesting CyclomaticModified -db [email protected]
@$(UND) add $(CURDIR) -db [email protected]
[email protected]$(UND) remove unittest -db [email protected]
@$(UND) analyze -all -db [email protected] > $(UND_METRICS_LOG) 2>&1
@$(UND) metrics -db [email protected]
[email protected] -f metric.csv $(MET_DIR)/
@rm [email protected]
@echo
@echo metrics: Done
@echo ----------------------------------------------------------------------------
metricclean:
@rm -rf $(MET_DIR)
@mkdir $(MET_DIR)
@echo
@echo metricclean: Done
@echo ----------------------------------------------------------------------------
##########################################################################
# #
# Build Rules to create a manifest of static analysis tool results #
# #
##########################################################################
manifestall: manifestclean uncrustifyclean lintclean codecheckclean metricclean uncrustify codecheck.udb metric.udb
@$(MAKE) -j $(NUMBER_OF_PROCESSORS) lint
@python $(MANIFEST_SCRIPT_LOCATION) --cpp $(MANIFEST_SRC) --searchpath $(VPATH)
@echo
@echo manifestall: Done
@echo ----------------------------------------------------------------------------
manifest:
@python $(MANIFEST_SCRIPT_LOCATION) --cpp $(MANIFEST_SRC) --searchpath $(VPATH)
@echo manifest: Done
@echo ----------------------------------------------------------------------------
manifestclean:
@rm -f $(CURDIR)/manifest.csv
@echo manifestclean: Done
@echo ----------------------------------------------------------------------------
##########################################################################
# #
# Build rules for PyLint of Python files #
# #
##########################################################################
# TODO in the future
# rule to create lint output for Python code
#$(PYLINT_DIR)/%.pylint: %.py
# @echo ----------------------------------------------
# @echo -PyLint: $<
# @echo ----------------------------------------------
# @$(PYTHON) $(PYLINT) --include-ids=y --rcfile=$(PYLINT_CONFIG) $< > [email protected]
##########################################################################
# #
# Build rules for PEP8 (CodeCheck) of Python files #
# #
##########################################################################
# TODO in the future
# rule to create codecheck for Python code
#$(CCK_DIR)/%.pep8: %.py
# @echo ----------------------------------------------
# @echo PEP8: $<
# @echo ----------------------------------------------
# @$(PYTHON) $(PEP) --statistics --show-source --repeat $< > [email protected]
##########################################################################
# #
# Dependancy File Creation #
# #
##########################################################################
# alwawys try to create a dependancy file unless $(MAKECMDGOALS) is one of the listed targets
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),lint)
ifneq ($(MAKECMDGOALS),lintclean)
ifneq ($(MAKECMDGOALS),uncrustify)
ifneq ($(MAKECMDGOALS),uncrustifyclean)
ifneq ($(MAKECMDGOALS),codecheck.udb)
ifneq ($(MAKECMDGOALS),codecheckclean)
ifneq ($(MAKECMDGOALS),metric.udb)
ifneq ($(MAKECMDGOALS),metricclean)
ifneq ($(MAKECMDGOALS),manifestall)
ifneq ($(MAKECMDGOALS),manifest)
ifneq ($(MAKECMDGOALS),manifestclean)
include $(DEP_OBJS)
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
你所說的'vpath'不能解釋錯誤。如果你向我們展示'Subsystem_1_Test/makefile'和'buildrules.mak',這將有所幫助。 – Beta
我使用所需數據更新了原始文章 – Brian
您的'buildrules.mak'包含'toolset.mak'和'common.mak';這棵樹中有多少個文件,它們的總數有多大? (根據拼寫錯誤和多餘線條的混合來判斷,我認爲這是一個手寫Make代碼的混合體,可以生成或複製粘貼Make代碼,建立很長一段時間 - 技術術語是「大泥球」 - 所以修復它可能會很困難。) – Beta