jma
November 5, 2008, 1:19pm
1
In the Makefile supplied with $(SDK)/projects/template, you can read the following:
Add source files here
EXECUTABLE := template
CUDA source files (compiled with cudacc)
CUFILES := template.cu
CUDA dependency files
CU_DEPS := template_kernel.cu
C/C++ source files (compiled with gcc / c++) ← Dangerous!
CCFILES := template_gold.cpp
This works for files with the ‘cpp’ extender, but for C-files with a ‘c’ extension a ‘make clean’ will remove the source and leave the object, which may come in as surprise to some …
After looking into common.mk I noticed that there is also a CFILES variable. Using that one instead works as expected for C, but then shows the same symptom as above but now for ‘cpp’ :rolleyes:
What appears to work is something like:
Build script for project:
EXECUTABLE := template
######################################
CUDA source files (compiled with cudacc)
CUFILES := template.cu
CUDA dependency files
CU_DEPS := template_kernel.cu
C source files (compiled with gcc)
CFILES := template_sound.c
C++ source files (compiled with c++)
CCFILES := template_ui.cpp
######################################
Rules and targets
#verbose :=1
include …/…/common/common.mk
######################################
Additional compiler flags and libraries
activate Intel intrinsics in C-files
CFLAGS += -mssse3
use ALSA for sound
LIB += -lasound
Mafos
November 6, 2008, 11:09am
2
I confirm this ‘bug’… well maybe nvidia thinks this is a feature ;)
jma
November 6, 2008, 1:40pm
3
Yeah, to give support for statements like: “compiler ate my homework …” :unsure:
A more user-proof fix is to edit the definition of the OBJS variable in the common.mk file to filter the proper extensions
SAFE_CUFILES := $(filter %.cu,$(CUFILES))
SAFE_CCFILES := $(filter %.cpp,$(CCFILES) $(CFILES))
SAFE_CFILES := $(filter %.c,$(CCFILES) $(CFILES))
OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp_o,$(notdir $(SAFE_CCFILES)))
OBJS += $(patsubst %.c,$(OBJDIR)/%.c_o,$(notdir $(SAFE_CFILES)))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_o,$(notdir $(SAFE_CUFILES)))
tyoc
December 31, 2008, 5:02pm
5
A more user-proof fix is to edit the definition of the OBJS variable in the common.mk file to filter the proper extensions
SAFE_CUFILES := $(filter %.cu,$(CUFILES))
SAFE_CCFILES := $(filter %.cpp,$(CCFILES) $(CFILES))
SAFE_CFILES := $(filter %.c,$(CCFILES) $(CFILES))
OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp_o,$(notdir $(SAFE_CCFILES)))
OBJS += $(patsubst %.c,$(OBJDIR)/%.c_o,$(notdir $(SAFE_CFILES)))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_o,$(notdir $(SAFE_CUFILES)))
If I understand correctly, then I should paste this code in NVIDIA_CUDA_SDK/common/common.mk
############################################################
####################
# Set up object files
############################################################
####################
OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
OBJS += $(patsubst %.c,$(OBJDIR)/%.c.o,$(notdir $(CFILES)))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu.o,$(notdir $(CUFILES)))
#SAFE_CUFILES := $(filter %.cu,$(CUFILES))
#SAFE_CCFILES := $(filter %.cpp,$(CCFILES) $(CFILES))
#SAFE_CFILES := $(filter %.c,$(CCFILES) $(CFILES))
#OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
#OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp_o,$(notdir $(SAFE_CCFILES)))
#OBJS += $(patsubst %.c,$(OBJDIR)/%.c_o,$(notdir $(SAFE_CFILES)))
#OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_o,$(notdir $(SAFE_CUFILES)))
Like you see your code is commented out, but if I comment original code and let your code, then doing make on NVIDIA_CUDA_SDK, then I get
$ make
make[1]: entering directory `/home/tyoc/NVIDIA_CUDA_SDK/common'
make[1]: *** There are no rules for build object `obj/release/bank_checker.cpp_o', needed for `../lib/libcutil.a'. Stop.
make[1]: Exiting directory `/home/tyoc/NVIDIA_CUDA_SDK/common'
make: *** [lib/libcutil.so] Error 2
So, what should I do?
Looks like the extension should be .cpp.o instead of .cpp_o. (oops) Try the following:
############################################################
####################
# Set up object files
############################################################
####################
OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
OBJS += $(patsubst %.c,$(OBJDIR)/%.c.o,$(notdir $(CFILES)))
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu.o,$(notdir $(CUFILES)))
#SAFE_CUFILES := $(filter %.cu,$(CUFILES))
#SAFE_CCFILES := $(filter %.cpp,$(CCFILES) $(CFILES))
#SAFE_CFILES := $(filter %.c,$(CCFILES) $(CFILES))
#OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
#OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(SAFE_CCFILES)))
#OBJS += $(patsubst %.c,$(OBJDIR)/%.c.o,$(notdir $(SAFE_CFILES)))
#OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu.o,$(notdir $(SAFE_CUFILES)))
[/code]