help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Re: libglpk0: excessive install dependencies


From: vijay patil
Subject: Re: [Help-glpk] Re: libglpk0: excessive install dependencies
Date: Thu, 13 Mar 2008 23:02:45 +0530

It would be nice to have this change (i.e. explicitly loading the dynamic library/shared object related to table feature in MathProg) work on MS Windows.

I ported example on page http://linux.die.net/man/3/dlopen to windows. We will need to use ifdefs at come places (loading, unloading, and getting function address), but actual function invocation is OS independent. I have tested program below on Windows XP and it works as expected.

---------------------------------------------
#include<stdio.h>
#include<stdlib.h>

#define WINDOWS /* Testing purpose only */

#ifdef WINDOWS
#include<windows.h>
#endif

int main(int argc, char **argv) {

#ifdef LINUX
    void *handle;
    char *error;
#else ifdef WINDOWS
    HINSTANCE handle;
#endif

    /* Note: OS Indepdent code. */
    double (*cosine)(double);   

#ifdef LINUX
    handle = dlopen ("libm.so", RTLD_LAZY);
    if (!handle) {
        fprintf (stderr, "%s\n", dlerror());
        exit(1);
    }

#else ifdef WINDOWS

    //handle = LoadLibrary(TEXT("libmySQL"));
    //handle = LoadLibrary(TEXT("odbc32"));
    handle = LoadLibrary(TEXT("msvcrt"));
    if(!handle) {
        fprintf(stderr, "Could not load shared library msvcrt.dll.\n");
        exit(1);
    }
#endif

#ifdef LINUX
    dlerror();    /* Clear any existing error */   
    cosine = dlsym(handle, "cos");

    if ((error = dlerror()) != NULL)  {
        fprintf (stderr, "%s\n", error);
        exit(1);
    }

#else ifdef WINDOWS
    cosine = (void*)GetProcAddress(handle, "cos");
    if(!cosine) {
        fprintf(stderr, "Could not find function 'cos' in dll.\n");

    }
#endif

    /* Note: OS Indepdent code. */
    printf ("%f\n", (*cosine)(2.0));
   
#ifdef LINUX
    dlclose(handle);

#else if WINDOWS
    FreeLibrary(handle);
#endif

    return 0;
}

On Tue, Mar 11, 2008 at 1:48 AM, Andrew Makhorin <address@hidden> wrote:
> I found a guide for the program changes needed at
> http://linux.die.net/man/3/dlopen
> According to
> http://sourceware.org/autobook/autobook/autobook_167.html
> Configure.ac also will need changes: At least AC_LIBTOOL_DLOPEN must
> be included.

> Do You know of better guides for shared libraries?

Please see:
http://www.gnu.org/software/libtool/manual.html

> I will try to make an implementation until Sunday March 17th.




_______________________________________________
Help-glpk mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-glpk



--
Vijay Patil
reply via email to

[Prev in Thread] Current Thread [Next in Thread]