Building a Multi-threaded Program with Shared Libraries.

Posted on 2010-01-03
Last Modified: 2013-12-26
Dear experts,

I would like to write a multi-threaded program using shared libraries. There will be a front-end module calling external (kept as a file) shared libraries as separate threads. How can I achieve this, and I wonder how to create a Windows DLL like executables in Unix using C++.

Any document and comment welcomes.

Question by:GurcanK
    LVL 17

    Assisted Solution

    DLL is Windows Term, In Linux they are called shared libraries.
    See this:

    You can create linux .so files.
    Using gcc you can create a .so by using the -shared option.
    LVL 17

    Assisted Solution

    gcc -shared -o foo.c
    If you name your shared object lib*.so you can compile against it by using the `-l` option on your linker. Note that the "lib" is inferred in this circumstance. ie.
    ld -o a.out -lfoo someobject.o

    Alternatively you can load .so files at runtime, just as you can with .dlls, using dlopen() and dlsym().
    LVL 17

    Assisted Solution

    LVL 11

    Accepted Solution

    It would be nice to know which version of *nix you're using and which compilers you're using.  We're just assuming you're using gcc on Linux.

    You can't create Windows DLLs on Linux: the architecture is different and the concepts are different.  The program has to be compiled as multithreaded (there are 4 models on windows).  On Windows, a DLL is in 2 parts: a .lib for others to link with and a .dll for runtime.  The .dll can be either in the same directory as the executable or on the path.

    On *nix, you probably need a -mt flag somewhere on the compile or the link line.  The way shared objects are approached is different, depending on which version of *nix you are using.  Some versions of *nix have their own multi-threading libraries, others use pthreads.  HPUX, for instance uses .sl instead of .so and, depending on whether you are using HPUX 10 or 11, it uses different environment variables.  Solaris used to have its own thread library and AIX is another different ball game.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    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.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now