Alternative to QLibrary or libtool

Hello everyone, I made a port in Windows XP for a program written in C + + for Linux.
To make haste I used programming environment for Qt 4.8.2 MinGW compiler 4.6.2
In this program originally written for Linux makes use of libtool library to load dynamic libraries.
I report the relevant piece of code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    void Model::LoadControllerModule( const char *lib )
    {
        printf( "[Ctrl \"%s\"]\n", lib );

        // Initialise libltdl.
        int errors = lt_dlinit();
        if (errors)
        {
          printf( "Libtool error: %s. Failed to init libtool. Quitting\n",
                  lt_dlerror() ); // report the error from libtool
          puts( "libtool error #1" );
          fflush( stdout );
          exit(-1);
        }

        printf( "[STAGEPATH: %s]\n",  FileManager::stagePath().c_str());

        lt_dlsetsearchpath( FileManager::stagePath().c_str() );
        printf( "ltdl search path: %s\n", lt_dlgetsearchpath() );

        // PLUGIN_PATH now defined in config.h
        lt_dladdsearchdir( PLUGIN_PATH );
        printf( "ltdl search path: %s\n", lt_dlgetsearchpath() );

        lt_dlhandle handle = NULL;
     
        // the library name is the first word in the string
        char libname[256];
        sscanf( lib, "%s %*s", libname );

        printf( "libname: %s\n", libname );

        if(( handle = lt_dlopenext( libname ) ))
        {
            model_callback_t initfunc = (model_callback_t)lt_dlsym( handle, 
                                         "Init" );
            if( initfunc  == NULL )
            {
                printf( "(Libtool error: %s.) Something is wrong with your 
                          plugin.\n",
                          lt_dlerror() ); // report the error from libtool
                puts( "libtool error #1" );
                fflush( stdout );
                exit(-1);
            }

            // pass complete string into initfunc
            AddCallback( CB_INIT, initfunc, new CtrlArgs(lib, World::ctrlargs)
                        );
        }
        else
        {
            printf( "(Libtool error: %s.) Can't open your plugin.\n",
                    lt_dlerror() ); // report the error from libtool
          
            PRINT_ERR1( "Failed to open \"%s\". Check that it can be found by 
                         searching the directories"
                        "in your STAGEPATH environment variable, or the current
                         directory if STAGEPATH "
                        "is not set.]\n", libname );
               
            printf( "ctrl \"%s\" STAGEPATH \"%s\"\n", libname, PLUGIN_PATH );
               
            puts( "libtool error #2" );
            fflush( stdout );
            exit(-1);
        }
     
        fflush(stdout);
   }

As I said before I used the Qt environment to solve the problem using the class QLibrary
I report the code that replaces the one above:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    void Model::LoadControllerModule( const char *lib )
    {
        printf( "Model::LoadControllerModule() - [Ctrl \"%s\"", lib );
        fflush(stdout);

        char libname[256];
        strcpy(libname, lib);
        printf( "\nModel::LoadControllerModule() - libname = %s\n", libname );
        QLibrary library(libname);
        model_callback_t initfunc = (model_callback_t)library.resolve("Init");
        printf( "]" );

        if(initfunc == 0)
        {
            // report the error from QLibrary
            printf("\nModel::LoadControllerModule() - QLibrary error(%s) 
                    \nSomething is wrong with your
                    plugin.\n", library.errorString().toStdString().c_str());
            printf("QLibrary error #1\n");

            return;
        }

        // pass complete string into initfunc
        AddCallback(CB_INIT, initfunc, new CtrlArgs(lib, World::ctrlargs));
    }

In doing so it works fine.
Now I want to find a solution that does not use Qt 4.8.2 but using normal code in MinGW 4.7.1 using Code :: Blocks IDE as 13:12.
Can you help me in this regard?
What's wrong with using dlopen/dlsym/dlclose on POSIX, along with LoadLibrary/GetProcAddress/FreeLibrary on Windows?
Hi kbw, I solved using LoadLibrary and I report the solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <windows.h>
#include <stdio.h>
...
void Model::LoadControllerModule( const char *lib )
{
    typedef int (__cdecl *MYPROC) (Model*, CtrlArgs*);

    HINSTANCE hinstLib;
    MYPROC ProcAdd;
    BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;

    // the library name is the first word in the string
    char libname[256];
    sscanf( lib, "%s %*s", libname );
    printf( "libname: %s\n", libname );
    hinstLib = LoadLibrary(TEXT(libname));
    if (hinstLib != NULL) {
        printf("\n------------------------------------------\n");
        printf("\nhinstLib risulta essere non NULL\n");
        printf("\n------------------------------------------\n");

        ProcAdd = (MYPROC) GetProcAddress(hinstLib, "Init");
        model_callback_t initfunc = (model_callback_t)ProcAdd;
        if(initfunc == 0)
        {
            // report the error from QLibrary
            //printf("\nModel::LoadControllerModule() - QLibrary error(%s) \nSomething is wrong with your plugin.\n",
            //       library.errorString().toStdString().c_str());
            printf("LoadLibrary error #1\n");

            return;
        }

        if (NULL != ProcAdd) {
            fRunTimeLinkSuccess = TRUE;

            if (NULL != initfunc) {
                // pass complete string into initfunc
                AddCallback( CB_INIT, initfunc, new CtrlArgs(lib, World::ctrlargs) );
            }
            else {
                printf("\n------------------------------------------\n");
                printf("\nERRORE: initfunc risulta essere NULL\n");
                printf("\n------------------------------------------\n");
            }
        }
        else {
            printf("\n------------------------------------------\n");
            printf("\nERRORE: hinstLib risulta essere NULL\n");
            printf("\n------------------------------------------\n");
        }

        // Nota: va inserita dove si vuole scaricare la libreria dll
        //       per liberare la memoria e permettere di caricare
        //       un'altra libreria dll
        //fFreeResult = FreeLibrary(hinstLib);
    }
    else {
        printf("\n------------------------------------------\n");
        printf("\nERRORE: ProcAdd risulta essere NULL\n");
        printf("\n------------------------------------------\n");
    }
    if (!fRunTimeLinkSuccess)
        printf("Problema nel caricare la dll\n");
}

But there remains the problem of Libtool library / ltdl not resolved, I would like to know where I'm wrong.
In practice, this line is not resolved
 
if(( handle = lt_dlopenext( libname ) ))

I see a message written by me
1
2
3
4
5
6
printf( "(Libtool error: %s.) Can't open your plugin.\n",
                lt_dlerror() ); // report the error from libtool

        PRINT_ERR1( "Failed to open \"%s\". Check that it can be found by searching the directories"
                    "in your STAGEPATH environment variable, or the current directory if STAGEPATH "
                    "is not set.]\n", libname );

Could you give a simple example of a dynamic library created with Libtool and loaded into a main ltdl from running under Windows with MinGW ?
I'm a little lost.

Your original implementation used Libtool, but you replaced it with your own calls, right? So what's using libtool, is it a client?
Is Litool this ?
http://en.wikipedia.org/wiki/GNU_Libtool

If so, why do you want to use it on windows ?


I really don't understand what you want to do, why Qt implementation is not an option (it is portable) or why LoadLibrary and GetProcAddress is not enough (these are standard on windows)

Libtool it is only used on *nix operating systems.
Ok, what I want to do is use a form of creation and loading of dynamic libraries valid for both Linux and Windows. Because there is a Windows version of Libtool (which is normally used in Linux) I was thinking of using it.
I was thinking of using it.
I wou;dn't bother. It's an unnecessary troublesome dependency.

But if you need to use, we ought be able to help.
Topic archived. No new replies allowed.