【发布时间】:2020-10-12 17:59:37
【问题描述】:
我有一个在 openmp 中完成的障碍的模块化实现。我有一个我想链接的测试工具。目录如下所示:
Project/
-Tests
-openmp_tournament
-test_openmp_tournament.cpp
-OpenMP
-tournament.cpp . //barrier implementation
-tournament.h
现在,两个 .cpp 文件都在 Project/OpenMp/ 中包含了针对锦标赛.h 的标头。这个想法是编译两者,然后以模块化方式将它们链接在一起(因为我有各种我想测试的实现)。我的 makefile 看起来像这样:
PATH_TO_OPENMP = ../../OpenMP/
#OpenMP Flags Etc.
OMPFLAGS = -fopenmp -DLEVEL1_DCACHE_LINESIZE=`getconf LEVEL1_DCACHE_LINESIZE`
OMPLIBS = -lgomp
CC = g++
CPPFLAGS = -MMD -MP # enables automatic dependency tracking
CFLAGS = -Wall -Wextra -I$(PATH_TO_OPENMP) $(OMPFLAGS) -std=c++11
LDLIBS = $(OMPLIBS)
COMPILE = $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDLIBS) -o $@
COMPILE_NOLINK = $(CC) -c $(CPPFLAGS) $(CFLAGS) $< $(LDLIBS) -o $@
all: tournament_openmp.a
# link all files into one binary
tournament_openmp.a: tournament.o test_openmp_tournament.o
$(COMPILE)
# compile only each source file and mark as dependent
%.o: $(PATH_TO_OPENMP)%.cpp %.d
$(COMPILE_NOLINK)
# Empty pattern rule to match dependency (*.d) files (i.e. makefiles),
# so make won't fail if dependency doesn't exist
%.d: ;
# Mark dependency files as precious so they won't be deleted as intermediates
.PRECIOUS: %.d
# The list of all source files I want to track dependencies for
SOURCES=$(wildcard *.cpp)
# Include any dependency files that exist, and
# suppress error message for ones that don't yet (via hyphen)
-include $(SOURCES:.cpp=.d)
.PHONY: clean
clean:
rm -rf *.o *.d *.a *_openmp *_mpi
当我运行 Make 时,我收到以下错误,我不确定如何解决它。它找不到 test_openmp_tournament.cpp 文件的锦标赛.h:
a@ubuntu:~/Documents/Project/Tests/openmp_tournament$ make all
g++ -c -MMD -MP -Wall -Wextra -I../../OpenMP/ -fopenmp -DLEVEL1_DCACHE_LINESIZE=`getconf LEVEL1_DCACHE_LINESIZE` -std=c++11 ../../OpenMP/tournament.cpp -lgomp -o tournament.o
g++ -MMD -MP -c -o test_openmp_tournament.o test_openmp_tournament.cpp
test_openmp_tournament.cpp:51:10: fatal error: tournament.h: No such file or directory
51 | #include "tournament.h"
【问题讨论】: