Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Calls from shared object to main app fail if I build with QtCreator
Forum Updated to NodeBB v4.3 + New Features

Calls from shared object to main app fail if I build with QtCreator

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
4 Posts 2 Posters 459 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RobDaNet
    wrote on last edited by RobDaNet
    #1

    Hello to everybody,
    something rather strange is happening when I build my c project with QtCreator.
    I have this application which links dynamically to a shared library, using ldopen and friends. The library uses some functionality inside the main application. Everything works fine if I build the project from the terminal, while, if I build it with QtCreator, calling from the library fails, and it fails only if the library's function calls a function inside the main application. If I remove this call, it works as it should.
    This is the error I get:
    /Programming/C/emme_1/emme_1: symbol lookup error: ./modtest/libtest_add.so: undefined symbol: pop
    This is my .pro file:

    TEMPLATE = app
    CONFIG += console c++11
    CONFIG -= app_bundle
    CONFIG -= qt
    QMAKE_CFLAGS += -DTRACE_ASM
    QMAKE_CFLAGS += -rdynamic -lm -L/-dl
    

    Thanks for helping.

    Edit:
    System Ubuntu 16.04 QtCreator 3.5.1 based on Qt 5.5.1

    R 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That sounds a bit strange. How do you make your library call that function from your main application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        That sounds a bit strange. How do you make your library call that function from your main application ?

        R Offline
        R Offline
        RobDaNet
        wrote on last edited by
        #3

        @SGaist Hi,

        I call the function via pointer to function, like this:

        typedef void (*native_fn)(eVm*);
        
        native_fn load_so(const char* libname, const char* symname)
        {
            void* so_library = dlopen(libname, RTLD_LAZY);
            if (so_library == NULL)
            {
                fprintf(stderr, "Error loading %s\n:%s", libname, dlerror());
            }
            else
            {
                void* initializer = dlsym(so_library, symname);
                if (initializer == NULL)
                {
                    fprintf(stderr, "Error loading %s.%s:\n%s", libname, symname, dlerror());
                }
                else
                {
                    fprintf(stdout, "Loading %s:%s\n", libname, symname);
                    native_fn sobj = (native_fn)initializer;
                    return sobj;
                }
            }
            return NULL;
        }
        

        The function is then stored inside an object's metatable like this:

            ...
            eObject name = eobj_string("addtest");
            eFunction* f = efunction_new(OBJ_AS_CSTR(name), NULL);
            f->fp = load_so("./modtest/libtest_add.so", "wr_add_test");
            f->is_native = true;
            eObject func = ((eObject){ EFUNCTION, .value.object=f });
            edict_insert(&vm->globals,  OBJ_AS_CSTR(name), func);
            ...
        

        addtest is the named used to search the function and call it.
        Thanks a lot for your help.

        1 Reply Last reply
        0
        • R RobDaNet

          Hello to everybody,
          something rather strange is happening when I build my c project with QtCreator.
          I have this application which links dynamically to a shared library, using ldopen and friends. The library uses some functionality inside the main application. Everything works fine if I build the project from the terminal, while, if I build it with QtCreator, calling from the library fails, and it fails only if the library's function calls a function inside the main application. If I remove this call, it works as it should.
          This is the error I get:
          /Programming/C/emme_1/emme_1: symbol lookup error: ./modtest/libtest_add.so: undefined symbol: pop
          This is my .pro file:

          TEMPLATE = app
          CONFIG += console c++11
          CONFIG -= app_bundle
          CONFIG -= qt
          QMAKE_CFLAGS += -DTRACE_ASM
          QMAKE_CFLAGS += -rdynamic -lm -L/-dl
          

          Thanks for helping.

          Edit:
          System Ubuntu 16.04 QtCreator 3.5.1 based on Qt 5.5.1

          R Offline
          R Offline
          RobDaNet
          wrote on last edited by
          #4

          @RobDaNet
          Ok, I solved my problem (actually I got help on SO). Nevertheless, this was a good occasion to register on QtForum ;)

          This line:

          QMAKE_CFLAGS += -rdynamic -lm -L/-dl
          

          should be

          QMAKE_LFLAGS += -rdynamic -lm -L/-dl
          
          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