1

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

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.

4

1 回答 1

3

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

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

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

于 2013-05-09T22:38:57.553 回答