Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 294541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:22:34+00:00 2026-05-12T06:22:34+00:00

I have a shared object (a so – the Linux equivalent of a Windows

  • 0

I have a shared object (a so – the Linux equivalent of a Windows dll) that I’d like to import and use with my test code.

I’m sure it’s not this simple 😉 but this is the sort of thing I’d like to do..

#include "headerforClassFromBlah.h"

int main()
{
    load( "blah.so" );

    ClassFromBlah a;
    a.DoSomething();
}

I assume that this is a really basic question but I can’t find anything that jumps out at me searching the web.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:22:35+00:00Added an answer on May 12, 2026 at 6:22 am

    There are two ways of loading shared objects in C++

    For either of these methods you would always need the header file for the object you want to use. The header will contain the definitions of the classes or objects you want to use in your code.

    Statically:

    #include "blah.h"
    int main()
    {
      ClassFromBlah a;
      a.DoSomething();
    }
    
    gcc yourfile.cpp -lblah
    

    Dynamically (In Linux):

    #include <stdio.h>
    #include <stdlib.h>
    #include <dlfcn.h>
    int main(int argc, char **argv) {
        void *handle;
        double (*cosine)(double);
        char *error;
        handle = dlopen ("libm.so", RTLD_LAZY);
        if (!handle) {
            fprintf (stderr, "%s\n", dlerror());
            exit(1);
        }
        dlerror();    /* Clear any existing error */
        cosine = dlsym(handle, "cos");
        if ((error = dlerror()) != NULL)  {
            fprintf (stderr, "%s\n", error);
            exit(1);
        }
        printf ("%f\n", (*cosine)(2.0));
        dlclose(handle);
        return 0;
    }
    

    *Stolen from dlopen Linux man page
    The process under windows or any other platform is the same, just replace dlopen with the platforms version of dynamic symbol searching.

    For the dynamic method to work, all symbols you want to import/export must have extern’d C linkage.

    There are some words Here about when to use static and when to use dynamic linking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 177k
  • Answers 177k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's a sample code for creating radio buttons programmatically: //create… May 12, 2026 at 3:23 pm
  • Editorial Team
    Editorial Team added an answer You can also check out the org.eclipse.jface.fieldassist.AutoCompleteField class. It's not… May 12, 2026 at 3:23 pm
  • Editorial Team
    Editorial Team added an answer are you sure recv isn't returning "" -- meaning the… May 12, 2026 at 3:23 pm

Related Questions

I have a shared object (a so - the Linux equivalent of a Windows
I created a shared library ( *.so ) using the *.o object code files
I have a third-party library which consists mainly of a large number of static
I have a set of Win32 applications that share information using a shared memory
I have a VB.NET application where various objects are going to access some common

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.