I have both c file and cpp file in project. Trying to build using g++.
Now I can make gstdsexample.o and jetsonGPIO.o
.
gstdsexample.o is object for cpp files and jetsonGPIO.o is object for c files
.
In gstdsexample.cpp
, I am using functions from c header file.
But the errors are those c functions used in cpp file have undefined reference errors
.
gstdsexample.o: In function `gst_dsexample_start(_GstBaseTransform*)':
gstdsexample.cpp:(.text+0x1b3c): undefined reference to `gpioExport(unsigned int)'
gstdsexample.cpp:(.text+0x1b50): undefined reference to `gpioSetDirection(unsigned int, unsigned int)'
gstdsexample.o: In function `gst_dsexample_stop(_GstBaseTransform*)':
gstdsexample.cpp:(.text+0x238c): undefined reference to `gpioUnexport(unsigned int)'
gstdsexample.o: In function `gst_dsexample_transform_ip(_GstBaseTransform*, _GstBuffer*)':
gstdsexample.cpp:(.text+0x2db4): undefined reference to `gpioSetValue(unsigned int, unsigned int)'
gstdsexample.cpp:(.text+0x2dd4): undefined reference to `gpioSetValue(unsigned int, unsigned int)'
collect2: error: ld returned 1 exit status
Makefile:81: recipe for target 'libnvdsgst_dsexample.so' failed
make: *** [libnvdsgst_dsexample.so] Error 1
What is wrong with my Makefile?
USE_OPTIMIZED_DSEXAMPLE?=0
CUDA_VER?=10.2
ifeq ($(CUDA_VER),)
$(error "CUDA_VER is not set")
endif
TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -)
CXX:= g++
ifeq ($(USE_OPTIMIZED_DSEXAMPLE),1)
SRCS:= gstdsexample_optimized.cpp
else
SRCS:= gstdsexample.cpp
C_SRCS:= jetsonGPIO.c
endif
INCS:= $(wildcard *.h)
LIB:=libnvdsgst_dsexample.so
NVDS_VERSION:=5.1
DEP:=dsexample_lib/libdsexample.a
DEP_FILES:=$(wildcard dsexample_lib/dsexample_lib.* )
DEP_FILES-=$(DEP)
CFLAGS+= -fPIC -DDS_VERSION=\"5.1.0\" \
-I /usr/local/cuda-$(CUDA_VER)/include \
-I ../../includes
GST_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/gst-plugins/
LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/
LIBS := -shared -Wl,-no-undefined \
-L dsexample_lib -ldsexample \
-L/usr/local/cuda-$(CUDA_VER)/lib64/ -lcudart -ldl \
-lnppc -lnppig -lnpps -lnppicc -lnppidei -pthread -lnvds_osd\
-L$(LIB_INSTALL_DIR) -lnvdsgst_helper -lnvdsgst_meta -lnvds_meta -lnvbufsurface -lnvbufsurftransform\
-Wl,-rpath,$(LIB_INSTALL_DIR)
#OBJS:= $(SRCS:.cpp=.o)
OBJS:= $(SRCS:.cpp=.o) $(C_SRCS:.c=.o)
ifeq ($(TARGET_DEVICE),aarch64)
PKGS:= gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 opencv4
else
PKGS:= gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 opencv
endif
CFLAGS+=$(shell pkg-config --cflags $(PKGS))
LIBS+=$(shell pkg-config --libs $(PKGS))
all: $(LIB)
%.o: %.cpp $(INCS) Makefile
@echo $(CFLAGS)
$(CXX) -c -o $@ $(CFLAGS) $<
$(LIB): $(OBJS) $(DEP) Makefile
@echo $(CFLAGS)
$(CXX) -o $@ $(OBJS) $(LIBS)
$(DEP): $(DEP_FILES)
$(MAKE) -C dsexample_lib/
install: $(LIB)
cp -rv $(LIB) $(GST_INSTALL_DIR)
clean:
rm -rf $(OBJS) $(LIB)
EDIT:
Undefined reference functions are from jetsonGPIO.c and jetsonGPIO.h I have another gstdsexample.cpp and gstdsexample.h. gstdsexample.cpp uses these functions from jetsonGPIO.h.
Now I can make jetsonGPIO.o.
OBJS:= $(SRCS:.cpp=.o) $(C_SRCS:.c=.o) create .o files.
ALL .o file are used to create lib in
$(LIB): $(OBJS) $(DEP) Makefile
@echo $(CFLAGS)
$(CXX) -o $@ $(OBJS) $(LIBS)