Search code examples
cgsoap

I can't generate stdsoap2.c (.h) file with soapcpp2 release 2.8.117


I am following tutorials on gSOAP website to build a gSOAP-based web service. Specifically, I follow an example for building this service using calc.c from the auto-generated calc.h. I have run the following commands in Ubuntu.

wsdl2h -c -o calc.h http://www.genivia.com/calc.wsdl
soapcpp2 -CL calc.h
cc -o calc calc.c soapClient.c soapC.c stdsoap2.c

The second command, soapcpp2 -CL calc.h, is supposed to generate files required for the compilation of a gSOAP-based application.

The problem is that the file stdsoap2.c is not generated and I could not figure out the problem.

I tried to re-install the gsoap package and run the commands again, but it did not generate the stdsoap2.c file.

I read an answer here, but I could not locate the gsoap directory in ubuntu. So, I copied the stdsoap2.c and stdsoap2.h files from another project and pasted them into mine, which happened to pass this error. Then I had another error that calc.c was not generated, and something about the gsoap version.

cc1: fatal error: calc.c: No such file or directory
compilation terminated.
In file included from soapH.h:16,
                 from soapClient.c:18:
soapStub.h:20:3: error: #error "GSOAP VERSION 208117 MISMATCH IN GENERATED CODE VERSUS LIBRARY CODE: PLEASE REINSTALL PACKAGE"
   20 | # error "GSOAP VERSION 208117 MISMATCH IN GENERATED CODE VERSUS LIBRARY CODE: PLEASE REINSTALL PACKAGE"
      |   ^~~~~
In file included from soapH.h:16,
                 from soapC.c:19:
soapStub.h:20:3: error: #error "GSOAP VERSION 208117 MISMATCH IN GENERATED CODE VERSUS LIBRARY CODE: PLEASE REINSTALL PACKAGE"
   20 | # error "GSOAP VERSION 208117 MISMATCH IN GENERATED CODE VERSUS LIBRARY CODE: PLEASE REINSTALL PACKAGE"
      |   ^~~~~

How to do this right?


Solution

  • stdsoap2.c and stdsoap2.h represent the library code. These files will not be generated by wsdl2h or soapcpp2.

    Placing a copy of these files in the project is a very manual way of including the library. To make this work you must ensure that the version of the library code matches that of generated code.

    • Invoking soapcpp2 -V (and/or wsdl2h -V) will tell you the version of the generated code.
    • grep GSOAP_VERSION stdsoap2.h will tell you the version of the library you copied.

    You have a version mismatch between the generated code and the library (the files you copied), hence the error.

    On Ubuntu, you are better off using the package manager.

    While the gsoap package contains the tools for code generation, the libgsoap-dev package contains the development files needed to compile your final program.

    $ apt install libgsoap-dev
    

    (Note: libgsoap, which contains the runtime libraries, will be installed as a dependency for both gsoap and libgsoap-dev.)

    Compile your program, linking against the gsoap library:

    $ cc -o calc calc.c soapClient.c soapC.c -lgsoap
    
    $ ./calc add 40 2
    result = 42