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 9240571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:12:43+00:00 2026-06-18T08:12:43+00:00

I have a C++ shared library ( libtest-lib.so ) that is linked against by

  • 0

I have a C++ shared library ( libtest-lib.so ) that is linked against by 2 Qt Apps – App A and App B on an embedded Linux platform. I want to be able to reference a single shared pointer from libtest-lib.so by both App A and App B.

Libtest-lib.so is tiny –

test-lib_global.h:

#ifndef TESTLIB_GLOBAL_H
#define TESTLIB_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(TESTLIB_LIBRARY)
#  define TESTLIBSHARED_EXPORT Q_DECL_EXPORT
#else
#  define TESTLIBSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // TESTLIB_GLOBAL_H

testlib.h:

#ifndef TESTLIB_H
#define TESTLIB_H

#include "test-lib_global.h"

class TESTLIBSHARED_EXPORT TestLib
{
public:
    TestLib();

    // Notice that it is a reference
    TESTLIBSHARED_EXPORT static int& GetSingleInt();

    // Create a global audio buffer
    TESTLIBSHARED_EXPORT static signed short* getGlobalAudioBuffer();

};

#endif // TESTLIB_H

testlib.cpp:

#include "testlib.h"

int& TestLib::GetSingleInt()
{
    // keep the actual value as static to this function
    int min = 5;
    int max = 500;
    static int s_value(min + (rand() % (int)(max - min + 1)));

    // but return a reference so that everybody can use it
    return s_value;
}

// Create a global audio buffer
signed short* TestLib::getGlobalAudioBuffer() {

    // Create a static audio buffer
    static signed short* globalAudioBuffer = (signed short*)malloc( 1000 * sizeof(signed short) );

    return globalAudioBuffer;

}

TestLib::TestLib()
{
}

Both App A and App B do the following in their main:

int me = TestLib::GetSingleInt();
qDebug() << "SHARED INT IS: " << me;

signed short* audioBuffer = TestLib::getGlobalAudioBuffer();
qDebug() << "SHARED AUDIO BUFFER POINTER IS: " << &audioBuffer;

When I deploy libtest-lib.so and then build and deploy App A and App B, I get the following output:

App A:

SHARED INT IS:  108 
SHARED AUDIO BUFFER POINTER IS:  0xbe844ac8

App B:

SHARED INT IS:  108 
SHARED AUDIO BUFFER POINTER IS:  0xbeff0e64

The int is the same, but the pointer address is different. What am I doing wrong? How can I return an identical shared pointer from the library function?

Thanks –

  • 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-06-18T08:12:44+00:00Added an answer on June 18, 2026 at 8:12 am

    That’s not possible per se. Each process has its separate address space. A shared library shares instructions and data, not memory at runtime. You would have to use shared memory and synchronize between processes accordingly. Qt offers QSharedMemory, which provides a platform-independent API to a raw chunk of shared memory with some basic semaphore-based lock/unlock mechanism for synchronization.

    Alternatively, use another IPC mechanism to stream the audio data, e.g. pipes or sockets. That might make synchronization a whole lot easier, depending on the complexity of interaction between the processes.

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

Sidebar

Related Questions

I have problems using a shared library that was linked against a shared library.
Does Linux have a shared library that exports OS functions? msvcrt.dll -> libc.so.6 kernel32.dll
In Linux, I have a shared library I made that uses pthreads and a
I have an in-house shared library on RedHat Linux 5.0 that provides functions free
I have a shared library that I wish to link an executable against using
Suppose we have a shared library named libtest.so, there is one function foo in
I have existing Linux shared object file (shared library) which has been stripped. I
I have created a simple linux 32bit shared library(.so) for my rendering wrappers but
I have a specialized shared library that is loaded dynamically during the execution of
I have compiled a shared library on my Ubuntu 9.10 desktop. I want to

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.