Important: Please read the Qt Code of Conduct -

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

  • 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/ undefined symbol: pop
    This is my .pro file:

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

    Thanks for helping.

    System Ubuntu 16.04 QtCreator 3.5.1 based on Qt 5.5.1

  • Lifetime Qt Champion


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

  • @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());
            void* initializer = dlsym(so_library, symname);
            if (initializer == NULL)
                fprintf(stderr, "Error loading %s.%s:\n%s", libname, symname, dlerror());
                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/", "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.

  • @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

Log in to reply