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
中沒有看到這樣的序列。
啊,我現在明白了。我改變了'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