gsoap的一个demo例子WSDD - ONVIF WS-Discovery server 的交叉编译

 奇怪了,交叉编译出来了,但是不能运行。

# WSDD - ONVIF WS-Discovery server


## Description

wsdd is Linux daemon for ONVIF WS-Discovery service (server side).

ONVIF official website: [http://www.onvif.org](http://www.onvif.org)

The web services data binding is generated using [gSOAP](http://www.genivia.com)

For more details about it see the [gSOAP WS-Discovery plugin official manual.](https://www.genivia.com/doc/wsdd/html/wsdd_0.html)

 

项目在github上 wsdd 使用了  gsoap里面的 plugin里面的两个文件

(注意:

GSOAP_PLUGIN_DIR  = $(GSOAP_DIR)/plugin

SOAP_SRC = $(GSOAP_DIR)/stdsoap2.c         \
           $(GSOAP_PLUGIN_DIR)/wsaapi.c    \
           $(GSOAP_PLUGIN_DIR)/wsddapi.c   \

           $(GENERATED_DIR)/soapClient.c

)。

 

GCC_ARM          ?= arm-linux-gnueabi-gcc-4.7  (这里修改添加了一个交叉编译器)

define build_object
    @$(BUILD_ECHO)
    $(GCC_ARM) -c $< -o $@  $(CFLAGS)  (使用的交叉编译器 编译依赖的 文件)
endef

define build_bin
    @$(BUILD_ECHO)
    $(GCC_ARM)  $1 -o $@  $(CFLAGS)  (使用的交叉编译器 编译连接最终的target)
    @echo "\n---- Compiled $@ ver $(DAEMON_MAJOR_VERSION).$(DAEMON_MINOR_VERSION).$(DAEMON_PATCH_VERSION) ----\n"
endef

里面还有一个 GCC ,要注意整个编译过程。 第一部分是先用GCC 编译gSoap的源代码产生两个 WSDL2H  ,SOAPCPP2。

这两个是 x86下的程序用来生成我们的 开发框架的。 所以这部分不能交叉编译。

生成的框架和我们的代码都被包含在 SOURCES这个变量里面。

SOAP_SRC = $(GSOAP_DIR)/stdsoap2.c         \
           $(GSOAP_PLUGIN_DIR)/wsaapi.c    \
           $(GSOAP_PLUGIN_DIR)/wsddapi.c   \
           $(GENERATED_DIR)/soapClient.c

# Add your source files to the list.
# Supported *.c  *.cpp  *.S files.
# For other file types write a template rule for build, see below.
SOURCES  = $(COMMON_DIR)/$(DAEMON_NAME).c   \
           $(COMMON_DIR)/daemon.c           \
           $(COMMON_DIR)/net_utils.c        \
           $(COMMON_DIR)/file_utils.c       \
           $(COMMON_DIR)/wsdd_utils.c       \
           $(COMMON_DIR)/client_events.c    \
           $(GENERATED_DIR)/soapC.c         \
           $(SOAP_SRC)

最后调用

# release
$(DAEMON_NAME): .depend $(OBJECTS)
    $(call build_bin, $(OBJECTS))


# debug
$(DAEMON_NAME)_$(DEBUG_SUFFIX): .depend $(DEBUG_OBJECTS)
    $(call build_bin, $(DEBUG_OBJECTS))


# Build release objects
%.o: %.c
    $(build_object)


%.o: %.cpp
    $(build_object)


%.o: %.S
    $(build_object)

# Build debug objects
%_$(DEBUG_SUFFIX).o: %.c
    $(build_object)


%_$(DEBUG_SUFFIX).o: %.cpp
    $(build_object)


%_$(DEBUG_SUFFIX).o: %.S
    $(build_object)

build_bin 和 build_object 里面的编译工具已经替换成了  交叉编译工具。最后就可以生成 ARM下的可执行文件了。

 

 

 

DAEMON_NAME           = wsdd
DAEMON_MAJOR_VERSION  = 2
DAEMON_MINOR_VERSION  = 1
DAEMON_PATCH_VERSION  = 0
DAEMON_PID_FILE_NAME  = $(DAEMON_NAME).pid
DAEMON_LOG_FILE_NAME  = $(DAEMON_NAME).log
DAEMON_NO_CHDIR       = 1
DAEMON_NO_CLOSE_STDIO = 0




GSOAP_DIR         = ./gsoap-2.8/gsoap
GSOAP_PLUGIN_DIR  = $(GSOAP_DIR)/plugin
GSOAP_IMPORT_DIR  = $(GSOAP_DIR)/import


SOAPCPP2          = $(GSOAP_DIR)/src/soapcpp2
WSDL2H            = $(GSOAP_DIR)/wsdl/wsdl2h


COMMON_DIR        = ./src
GENERATED_DIR     = ./generated


CFLAGS            = -DDAEMON_NAME='"$(DAEMON_NAME)"'
CFLAGS           += -DDAEMON_MAJOR_VERSION=$(DAEMON_MAJOR_VERSION)
CFLAGS           += -DDAEMON_MINOR_VERSION=$(DAEMON_MINOR_VERSION)
CFLAGS           += -DDAEMON_PATCH_VERSION=$(DAEMON_PATCH_VERSION)
CFLAGS           += -DDAEMON_PID_FILE_NAME='"$(DAEMON_PID_FILE_NAME)"'
CFLAGS           += -DDAEMON_LOG_FILE_NAME='"$(DAEMON_LOG_FILE_NAME)"'
CFLAGS           += -DDAEMON_NO_CHDIR=$(DAEMON_NO_CHDIR)
CFLAGS           += -DDAEMON_NO_CLOSE_STDIO=$(DAEMON_NO_CLOSE_STDIO)

CFLAGS           += -I$(COMMON_DIR)
CFLAGS           += -I$(GENERATED_DIR)
CFLAGS           += -I$(GSOAP_DIR) -I$(GSOAP_PLUGIN_DIR) -I$(GSOAP_IMPORT_DIR)
CFLAGS           += -O2  -Wall  -pipe

GCC              ?= gcc

GCC_ARM          ?= arm-linux-gnueabi-gcc-4.7  (这里修改添加了一个交叉编译器)



SOAP_SRC = $(GSOAP_DIR)/stdsoap2.c         \
           $(GSOAP_PLUGIN_DIR)/wsaapi.c    \
           $(GSOAP_PLUGIN_DIR)/wsddapi.c   \
           $(GENERATED_DIR)/soapClient.c



# Add your source files to the list.
# Supported *.c  *.cpp  *.S files.
# For other file types write a template rule for build, see below.
SOURCES  = $(COMMON_DIR)/$(DAEMON_NAME).c   \
           $(COMMON_DIR)/daemon.c           \
           $(COMMON_DIR)/net_utils.c        \
           $(COMMON_DIR)/file_utils.c       \
           $(COMMON_DIR)/wsdd_utils.c       \
           $(COMMON_DIR)/client_events.c    \
           $(GENERATED_DIR)/soapC.c         \
           $(SOAP_SRC)





OBJECTS  := $(patsubst %.c,  %.o, $(SOURCES) )
OBJECTS  := $(patsubst %.cpp,%.o, $(OBJECTS) )
OBJECTS  := $(patsubst %.S,  %.o, $(OBJECTS) )


DEBUG_SUFFIX   = debug

DEBUG_OBJECTS := $(patsubst %.o, %_$(DEBUG_SUFFIX).o, $(OBJECTS) )




.PHONY: all
all: debug release



.PHONY: release
release: CFLAGS := -s  $(CFLAGS)
release: $(DAEMON_NAME)



.PHONY: debug
debug: DAEMON_NO_CLOSE_STDIO = 1
debug: CFLAGS := -DDEBUG  -g  $(CFLAGS)
debug: $(DAEMON_NAME)_$(DEBUG_SUFFIX)



# release
$(DAEMON_NAME): .depend $(OBJECTS)
	$(call build_bin, $(OBJECTS))


# debug
$(DAEMON_NAME)_$(DEBUG_SUFFIX): .depend $(DEBUG_OBJECTS)
	$(call build_bin, $(DEBUG_OBJECTS))



# Build release objects
%.o: %.c
	$(build_object)


%.o: %.cpp
	$(build_object)


%.o: %.S
	$(build_object)



# Build debug objects
%_$(DEBUG_SUFFIX).o: %.c
	$(build_object)


%_$(DEBUG_SUFFIX).o: %.cpp
	$(build_object)


%_$(DEBUG_SUFFIX).o: %.S
	$(build_object)



.PHONY: clean
clean:
	-@rm -f $(DAEMON_NAME)
	-@rm -f $(DAEMON_NAME)_$(DEBUG_SUFFIX)
	-@rm -f $(OBJECTS)
	-@rm -f $(DEBUG_OBJECTS)
	-@rm -f .depend
	-@rm -f -d -R $(GENERATED_DIR)
	-@rm -f *.*~



.PHONY: distclean
distclean: clean
	-@rm -f -d -R SDK
	-@rm -f -d -R gsoap-2.8
	-@rm -f RECV.log SENT.log TEST.log



.depend: $(GENERATED_DIR)/soapC.c
	-@rm -f .depend
	@echo "Generating dependencies..."
	@for src in $(SOURCES) ; do \
        echo "  [depend]  $$src" ; \
        $(GCC) $(CFLAGS) -MT ".depend $${src%.*}.o $${src%.*}_$(DEBUG_SUFFIX).o" -MM $$src >> .depend ; \
    done



ifeq "$(findstring $(MAKECMDGOALS),clean distclean)"  ""
    include $(wildcard .depend)
endif




# ---- gSOAP ----

$(GENERATED_DIR)/wsdd.h:
	@$(build_gsoap)
	@mkdir -p $(GENERATED_DIR)
	$(WSDL2H) -cg -t $(GSOAP_DIR)/WS/typemap.dat  -o $@  wsdl/remotediscovery.wsdl



$(GENERATED_DIR)/soapC.c: $(GENERATED_DIR)/wsdd.h
	$(SOAPCPP2) -C -L -x -c -2 -d $(GENERATED_DIR) -I$(GSOAP_DIR):$(GSOAP_IMPORT_DIR) $<



# This targets is needed for parallel work of make
$(OBJECTS) $(DEBUG_OBJECTS) $(SOAP_SRC): $(GENERATED_DIR)/soapC.c





# Common commands
BUILD_ECHO = echo "\n  [build]  $@:"


define build_object
    @$(BUILD_ECHO)
    $(GCC_ARM) -c $< -o $@  $(CFLAGS)  (使用的交叉编译器 编译依赖的 文件)
endef



define build_bin
    @$(BUILD_ECHO)
    $(GCC_ARM)  $1 -o $@  $(CFLAGS)  (使用的交叉编译器 编译连接最终的target)
    @echo "\n---- Compiled $@ ver $(DAEMON_MAJOR_VERSION).$(DAEMON_MINOR_VERSION).$(DAEMON_PATCH_VERSION) ----\n"
endef




define build_gsoap

    # get archive
    if [ ! -f SDK/gsoap.zip ]; then \
        mkdir -p SDK; \
        wget -O ./SDK/gsoap.zip.tmp "https://sourceforge.net/projects/gsoap2/files/gsoap-2.8/gsoap_2.8.66.zip/download" && \
        mv ./SDK/gsoap.zip.tmp ./SDK/gsoap.zip; \
    fi

    # unzip
    if [ ! -f gsoap-2.8/README.txt ]; then \
         unzip ./SDK/gsoap.zip; \
    fi

    # build
    if [ ! -f $(SOAPCPP2) ] || [ ! -f $(WSDL2H) ]; then \
         cd gsoap-2.8; \
         ./configure && \
         make -j1; \
         cd ..;\
    fi
endef




.PHONY: help
help:
	@echo "make [command]"
	@echo "command is:"
	@echo "   all       -  build daemon in release and debug mode"
	@echo "   debug     -  build in debug mode (#define DEBUG 1)"
	@echo "   release   -  build in release mode (strip)"
	@echo "   clean     -  remove all generated files"
	@echo "   distclean -  clean + remove all SDK files"
	@echo "   help      -  this help"

 

带gsoap-2.8源码,基于服务器客户端的实例,带自动生成服务客户端代码的批处理程序,及如何使用。带自己学习参考的教程; 0.解压附件,soapInterface.bat所在路径不得含中文 空格 1.新建头文件 取soapInterface.bat文件的同名:soapInterface.h 文件内编写接口,具体说明看附件参考的教程 //gsoap ns service name: gservice //gsoap ns service style: rpc int ns__add(int num1, int num2, int* result ); int ns__sub(int num1, int num2, int* result ); int ns__mult( int num1, int num2, int *result); int ns__divid( int num1, int num2, int *result); 2.从附件内gsoap-2.8包中搜索复制stdsoap2.h,stdsoap2.cpp,soapcpp2.exe, 存放于soapInterface.bat同级目录 3.双击soapInterface.bat运行。生成gClientSoap,gServerSoap两个文件夹,分别复制到服务器工程与客户端工程中使用 4.gClientSoap,gServerSoap两个文件夹内用到的文件功能说明,更多参考附件教程 1)soapC.cpp , soapH.h//soap的序列和反序列代码,它已经包含了soapStub.h 2)soapServer.c ppsoapServerLib.cpp //服务器端代码(纯C代码是soapServer.c soapServerLib.c ),soapServerLib.cpp文件则只是简单地包含soapServer.cpp和soapC.cpp 3)soapClient.cpp soapClientLib.cpp//客户端代码(纯C代码是soapClient.csoapClientLib.c ),soapClientLib.cpp文件则只是简单地包含soapClient.cpp和soapC.cpp 4) soapStub.h // soap的存根文件,定义了我们编写的头文件里对应的远程调用模型 5) add.nsmap //XML服务命名空间 6)服务器端要载入的文件有:soapServer.cpp,soapC.cpp,stdsoap2.cpp; 要包含的文件有:gservice.nsmap,soapH.h; 客户端要输入的文件有: soapClient.cpp,soapC.cpp,stdsoap2.cpp; 要包含的文件有:gservice.nsmap,soapH.h
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值