在msvc下编码没问题,gcc make 一直编译不过,巡大佬指点迷津。
  
===============================================================
redishelper.h 如下:
#ifndef REDISHELPER_H
#define REDISHELPER_H
  
#include <string>
#include "hiredis/hiredis.h"
  
class RedisHelper
{
private:
     RedisHelper(std::string ip = "127.0.0.1", int port = 6379);
public:
     ~RedisHelper() {
         redisFree(this->context);
     };
public:
     bool setCommand(const char *key, const char *value);
private:
     std::string ip;
     int port;
     redisContext* context;
public:
     static RedisHelper* instance(){
         return p;
     }
private:
     static RedisHelper* p;
};
#endif // REDISADAPTER_H
  
===============================================================
redishelper.cpp 如下:
#include <strings.h>
#include <iostream>
#include "redishelper.h"
  
RedisHelper* RedisHelper::p = new RedisHelper();
  
RedisHelper::RedisHelper(std::string ip, int port) {
     this->ip = ip;
     this->port = port;
     this->context = redisConnect(ip.c_str(), port);
     if (this->context == NULL) {
         printf("Connection error: can't allocate redis context !\n");
     }
     if (this->context->err){
         std::cerr << "Error: " << this->context->errstr << std::endl;
         redisFree(this->context);
         this->context = NULL;
     }
}
bool RedisHelper::setCommand(const char *key, const char *value){
     if (this->context == NULL) {
         printf("Error: context is NULL, cann't set !\n");
         return false;
     }
     redisReply *reply = (redisReply *)redisCommand(this->context, "SET %s %s", key, value);
     if (reply == NULL) {
         printf("Error: execut command failure!\n");
         return false;
     }
     if (reply->type != REDIS_REPLY_STATUS || strcasecmp(reply->str, "OK")) {
         printf("Error: execut command failure! (%s)\n", reply->str);
         freeReplyObject(reply);
         return false;
     }
     printf("Set command(%s=%s) success.\n", key, value);
     freeReplyObject(reply);
     return true;
}
  
===============================================================
Makefile 如下:
APP:= deepstream-app
  
CXX=g++
  
TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -)
  
NVDS_VERSION:=5.0
  
LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/
APP_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/bin/
  
ifeq ($(TARGET_DEVICE),aarch64)
   CFLAGS:= -DPLATFORM_TEGRA
endif
  
SRCS:= $(wildcard *.c)
#SRCS+= $(wildcard *.cpp)
SRCS+= $(wildcard ../../apps-common/src/*.c)
SRCS+= redishelper.cpp
  
INCS:= $(wildcard *.h)
INCS+= $(wildcard ./hiredis/*.h)
#INCS+= $(wildcard ../../apps-common/includes/*.h)
#INCS+= $(wildcard ../../../includes/*.h)
  
ifeq ($(TARGET_DEVICE),aarch64)
     PKGS:= gstreamer-1.0 gstreamer-video-1.0 x11 json-glib-1.0 opencv4
else
     PKGS:= gstreamer-1.0 gstreamer-video-1.0 x11 json-glib-1.0 opencv
endif
  
OBJS:= $(SRCS:.c=.o)
#OBJS+= $(SRCS:.cpp=.o)
OBJS+= deepstream_nvdsanalytics_meta.o
OBJS+= redishelper.o
  
CFLAGS+= -I./ -I../../apps-common/includes -I../../../includes -DDS_VERSION_MINOR=0 -DDS_VERSION_MAJOR=5
CFLAGS+= -I/usr/include/gstreamer-1.0
  
LIBS+= -L$(LIB_INSTALL_DIR) -lnvdsgst_meta -lnvds_meta -lnvdsgst_helper -lnvdsgst_smartrecord -lnvds_utils -lnvds_msgbroker -lm \
        -lgstrtspserver-1.0 -lnvbufsurface -lhiredis -ldl -Wl,-rpath,$(LIB_INSTALL_DIR)
  
CFLAGS+= `pkg-config --cflags $(PKGS)`
  
LIBS+= `pkg-config --libs $(PKGS)`
  
all: $(APP)
  
%.o: %.c $(INCS) Makefile
     $(CC) -c -o $@ $(CFLAGS) $<
  
deepstream_nvdsanalytics_meta.o: deepstream_nvdsanalytics_meta.cpp $(INCS) Makefile
     $(CXX) -c -o $@ -Wall -Werror $(CFLAGS) $<
  
redishelper.o: redishelper.cpp $(INCS) Makefile
     $(CXX) -c -o $@ -Wall -Werror $(CFLAGS) $<
  
$(APP): $(OBJS) Makefile
     $(CXX) -o $(APP) $(OBJS) $(LIBS)
  
install: $(APP)
     cp -rv $(APP) $(APP_INSTALL_DIR)
  
clean:
     rm -rf $(OBJS) $(APP)
--
FROM 223.88.88.*