Makefile导致编译错误

时间:2013-05-09 22:15:56

标签: c++ makefile g++ openmp nvcc

我正在尝试编译一个程序(不是我的):

make -f makefile

...使用以下makefile

# Compiler for .cpp files
CPP  = g++

# Use nvcc to compile .cu files
NVCC = nvcc
NVCCFLAGS = -arch sm_20 # For fermi's in keeneland

# Add CUDA Paths
ICUDA = /usr/lib/nvidia-cuda-toolkit/include
LCUDA = /usr/lib/nvidia-cuda-toolkit/lib64

# Add CUDA libraries to the link line
LFLAGS += -lcuda -lcudart -L$(LCUDA) -lgomp

# Include standard optimization flags
CPPFLAGS = -O3 -c -I $(ICUDA) -Xcompiler -fopenmp -DTHRUST_DEVICE_BACKEND=THRUST_DEVICE_BACKEND_OMP

# List of all the objects you need
OBJECTS  = timer.o ar1.o kGrid.o vfInit.o parameters.o

# Rule that tells make how to make the program from the objects
main :  main.o $(OBJECTS)
        $(CPP) -o main main.o $(OBJECTS) $(LFLAGS)

# Rule that tells make how to turn a .cu file into a .o
%.o: %.cu
                $(NVCC) ${NVCCFLAGS} $(CPPFLAGS) -c $<

# How does make know how to turn a .cpp into a .o?  It's built-in!
# but if you wanted to type it out it would look like:
# %.o: %.cpp
#       $(CPP) $(CPPFLAGS) -c $<

clean :
        rm -f *.o
        rm -f core core.*

veryclean :
        rm -f *.o
        rm -f core core.*
        rm -f main

这导致以下命令:

nvcc -arch sm_20  -O3 -c -I /usr/lib/nvidia-cuda-toolkit/include -Xcompiler -fopenmp -DTHRUST_DEVICE_BACKEND=THRUST_DEVICE_BACKEND_OMP -c main.cu
g++  -O3 -c -I /usr/lib/nvidia-cuda-toolkit/include -Xcompiler -fopenmp -DTHRUST_DEVICE_BACKEND=THRUST_DEVICE_BACKEND_OMP  -c -o timer.o timer.cpp
g++: error: unrecognized command line option â-Xcompilerâ
make: *** [timer.o] Error 1

我不理解makefile-xCompiler标志(在变量CPPFLAGS中)只应由nvcc编译器使用,而不是g++ }。因此,我理解为什么我会收到错误。但是,根据我对上面makefile的基本理解,我不明白为什么在某些时候变量CPPFLAGS跟在g++之后(变量CPP)。我在makefile中没有看到任何这样的序列。

1 个答案:

答案 0 :(得分:3)

您的main规则需要timer.otimer.o没有明确的规则,因此make使用内置的隐式规则(如makefile末尾的注释中所述)。将.cpp文件转换为.o文件的隐式规则格式为

$(CPP) $(CPPFLAGS) -c $<

所以它使用CPPFLAGS中包含-Xcompiler的选项进行编译。您可能希望-Xcompiler标记位于NVCCFLAGS而不是CPPFLAGS