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

  • SEARCH
  • Home
  • 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 6837253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:27:19+00:00 2026-05-26T23:27:19+00:00

I read a few tutorials about loading shared libraries and call functions in them.

  • 0

I read a few tutorials about loading shared libraries and call functions in them. I succeded on both points. There’s just one thing I didn’t see in any of the tutorials:

How do I return a value from a function in a shared library to the main code?

This is my shared library source:

#include <stdio.h>

char* entry(){
  printf("this is a working plugin\n");

  return "here we go!";
}

When i call it, i get “this is a working plugin” on the stdout. My question is now, how i can get the “here we go” string back to the main.c which looks like:

void *lib_handle;
void (*lib_func)();

...

lib_handle = dlopen("/home/tectu/projects/tibbers/plugins.so", RTLD_LAZY);
if(!lib_handle)
  error("coudln't load plugins", NULL);

lib_func = dlsym(lib_handle, "entry");
  if(!lib_func)
    error("coudln't find symbol in plugin library", NULL);

(*lib_func)();  // here i call the entry() from the .so

Something like this does not work:

printf("return value: %s\n, (*lib_func)());

So, any ideas?

Thank you.

  • 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-26T23:27:20+00:00Added an answer on May 26, 2026 at 11:27 pm

    It works when lib_func is properly declared:

    char* (*lib_func)();
    

    You might need to cast in the assignment from dlsym.

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

Sidebar

Related Questions

I'm learning about Pylons and I've read a few tutorials, but none of them
I'm a bit confused by a few tutorials that I read about the ListView.
I have read a few tutorials and in a book about using Active Record,
I've read a few threads on SO about usefulness of unit-testing various applications. The
i've just read a few posts on hiding Silverlight code in some way. Main
I've read a few topics about programs that combine Windows Forms and console applications,
I'm just starting to play around with directx and I've read a few articles
I read a few tutorials on getting memcached set up with Rails (2.3.5), and
I have read a few posts about people putting in either their own icons
I have read a few tutorials ( Catalin Zima , TheCansin ) regarding Deferred

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.