cuda dynamic link makefile ,compiles but not excuted

Hello, I have a project that runs just fine from nsight eclipse.
I created a makefile and it compiles fine but when I try to run it ,it gives segmentaion fault.
I noticed this:

In my code , I print some values :

NbOfCDV : 286752
NbOfSTD : 286720
NbOfNOI : 32

TotalSize: 298713088 bytes

When the code is being executed from makefile ,it gives :

NbOfCDV : 286752
NbOfSTD : 0
NbOfNOI : 0

TotalSize: 8386658489117799521 bytes

!!!

What am I doing wrong??

Makefile:

PROJECT_NAME = Calc

# Location of the CUDA Toolkit
CUDA_PATH     = /usr/local/cuda-6.5
CUDA_BIN_PATH ?= $(CUDA_PATH)/bin

# compiler
GCC = gcc
NVCC = $(CUDA_BIN_PATH)/nvcc

# Compiler flags
CCFLAGS 		:= -m64 -std=c99 
NVCCFLAGS   	:= --target-cpu-architecture x86 -m64 -rdc=true 
LDFLAGS     	:= -lcudart -lcublas_device -lcudadevrt -lcublas -lcuda -lm 
DLINKFLAGS 		:= -lcublas_device -lcudadevrt -lcublas -lcudart

#debug
DEBUG ?= 0
ifeq (DEBUG, 1)
    CCFLAGS 	+= -DDEBUG -g 
    NVCCFLAGS 	+= -DDEBUG -g -G
else
    CCFLAGS 	+= -DNDEBUG
    NVCCFLAGS 	+= -DNDEBUG
endif

# Common includes and library paths 
INCLUDES  := -I/usr/local/cuda-6.5/include ...

LIBRARIES := -L/usr/local/cuda-6.5/lib64 ...

# CUDA code generation flags
GENCODE_SM35    := -gencode arch=compute_35,code=sm_35
GENCODE_FLAGS   := $(GENCODE_SM35)

# Target rules
.PHONY: all
all: build

build: $(PROJECT_NAME)

Calc.o:Calc.cu	
	$(NVCC)	$(NVCCFLAGS) $(MKLFLAGS) $(GENCODE_FLAGS) $(INCLUDES)  -c $<
	$(NVCC) -dlink $(GENCODE_FLAGS)  $(DLINKFLAGS) -o Calc_link.o $@ 
			
PhListFile.o:PhListFile.c		
	$(GCC) $(CCFLAGS) $(INCLUDES) -c $<
			
PhFilesUtil.o:PhFilesUtil.c			
	$(GCC) $(CCFLAGS) $(INCLUDES) -c $<
	
	
$(PROJECT_NAME):Calc.o	Calc_link.o	 PhListFile.o	PhFilesUtil.o		    	 
	$(GCC) $(CCFLAGS) -o  $@ $+   $(LIBRARIES) $(LDFLAGS)
		

run: build
	./$(PROJECT_NAME)

.PHONY: clean
clean:
	rm -f *.o $(PROJECT_NAME)

Any ideas for this?

Thanks!

A seg fault occurs in host code, not device code. Have you tracked down the line in your host code that is causing the seg fault? If not, do that first.

But , when I debug through nsight everything is ok…
Not even a warning.

If ,after “make” ,I use from command line either cuda-gdb or gdb ,it just shows :

Program received signal SIGSEGV, Segmentation fault.
0x00000034d64897cb in memcpy () from /lib64/libc.so.6
backtrace

#0  0x00000034d64897cb in memcpy () from /lib64/libc.so.6
#1  0x000000000045d237 in LoadSample ()
#2  0x0000000000450429 in TestList ()
#3  0x000000000044f5e0 in main ()

I don’t know if/how to extract more information from this.

The LoadSample is in TestList and main calls TestList.

But I repeat , the program runs fine through nsight!

Use printf to subdivide the program that seg faults into pieces. Eventually you will get down to the line that is causing the seg fault.