473,654 Members | 3,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with UNIX/Linux Shared Libraries and Global variables ...

I observe a behavior with shared libraries (.so) and global variables
that I cannot understand ...
I'd appreciate if someone can explain the behavior ..

Scenario 1:
aTest is an executable on Solaris/Linux built from main.o (main.cpp)
bTest dynamically loads a shared libraires mylib1.so and mylib2.so
both built from mylibsrc.o (mylibsrc.cpp)
cmylibsrc.cpp contains a global variable 'int MyGlobal' that is non
static and not extern (simply int MyGlobal)
dI have extern C Set and Get functions in mylibsrc.cpp to access
MyGlobal
eUnder these circumstatnces, when I run Test, MyGlobal seems to have
two instances in memory, one for each .so
Their runtime values (modified by dlsym(handle, Set)) and
addresses are different as expected.

Scenario 2:
aEverything is same as Scenario 1 except ..
bmain.cpp (Test) also has a global non-static, non-extern variable
'int MyGlobal'
cNow when I run Test, all 3 MyGlobal(s) (in Test, mylib1.so and
mylib2.so) are the same memory address and same value.

Why is the behavior under these to scenarios different ?
I expect that MyGlobal in main.cpp should have its own instance ...

p.s. I use -fPIC / -KPIC and -Bsymbolic while generating the .so(s)

Thanks in advance ...
Jun 27 '08 #1
1 3061
On Fri, 20 Jun 2008 18:01:10 -0700 (PDT), vi***********@g mail.com
wrote in comp.lang.c:
I observe a behavior with shared libraries (.so) and global variables
that I cannot understand ...
I'd appreciate if someone can explain the behavior ..
I am sure someone can, in an appropriate group like
news:comp.unix. programmer or news:comp.os.li nux.development .apps.

You are off-topic here, the C language does not define the details of
specific tool sets and features like shared libraries.
Scenario 1:
aTest is an executable on Solaris/Linux built from main.o (main.cpp)
bTest dynamically loads a shared libraires mylib1.so and mylib2.so
both built from mylibsrc.o (mylibsrc.cpp)
And even more off-topic here. The C++ language defines ways to link
code to compatible C compilers, the C language does not define linkage
to any other language at all.

But this is more of a platform issue than a C++ one.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
624
by: Gary Cote | last post by:
>Description: I've recently compiled mysql 4.0.14 on redhat 8.0. The installation fails, however, when running mysql_install_db. I've attached a transcript below. I gather from searching the 'net that this isn't an entirely unusual thing to happen, and is likely the result of some misconfiguration on my part, or perhaps a version incompatability with my libc. Unfortunately, I haven't seen any concrete suggestions on how to get past it.
4
6766
by: PaulR | last post by:
Hi, We have a Server running SLES 8 and 3GB memory, with 1 DB2 instance and 2 active Databases. General info... DB2level = "DB2 v8.1.0.72", "s040914", "MI00086", and FixPak "7" uname -a = Linux galahad 2.4.19-64GB-SMP #1 SMP /etc/sysctl.conf kernel.shmmax=268435456
3
4258
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is active? Can the setting of LD_LIBRARY_PATH guanrantee that the correct one is executed? 2> In MS-WINDOWS, once a DLL is loaded by one allication, this DLL will be used by the subsequent appication. Does UNIX have the same
1
313
by: Peetah_junkmail | last post by:
Hi, I'm not sure this is completely a C related question since it's more about linking problems, so don't hesitate to redirect me to a more appropriate NG. I have a set of useful functions (let's call this SUF) that facilitates my life when coding, such as memory allocation wrappers or generic string functions. I have a project composed of a shared library (SL) and a main program (MP) using SL. For some reasons, I don't want to make a...
5
5387
by: Michael Rudolph | last post by:
Hi newsgroup, I have an issue with the configuration of a DB2 federated database (WebSphere Information Integrator) in conjunction with the relational wrapper for Oracle on AIX. DB2 seems to not use the existing tnsnames.ora. The Oracle client is installed and the connection to the Oracle database using tnsping and sqlplus is possible (for the db2instance user). For that I changed the environment for the db2instanceuser and added the...
2
1481
by: baileyxia | last post by:
Hi, all I am learning how to import c code in python. Here is my simple code foo.c: ===================== #include <Python.h> void bar() { printf("Hello! C wrap!"); } static PyObject *foo_bar(PyObject *self, PyObject *args) {
1
5954
by: nidumolu | last post by:
Hi, Can I have a Global variable declared in the application, be used in a shared library opened through 'dlopen' ? For example: I have a Library 'libfoo.so' with the following: libfoo_headerfile.h =============
3
10335
by: ankugoe7 | last post by:
Is it possible to share global variables such that all applications which use shared libraries can see the changes made to the global variables by the other applications.
4
2338
by: stuntgoat | last post by:
Hi, I want to start using Python 2.6 and 3000. I have several questions. What, in your experiences, is a functionally elegant solution to installing 2.6 and 3 from source without breaking package dependencies on your favorite Linux/Unix flavor? Is compiling Python 2.6 and 3.0 on a *nix development machine and having it work seamlessly as simple as choosing a particular flavor or are there always going to be package...
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.