?
Solved

Add DLL Functions to a c++ program for linux

Posted on 2003-11-17
10
Medium Priority
?
328 Views
Last Modified: 2010-04-02
Is it possible to load a DLL library of functions to a c++ program written for linux?
0
Comment
Question by:slogalbo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9766167
Sure it is - see the HOWTO at http://www.isotton.com/howtos/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html

#include <iostream>
#include <dlfcn.h>


int main() {
    using std::cout;
    using std::cerr;

    cout << "C++ dlopen demo\n\n";

    // open the library
    cout << "Opening hello.so...\n";
    void* handle = dlopen("./hello.so", RTLD_LAZY);
   
    if (!handle) {
        cerr << "Cannot open library: " << dlerror() << '\n';
        return 1;
    }
   
    // load the symbol
    cout << "Loading symbol hello...\n";
    typedef void (*hello_t)();
    hello_t hello = (hello_t) dlsym(handle, "hello");
    if (!hello) {
        cerr << "Cannot load symbol 'hello': " << dlerror() <<
            '\n';
        dlclose(handle);
        return 1;
    }
   
    // use it to do the calculation
    cout << "Calling hello...\n";
    hello();
   
    // close the library
    cout << "Closing library...\n";
    dlclose(handle);
}

0
 

Author Comment

by:slogalbo
ID: 9766244
Thanks so much for the quick response.

Any Idea where I can find the API for download?
0
 
LVL 86

Expert Comment

by:jkr
ID: 9766270
Which 'API' are you looking for? 'dlopen()', 'dlsym()' and 'dlclose()' support comes with every Linux installation, just type

man dlopen

:o)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 9766283
0
 

Author Comment

by:slogalbo
ID: 9766530
Thanks, this helps me more than you know.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9773335
Hm, so, do you have additional questions or can we close this one?
0
 

Author Comment

by:slogalbo
ID: 9773361
Well I would still like to know if I can download this API for use in a Win32 environment, or if it is specifically for linux.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9773423
The above is specifically for Linux. Win32 has it's own mechanisms to do that, see e.g. http://www.codeguru.com/win32/dyndllclass.shtml ("Dynamically loading classes from DLLs "). However, you could create an abstraction, as the similarities overbalance, e.g.

#ifdef WIN32
#define dlopen(x,y) LoadLibrary(x)
#define dlsym(x,y) GetProcAddress(x,y)
#define dlclose(x) FreeLibrary(x)
#endif

0
 

Author Comment

by:slogalbo
ID: 9773462
Okay this has helped me.  The thread is closed.

Thanks again.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 9773682
>>The thread is closed

Hm, to close this, you'll need to click on 'accept comment as answer' next to one of my comments :o)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question