2013-05-09 178 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