2013-05-09 157 views
1

我试图编译程序(这是不是我的):Makefile文件导致编译错误

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 FL ag(在变量CPPFLAGS中)只能由nvcc编译器使用,而不能使用g++。因此,我明白为什么我会收到错误。但是,根据我对上述makefile的基本了解,我不明白为什么在某些时候变量CPPFLAGS跟随g++(变量CPP)。 makefile中没有看到这样的序列。

回答

3

您的main规则要求timer.otimer.o没有明确的规则,所以make使用了一个内置的隐式规则(正如makefile文件末尾的注释中提到的那样)。转换.cpp文件到.o文件的隐含规则有

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

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

+0

啊,我现在明白了。我改变了'makefile'来显式地定义处理.cpp文件的规则:'%.o:%.cpp' $(CPP)-O3 -g -c $ <'但现在出现以下错误:'' g ++ -o main main.o timer.o ar1.o kGrid.o vfInit.o parameters.o -lcuda -lcudart -L/usr/lib/nvidia-cuda-toolkit/lib -lgomp' '/ usr/bin/ld:找不到-lcuda' 'collect2:error:ld returned 1 exit status' – lodhb 2013-05-09 23:53:59