Compiling and generating ONVIF linux C/C + + source code by gSoap

Posted by a94060 on Fri, 11 Feb 2022 08:10:18 +0100

1 Preparation


  • ONVIF has many modules, and each module corresponds to a different WSDL document. You can compile the specified WSDL document according to your needs;
  • WSDL documents can be Protocol specification , select the corresponding wsdl and right-click the link to save as (local compilation is required, online compilation is not required);
  • gSoap can compile WSDL documents to generate C/C + + source code;
  • gSoap tool download address: gSoap Download
  • gSoap usage guide:

1.2 download

1.3 installing and compiling OpenSSL

Download and compile OpenSSL to get the wsdl2h file that opens SSL/TLS

cd /openssl-1.0.2r
sudo make
sudo make install

1.4 installing and compiling gSOAP

  • Download and compile gsoap (download the open source version to GPLv2 Open Source Edition), address:
  • Compile and generate wsdl2h and soapcpp2 (there are compiled on mac and Windows, and you need to compile wsdl2h yourself under Linux):
cd gsoap-2.8
$ ./configure --with-openssl=/usr/local/ssl
$ make
$ make install
  • error: invalid conversion from 'char*' to 'int' [-fpermissive] err = str

Find the error reporting corresponding function, add atoi and convert char * into int

  • Check whether the compilation is successful
wsdl2h -h  # check if successful
whereis soapcpp2	# Query wsdl2h file location

2 compilation

  • It can be configured locally (it is troublesome to change the file) or online (it needs Networking)
  • /usr/local/bin/wsdl2h -h: you can view the meaning of each option
  • /usr/local/bin/soapcpp2 -h: check the meaning of each option
  • After wsdl2h and soapcpp2 are compiled, they can be found through sudo find / -name wsdl2h
  • It is mainly divided into three scripts:, and

Online configuration

  1. Script
  • C++:
/usr/local/bin/wsdl2h -P -s -x -c++ -t /home/gsoap-2.8/gsoap/typemap.dat -o /home/nvidia/Downloads/ONVIF-C++/onvif.h \\\\\
  • C:
/usr/local/bin/wsdl2h -P -x -c -s -t /home/gsoap-2.8/gsoap/typemap.dat -o /home/nvidia/Downloads/ONVIF-C/onvif.h \\\\\

-P: Do not create an inheritance from XSD__ Polymorphic type of anytype

-x: Do not generate_ XML any / anyAttribute extensible element

-s: Do not generate STL code (no std::string and no std::vector),

  1. Authentication (add the following at the beginning of onvif.h)
#import "wsse.h"
  1. Modify gSOAP / import / wsa5 Soap in H_ ENV__ Fault is SOAP_ENV__Fault_WSA5
#import "wsdd10.h" // wsdd10.h and #import "wsa.h"
#import "wsa5.h"   // wsa.h and wsa5 H two files repeatedly define int SOAP_ENV__Fault
  1. Script soapcpp2onvif SH, generate cpp code and link module
  • C++
/usr/local/bin/soapcpp2 -2 -x -L -C -c++ -d /home/nvidia/Downloads/ONVIF-C++/build \
-I /home/gsoap-2.8/gsoap \
-I /home/gsoap-2.8/gsoap/import \
-I /home/gsoap-2.8/gsoap/custom \
  • C:
/usr/local/bin/soapcpp2 -2 -x -L -C -c -d /home/nvidia/Downloads/ONVIF-C/build\
-I /home/gsoap-2.8/gsoap \
-I /home/gsoap-2.8/gsoap/import \
-I /home/gsoap-2.8/gsoap/custom \
  1. Generated file, reserved c/.cpp and h file, choose any one nsmap, all nsmap files are all the same namespace

  2. Script, copy other useful codes

cd /home/gsoap-2.8/gsoap

sudo cp stdsoap2.cpp stdsoap2.h dom.cpp plugin/wsaapi.c plugin/wsaapi.h plugin/wsseapi.cpp plugin/wsseapi.h plugin/mecevp.c plugin/mecevp.h plugin/smdevp.c plugin/smdevp.h plugin/threads.c plugin/threads.h custom/duration.c custom/duration.h custom/struct_timeval.c custom/struct_timeval.h \

Local configuration

  1. On the official website , right-click all WSDL files corresponding to Service definitions to save the WSDL file;
  2. Script
/usr/local/gSOAP/bin/wsdl2h -c++ -s -t typemap.dat -o samples/onvif/onvif.h \
samples/onvif/wsdl/devicemgmt.wsdl \
samples/onvif/wsdl/event.wsdl \
samples/onvif/wsdl/accesscontrol.wsdl \
samples/onvif/wsdl/accessrules.wsdl \
samples/onvif/wsdl/actionengine.wsdl \
samples/onvif/wsdl/analytics.wsdl \
samples/onvif/wsdl/appmgmt.wsdl \
samples/onvif/wsdl/authenticationbehavior.wsdl \
samples/onvif/wsdl/credential.wsdl \
samples/onvif/wsdl/deviceio.wsdl \
samples/onvif/wsdl/display.wsdl \
samples/onvif/wsdl/doorcontrol.wsdl \
samples/onvif/wsdl/imaging.wsdl \
samples/onvif/wsdl/media.wsdl \
samples/onvif/wsdl/media.wsdl \
samples/onvif/wsdl/provisioning.wsdl \
samples/onvif/wsdl/ptz.wsdl \
samples/onvif/wsdl/receiver.wsdl \
samples/onvif/wsdl/recording.wsdl \
samples/onvif/wsdl/search.wsdl \
samples/onvif/wsdl/replay.wsdl \
samples/onvif/wsdl/schedule.wsdl \
samples/onvif/wsdl/advancedsecurity.wsdl \
samples/onvif/wsdl/thermal.wsdl \
  • During compilation, the compilation may fail due to the path problem. You can modify the corresponding path. After successful compilation, an onvif will be automatically generated H documents.
  1. The rest are consistent with the online configuration steps

3 simple test


#include <soapH.h>
#include <soapStub.h>
#include <wsseapi.h> 
#include "PTZBinding.nsmap"

int main(){
    struct soap *soap = NULL;
    soap = soap_new();
    return 0;


SOURCE	:=	$(wildcard ../src/*.c) $(wildcard ../src/*.cpp) $(wildcard ../third/ONVIF-C++/src/*.cpp) $(wildcard ../third/ONVIF-C++/src/*.c)
OBJS	:=	$(patsubst %.cpp,%.o,$(patsubst %.c,%.o, $(SOURCE)))

CXX := g++

LIBS = 	/usr/local/lib/libssl.a\

LIBS += -lpthread -ldl

INCLUDE	:= -I/usr/include\

CFLAGS 	= -g -Wall -O3  $(DEFINES) $(INCLUDE) -fPIC
CXXFLAGS:= $(CFLAGS) -std=c++11 -Wunused-function -Wunused-variable -Wfatal-errors

.PHONY : everything objs clean veryclean rebuild

everything : $(TARGET)

all : $(TARGET)

rebuild: veryclean everything

clean :
	rm -fr ../src/*.so
	rm -fr ../src/*.o

veryclean : clean
	rm -fr $(TARGET)

%.o : %.cpp
	$(CXX) -c $(CXXFLAGS) $< -o $@
%.o : %.c
	$(CXX) -c $(CXXFLAGS) $< -o $@

	$(CXX) $(CXXFLAGS) -o $@ $(OBJS)  $(LDFLAGS) $(LIBS)

Topics: C++ onvif