Error when running C++ code using APIs

Help
shoyab
2013-02-01
2013-06-12
  • shoyab
    shoyab
    2013-02-01

    Hello,
    I am getting errors in C++ APIs when running below code in ubuntu and same code executing successfully in fedora. Can some one guide to solve this

    code:
    #include<iostream>
    #include "/usr/local/staf/include/STAF.h"
    #include "/usr/local/staf/include/STAF_iostream.h"
    using namespace std;
    int STAF_SERVICE_REQUEST(STAFString);
    unsigned int rc;
    STAFHandlePtr handle;
    int count = 0;
    int main()
    {
    rc  = STAFHandle::create("MyApplication", handle);
    STAFString staf_command;
    if (rc != 0)
    {
            cout << "Error registering with STAF, RC: " << rc << endl;
            return rc;
    }
    staf_command = STAFString("sh ip_setup.sh");
    STAF_SERVICE_REQUEST(staf_command);
    handle -> submit("LOCAL", "PROCESS", "START SHELL COMMAND wireshark &");
    staf_command = STAFString("ipsec start");
    STAF_SERVICE_REQUEST(staf_command);
    staf_command = STAFString("ipsec up secgw");
    STAF_SERVICE_REQUEST(staf_command);
    return 0;
    }

    int STAF_SERVICE_REQUEST(STAFString command)
    {
    count++;
    cout << "count value:" << count << endl;
    STAFString machine = STAFString("local");

    STAFString request = STAFString("START SHELL COMMAND ") + handle->wrapData(command) + "WORKDIR /home/neominds/shoyab/wu-9.5/LinuxC/ RETURNSTDOUT STDERRTOSTDOUT WAIT";

    STAFResultPtr result = handle -> submit(machine, "PROCESS", request);
    if(result->rc != 0)
    {
            cout << "Process request failed with RC: " << STAFString(result->rc) << endl << "Result: " << result->result << endl;
            return result->rc;
    }
    STAFString ProcessRC = result->resultObj->get("rc")->asString();
    STAFString stdoutRC = result->resultObj->get("fileList")->iterate()->next()->get("rc")->asString();
    STAFString stdoutData = result->resultObj->get("fileList")->iterate()->next()->get("data")->asString();
    if(ProcessRC == "0")
    {
            if(stdoutRC == "0")
            {
                            cout << "Process completed successfully" << endl << "stdoutData: " << stdoutData << endl << endl;
            }
            else
            {
                    cout << "Error in Process Result, stdoutRC: " << stdoutRC << endl << "stderrData:" << stdoutData << endl;
                    return 10;
            }
    }
    else
    {
            cout << "Process failed with Process RC: " << ProcessRC << endl << "stderrData: " << stdoutData << endl;
            return 20;
    }
    return 0;
    }

    command I used to run:
    g++ -L /usr/local/staf/lib -lSTAF /usr/local/staf/scripts/scriptC.cpp -o /usr/local/staf/scripts/script -g

    Errors I am getting:
    /tmp/ccdvxH7W.o: In function `~STAFStringBuffer':
    /usr/local/staf/include/STAFString.h:847: undefined reference to `STAFStringFreeBuffer'
    /tmp/ccdvxH7W.o: In function `STAFString':
    /usr/local/staf/include/STAFStringInlImpl.cpp:21: undefined reference to `STAFStringConstruct'
    /usr/local/staf/include/STAFStringInlImpl.cpp:44: undefined reference to `STAFStringConstructFromCurrentCodePage'
    /usr/local/staf/include/STAFStringInlImpl.cpp:48: undefined reference to `STAFStringConstruct'
    /usr/local/staf/include/STAFStringInlImpl.cpp:59: undefined reference to `STAFStringConstructFromUInt'
    /usr/local/staf/include/STAFStringInlImpl.cpp:144: undefined reference to `STAFStringConstructCopy'
    /usr/local/staf/include/STAFStringInlImpl.cpp:176: undefined reference to `STAFStringConstruct'
    /usr/local/staf/include/STAFStringInlImpl.cpp:180: undefined reference to `STAFStringConstructCopy'
    /usr/local/staf/include/STAFStringInlImpl.cpp:190: undefined reference to `STAFStringConstructChar'
    /tmp/ccdvxH7W.o: In function `STAFString::length(STAFString::IndexRep) const':
    /usr/local/staf/include/STAFStringInlImpl.cpp:253: undefined reference to `STAFStringLength'
    /tmp/ccdvxH7W.o: In function `STAFString::buffer(unsigned int*) const':
    /usr/local/staf/include/STAFStringInlImpl.cpp:279: undefined reference to `STAFStringGetBuffer'
    /tmp/ccdvxH7W.o: In function `STAFString::toCurrentCodePage() const':
    /usr/local/staf/include/STAFStringInlImpl.cpp:536: undefined reference to `STAFStringToCurrentCodePage'
    /tmp/ccdvxH7W.o: In function `STAFString::isEqualTo(STAFString const&, STAFStringCaseSensitive_e) const':
    /usr/local/staf/include/STAFStringInlImpl.cpp:634: undefined reference to `STAFStringIsEqualTo'
    /tmp/ccdvxH7W.o: In function `STAFString::operator=(STAFString const&)':
    /usr/local/staf/include/STAFStringInlImpl.cpp:688: undefined reference to `STAFStringConstructCopy'
    /usr/local/staf/include/STAFStringInlImpl.cpp:696: undefined reference to `STAFStringDestruct'
    /tmp/ccdvxH7W.o: In function `STAFString::operator+=(STAFString const&)':
    /usr/local/staf/include/STAFStringInlImpl.cpp:748: undefined reference to `STAFStringConcatenate'
    /tmp/ccdvxH7W.o: In function `operator+(STAFString const&, STAFString const&)':
    /usr/local/staf/include/STAFStringInlImpl.cpp:760: undefined reference to `STAFStringConstructCopy'
    /usr/local/staf/include/STAFStringInlImpl.cpp:764: undefined reference to `STAFStringConcatenate'
    /usr/local/staf/include/STAFStringInlImpl.cpp:766: undefined reference to `STAFStringDestruct'
    /tmp/ccdvxH7W.o: In function `~STAFString':
    /usr/local/staf/include/STAFStringInlImpl.cpp:787: undefined reference to `STAFStringDestruct'
    /tmp/ccdvxH7W.o: In function `STAFObject':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:31: undefined reference to `STAFObjectConstructNone'
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:33: undefined reference to `STAFObjectConstructList'
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:35: undefined reference to `STAFObjectConstructMap'
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:37: undefined reference to `STAFObjectConstructMarshallingContext'
    /tmp/ccdvxH7W.o: In function `STAFObject::unmarshall(STAFString const&, unsigned int)':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:153: undefined reference to `STAFObjectUnmarshallFromString'
    /tmp/ccdvxH7W.o: In function `STAFObject::asString()':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:217: undefined reference to `STAFObjectGetStringValue'
    /tmp/ccdvxH7W.o: In function `STAFObject::iterate()':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:268: undefined reference to `STAFObjectConstructListIterator'
    /tmp/ccdvxH7W.o: In function `STAFObject::get(STAFString const&)':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:297: undefined reference to `STAFObjectMapGet'
    /tmp/ccdvxH7W.o: In function `STAFObject::getRootObject()':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:469: undefined reference to `STAFObjectMarshallingContextGetRootObject'
    /tmp/ccdvxH7W.o: In function `~STAFObject':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:480: undefined reference to `STAFObjectDestruct'
    /tmp/ccdvxH7W.o: In function `STAFObjectIterator::next()':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:511: undefined reference to `STAFObjectIteratorGetNext'
    /tmp/ccdvxH7W.o: In function `~STAFObjectIterator':
    /usr/local/staf/include/STAFDataTypesInlImpl.cpp:521: undefined reference to `STAFObjectIteratorDestruct'
    /tmp/ccdvxH7W.o: In function `STAFHandle::create(STAFString const&, STAFRefPtr<STAFHandle>&)':
    /usr/local/staf/include/STAFInlImpl.cpp:27: undefined reference to `STAFRegisterUTF8'
    /tmp/ccdvxH7W.o: In function `STAFHandle::submit(STAFString const&, STAFString const&, STAFString const&, unsigned int)':
    /usr/local/staf/include/STAFInlImpl.cpp:66: undefined reference to `STAFSubmit2UTF8'
    /usr/local/staf/include/STAFInlImpl.cpp:71: undefined reference to `STAFFree'
    /tmp/ccdvxH7W.o: In function `~STAFHandle':
    /usr/local/staf/include/STAFInlImpl.cpp:185: undefined reference to `STAFUnRegister'
    /tmp/ccdvxH7W.o: In function `~STAFRefPtr':
    /usr/local/staf/include/STAFRefPtr.h:180: undefined reference to `STAFThreadSafeDecrement'
    /usr/local/staf/include/STAFRefPtr.h:180: undefined reference to `STAFThreadSafeDecrement'
    /usr/local/staf/include/STAFRefPtr.h:180: undefined reference to `STAFThreadSafeDecrement'
    /tmp/ccdvxH7W.o: In function `STAFRefPtr<STAFObject>::operator=(STAFRefPtr<STAFObject> const&)':
    /usr/local/staf/include/STAFRefPtr.h:146: undefined reference to `STAFThreadSafeDecrement'
    /usr/local/staf/include/STAFRefPtr.h:164: undefined reference to `STAFThreadSafeIncrement'
    /tmp/ccdvxH7W.o: In function `~STAFRefPtr':
    /usr/local/staf/include/STAFRefPtr.h:180: undefined reference to `STAFThreadSafeDecrement'
    /tmp/ccdvxH7W.o: In function `STAFRefPtr<STAFHandle>::operator=(STAFRefPtr<STAFHandle> const&)':
    /usr/local/staf/include/STAFRefPtr.h:146: undefined reference to `STAFThreadSafeDecrement'
    /usr/local/staf/include/STAFRefPtr.h:164: undefined reference to `STAFThreadSafeIncrement'
    /tmp/ccdvxH7W.o: In function `~STAFRefPtr':
    /usr/local/staf/include/STAFRefPtr.h:180: undefined reference to `STAFThreadSafeDecrement'
    collect2: ld returned 1 exit status

     
  • Sharon Lucas
    Sharon Lucas
    2013-02-01

    Does it work if you specfiy the following g++ command to compile it?

    g++ -I/usr/local/staf/include -lSTAF -L/usr/local/staf/lib -o /usr/local/staf/scripts/script /usr/local/staf/scripts/scriptC.cpp

     
  • shoyab
    shoyab
    2013-02-04

    Hello slucas,

    Sorry for delay. I used your command it showing

    cc1plus: error: cannot find -l/usr/local/staf/include
    collect2: ld returned 1 exit status

     
  • Sharon Lucas
    Sharon Lucas
    2013-02-04

    Are the STAF include files in directory /usr/local/staf/include?

    In your scriptC.cpp program, I would do:

    #include "STAF.h"

    not

    #include "/usr/local/staf/include/STAF.h"

    Same comment for #include "/usr/local/staf/include/STAF_iostream.h"

    g++ -I /usr/local/staf/include -L /usr/local/staf/lib -lSTAF /usr/local/staf/scripts/scriptC.cpp -o /usr/local/staf/scripts/script -g

     
  • shoyab
    shoyab
    2013-02-06

    I know, I tried that also but it is giving error as
    /usr/local/staf/scripts/scriptC.cpp:2:18: fatal error: STAF.h: No such file or directory

     
  • Sharon Lucas
    Sharon Lucas
    2013-02-06

    Did you install STAF.h and the rest of the STAF include files in directory /usr/local/staf/include?

    Did you try compiling specifying the libraries after the source file using:

    g++ /usr/local/staf/scripts/scriptC.cpp -I /usr/local/staf/include -L /usr/local/staf/lib -lSTAF -o /usr/local/staf/scripts/script -g

    The only other thing I can suggest is to check the man pages for g++ on your system and to google for the errors you're seeing and on how to specify include directories on Ubuntu.

     
  • shoyab
    shoyab
    2013-02-13

    Thanks you very much I will check

     
  • shoyab
    shoyab
    2013-02-14

    Hello slucas,
    Below one is working thanks again

    g++ /usr/local/staf/scripts/scriptC.cpp -L /usr/local/staf/lib -lSTAF -o /usr/local/staf/scripts/script -g