gSOAP g++ building error

Posted on 2012-09-04
Last Modified: 2012-09-20
I have gsoap installed, I am trying to to build one of the exmaples:

I do the following which builds a pure c version and this works fine:

g++  -c soapC.cpp

Open in new window

But when I try to build the c++ version like so:

g++ soapC.cpp
soapC.cpp:(.text+0x7645): undefined reference to `soap_element_begin_in'
soapC.cpp:(.text+0x7670): undefined reference to `soap_malloc'
soapC.cpp:(.text+0x76c0): undefined reference to `soap_revert'
soapC.cpp:(.text+0x76ce): undefined reference to `soap_malloc'
soapC.cpp:(.text+0x7752): undefined reference to `soap_id_lookup'
soapC.cpp:(.text+0x7773): undefined reference to `soap_element_end_in'
/tmp/ccMtcp0m.o: In function `soap_in_SOAP_ENV__Detail(soap*, char const*, SOAP_ENV__Detail*, char const*)':
soapC.cpp:(.text+0x77e5): undefined reference to `soap_element_begin_in'
soapC.cpp:(.text+0x783e): undefined reference to `soap_id_enter'
soapC.cpp:(.text+0x7926): undefined reference to `soap_inliteral'
soapC.cpp:(.text+0x799d): undefined reference to `soap_element_end_in'
soapC.cpp:(.text+0x79fd): undefined reference to `soap_id_forward'

Open in new window

How do I solve this???
I think I need to include a header file or library in my g++ path somehow.
Question by:Wanting2LearnMan

    Author Comment

    I have tried the following:

    g++ soapC.cpp -I /home/gsoap-2.8/gsoap/ -l libgsoap++.a

    Open in new window

    home/gsoap-2.8/gsoap includes header files and libgsoap++.s is a link as follows:
    libgsoap++.a -> /usr/local/lib/libgsoap++.a

    Open in new window

    But I now get the error:

    /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: cannot find -llibgsoap++.a
    collect2: ld returned 1 exit status

    Open in new window

    Any ideas??
    LVL 31

    Accepted Solution

    Is there any shared object?

    /sbin/ldconfig -p | grep -i soap

    Open in new window

    Also, did you make any change in your includes or anything?

    Do you still have

    Another problem is in:
    -l libgsoap++.a

    You need to drop lib

    So it should be
    -l gsoap++.a

    But I would normally look for shared objects .so instead of .a
    I will have to look for .a, I forgot but if it was, I would do

    Open in new window

    LVL 51

    Expert Comment

    please try:

     g++ soapC.cpp -I /home/gsoap-2.8/gsoap/ -l gsoap++

    or use a full path like  /path/to/libgsoap++.a
    (also see farzanj's comments on .a vs .so; better you make a decision if want to compile *and* link staticaly or with dynamic shared objects
    LVL 34

    Expert Comment

    by:Duncan Roe
    Since g++  -c soapC.cpp worked, there is no need to add -I /home/gsoap-2.8/gsoap/. You are done with the source and you now have the object file soapC.o.
    Your problem is to link soapC.o with the necessary libraries to make an executable program.
    Some systems don't by default look for libraries in /usr/local /lib, so here's what I would try
    g++  -c soapC.cpp
    g++ soapC.o -L/usr/local/lib -lgsoap++ -o soapC

    Open in new window

    Notice for the library you miss out the leading lib and the trailing .a. The above command will link to the shared library if it can find it, otherwise it will link to libgsoap++.a. Either way, the built program will be called soapC.
    LVL 9

    Expert Comment

        duncan_roe has already given pointers on this .. i tried to write a make file to build this..

    1) make sure you have copied the .a lib in the usr/local/lib directory (For another library i got the same problem but after manually copied the .so files it was worked fine)
    2) export LD_LIBRARY_PATH (if you have the gSoap lib on other dir not in gcc library search path)

    Here is the example Makefile to compile the stuff

    # Makefile (EE QID:27852210)
    # Target Name
    TARGET = soapC
    # Compiler options
    CC     = g++
    CFLAGS = -c
    LFLAGS = -o
    # Library Directories
    # modify this path as per requirement
    SOAP_LIB_PATH = -I/usr/local/soap_libs
    # Include Directories
    #modify this path for your requirement
    SOAP_INC_PATH = -I/usr/local/soap_inc
    # Static/Shared libraries
    GSOAP_LIBS = -lgsoap++
    # Source files
    SRCS = test.c#soapC.cpp
    # Compilation and Build
            @echo "Compiling " $(SRCS)
            @#@$(CC) $(LFLAGS) test $(SRCS)
            @echo "Build successful"

    Open in new window

    Use the following command to run the Makefile
    linux$make build
    LVL 34

    Expert Comment

    by:Duncan Roe
    Rather than exporting LD_LIBRARY_PATH you might prefer to add /usr/local/lib or whatever to /etc/ That's what I do
    LVL 9

    Expert Comment

    ---->Rather than exporting LD_LIBRARY_PATH you might prefer to add /usr/local/lib or whatever to /etc/ That's what I do
          Better need to configure again the LD_LIBRARY_PATH when you restart..

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now