Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can not call application function from shared library. Unresolved symbol error
QtWS25 Last Chance

Can not call application function from shared library. Unresolved symbol error

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 325 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zim32
    wrote on last edited by zim32
    #1

    Hi all.

    I am trying to make a shared library, some sort of plugin, and I want this library to call some functions from my main app.
    Library code is (simplified):

    #include "../../core/plugin.h"
    #include "iostream"
    #include "objmeshloader.h"
    
    static void register_plugin(zim::AppContainer *container)
    {
        container->getMeshLoader()->registerLoader();
        std::cout << "Registering plugin objloader for app version: " << container->getAppMajorVersion() << std::endl;
    }
    
    

    When I try to load it using QLibrary it gives me error:

    Error: Cannot load library libobjloader.so.1.0.0: undefined symbol: _ZN3zim12AppContainer13getMeshLoaderEv

        QLibrary lib(filePath);
        lib.setLoadHints(QLibrary::ResolveAllSymbolsHint);
    
        if (!lib.load()) {
            qFatal("Unable to load plugin %s. Error: %s", qUtf8Printable(filePath), qUtf8Printable(lib.errorString()));
        }
    

    When I dump symbols it seems that everything is OK

    nm -g  app | grep _ZN3zim12AppContainer13getMeshLoaderEv
    000000000000738a T _ZN3zim12AppContainer13getMeshLoaderEv
    
    nm -g  plugins/libobjloader.so.1.0.0 | grep _ZN3zim12AppContainer13getMeshLoaderEv
    U _ZN3zim12AppContainer13getMeshLoaderEv
    

    Why it can not link library?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zim32
      wrote on last edited by
      #5

      So I solved thi issue.

      QMAKE_LFLAGS += -export-dynamic

      1 Reply Last reply
      3
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        @zim32 said in Can not call application function from shared library. Unresolved symbol error:

        libobjloader.so.1.0.0

        That's your whole file path? Is the working dir the same as location of that library, then?

        (Z(:^

        1 Reply Last reply
        1
        • Z Offline
          Z Offline
          zim32
          wrote on last edited by
          #3

          Library is located under ./plugins/ directory of my app. It works fine (because I was able to load library before calling container->getMeshLoader() function)

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zim32
            wrote on last edited by
            #4

            It seems I can't call any function defined if my main app.

            F.e. if I declare some simple function in plugin.h file

            extern "C" {
            void some_test_func();
            }
            

            and then define it in my main.cpp

            void some_test_func() {
                qDebug("some_test_func called");
            }
            

            Trying to call it from shared library gives me undefined symbol: some_test_func

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zim32
              wrote on last edited by
              #5

              So I solved thi issue.

              QMAKE_LFLAGS += -export-dynamic

              1 Reply Last reply
              3

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved