THEn
THEn

Reputation: 1938

Having issue linking shared object in linux

I have been provided with .so file.

ldd libTodoAPI.so
    linux-vdso.so.1 =>  (0x00007ffc766b8000)
    libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fead8e3f000)
    libsqlite3.so => /usr/lib/libsqlite3.so (0x00007fead8b6a000)
    libQt5Network.so.5 => /usr/lib/libQt5Network.so.5 (0x00007fead8804000)
    libQt5Script.so.5 => /usr/lib/libQt5Script.so.5 (0x00007fead838b000)
    libQt5Core.so.5 => /usr/lib/libQt5Core.so.5 (0x00007fead7c4f000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fead78cd000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fead76b7000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fead72ed000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fead70e9000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fead6ecc000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fead6bc3000)
    libicui18n.so.53 => /usr/lib/libicui18n.so.53 (0x00007fead6777000)
    libicuuc.so.53 => /usr/lib/libicuuc.so.53 (0x00007fead63ec000)
    libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fead61ea000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fead5fe2000)
    libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fead5cd1000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fead949a000)
    libicudata.so.53 => /usr/lib/libicudata.so.53 (0x00007fead4649000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fead43d9000)

and with header

#ifndef TODO_API_H
#define TODO_API_H

#include <string>

using namespace std;

namespace todoarea {
    class TodoAPI{
    public:
        static string checkDoer();
        static string getInformation();
        static string callTask(string funcName, string param);
        static string Done(string param);
        static string returnStatus(string param);
        static string Close();
    };
}

#endif //TODO_API_H

I am trying to create a program to call from this shared object and having problem.

//load.cpp
#include <iostream>
#include "TodoAPI.h"

using namespace todoarea;

int main(int argc, char **argv)
{
 //  TodoAPI* myTodo = new TodoAPI();
 //  myTodo>checkDoer();
 //   TodoAPI m;
   string data = TodoAPI::checkDoer();
   string a = TodoAPI::getInformation();
}

When I try to compile it

g++ load.cpp -lTodoAPI
/tmp/ccs1hwWP.o: In function `main':
load.cpp:(.text+0x27): undefined reference to `todoarea::TodoAPI::checkDoer[abi:cxx11]()'
load.cpp:(.text+0x33): undefined reference to `todoarea::TodoAPI::getInformation[abi:cxx11]()'
collect2: error: ld returned 1 exit status

If I try to see the so file

nm -s libTodoAPI.so
nm: libTodoAPI.so: no symbols

Also

nm -DC libTodoAPI.so  | grep todoarea
000000000000a63a T todoarea::TodoAPI::Done(std::string)
000000000000a098 T todoarea::TodoAPI::callTask(std::string, std::string)
0000000000009e9c T todoarea::TodoAPI::getInformation()
000000000000a398 T todoarea::TodoAPI::returnStatus(std::string)
0000000000009ca0 T todoarea::TodoAPI::checkDoer()
000000000000a8dc T todoarea::TodoAPI::Close()

It has lots of functions (mostly seems like Qt) listed when I try nm with -D option.

Question: How can I use this library to create app in linux? What am I doing wrong? I tried to call functions dynamically but failed. Any help would be appreciated.

Upvotes: 2

Views: 165

Answers (1)

Mike Kinghan
Mike Kinghan

Reputation: 61610

You are falling foul of an ABI break between the GCC release with libTodoAPI.so was built and the one with which you are compiling your code. See Dual ABI Troubleshooting

Troubleshooting

If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.

Upvotes: 2

Related Questions