use of data structures in C++ API

I have written shared library consisting of functions and data structures. I want to know is it possible to share data between 2 programs using this shared library? if so how?
Unfortunately no. A shared library lets multiple programs share the same code, but they still have their own data. Even for the data within the library, the programs each have a separate copy.

What you want is shared memory.
Here is one of tutorials:
http://www.bogotobogo.com/cplusplus/libraries.php
You need to:
1) Declare exported functions in header file, which is used both by library and by main program.
2) Compile shared library with options -fPIC and link shared library with flag -shared.
3) Compile main program with flags -Ipath_to_library header and link with flags -llibrary_name -Lpath_to_library.
4) Set shell variable LD_LIBRARY_PATH to the path to library.
5) Run your program.
Last edited on
Thanks
2dhayden:
Actually it is possible for program to access variable from shared library, because library is mapped to the program's address space. Just need to use extern keyword in declaration in the main program. I think it's a bit more difficult in Windows, but I don't remember.
Last edited on
Topic archived. No new replies allowed.