how to support .cu file to dsexample_lib?

> dsexample_lib
   >dsexample_lib.c
   >dsexample_lib.h
   >Makefile
   >cudaCrop.cu (new add)
   >cudaCrop.h (new add)
   >cudaUtility.h (new add)
   >cudaMath.h (new add)

here is my document tree. i wanna call cuda_function.

in dsexample_lib.h file, the cudaCrop.h is included

#include "cudaCrop.h"
/* other code*/

is there any suggestion?

NVCC:=/usr/local/cuda-10.0/bin/nvcc
run: dsexample_lib.o cudaCrop.o
	gcc -L /usr/local/cuda-10.0/lib64 -c -o dsexample_lib_cuda.o -fPIC dsexample_lib.o cudaCrop.o -lcudart -lcuda

dsexample_lib.o: dsexample_lib.c cudaCrop.h
	gcc -I /usr/local/cuda-10.0/include -I . -c -o dsexample_lib.o dsexample_lib.c

cudaCrop.o: cudaCrop.cu cudaCrop.h
	$(NVCC) -c -o cudaCrop.o cudaCrop.cu

all:
	ar rcs libdsexample.a dsexample_lib_cuda.o

here is my makefile. i am using deepstream4.0 jetson nano
but it throws out this error!

gcc -L /usr/local/cuda-10.0/lib64 -c -o dsexample_lib_cuda.o -fPIC dsexample_lib.o cudaCrop.o -lcudart -lcuda
gcc: warning: dsexample_lib.o: linker input file unused because linking not done
gcc: warning: cudaCrop.o: linker input file unused because linking not done

could you refer the Makefile under sources/objectDetector_Yolo/nvdsinfer_custom_impl_Yolo.

the yolo compile the .cu as .so
but the gst-dsexample require .a
Hi , thank you very much, finally i finish it
finally , i use this makefile

CUDA_VER=10.0
CC:= g++
NVCC:=/usr/local/cuda-$(CUDA_VER)/bin/nvcc

CFLAGS:=-Wall -std=c++11
CFLAGS+=-I/usr/local/cuda-$(CUDA_VER)/include

SRCFILES:=cudaCrop.cu dsexample_lib.c
INCS:= $(wildcard *.h)
TARGET_OBJS:= $(SRCFILES:.cu=.o)
TARGET_OBJS:= $(TARGET_OBJS:.c=.o)
# $(warning $(TARGET_OBJS))

LIBS:=-L/usr/local/cuda-$(CUDA_VER)/lib64 -lcudart -lcublas
LFLAGS:=-Wl,--start-group $(LIBS) -Wl,--end-group

TARGET_LIB:= libdsexample.a

all: $(TARGET_LIB)

%.o: %.cu $(INCS) Makefile
	$(NVCC) -c -o $@ --compiler-options '-lib' $<

%.o: %.c $(INCS) Makefile
	$(CC) -c -o $@ $(CFLAGS) $<

$(TARGET_LIB): $(TARGET_OBJS)
	ar rcs -o $@  $(TARGET_OBJS)

clean:
	rm -rf $(TARGET_LIB)
1 Like