473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

external linkage of variable (IBM XL C++ on AIX)

Hello,

please forgive me for posting this if this problem has come up before.
I could not find any hint with google.

I am porting a bunch of source-code from SUN-OS to AIX at the moment
and have the following situation (simplified and renamed for better
understanding)
Source a.cc --> compiled and linked into a binary together with the
shared object underneath

.....
AnyType *globalAnyType;
....
Source b.cc --> compiled and linked into a shared object:

....
extern AnyType *globalAnyType;
....

globalAnyType = new AnyType(....); <----- Segment-Violation here
On SUN the code worked fine. On AIX I get no compile-errors and no
link errors. So I assume external references are resolved.

I found out using dbx that the assignment from "new AnyType(...)" to
globalAnyType causes the Segment-Violation. The external declared
globalAnyType appears not to be backed up by memory (dbx shows "nil").

To proove this I replaced globalAnyType by a non-extern-declared
variable of Type AnyType and....that works.

Does anyone have got an idea on why external binding of a variable
does not work in this case? Are there circumstances you can think of?

Might special compiler/linker options help?

I have to mention that I port from an old compiler without
namespace-support to a compiler with namespace-support. I already
checked if the variables may be in different namespaces because of
side effects of include files. But I concluded that this would be
logically impossible.

Thanks for any idea what I could try.

Cheers
Thomas

Mar 6 '06 #1
3 2255
Thomas Lenarz wrote:
Hello,

please forgive me for posting this if this problem has come up before.
I could not find any hint with google.

I am porting a bunch of source-code from SUN-OS to AIX at the moment
and have the following situation (simplified and renamed for better
understanding)
Source a.cc --> compiled and linked into a binary together with the
shared object underneath

.....
AnyType *globalAnyType;
....
Source b.cc --> compiled and linked into a shared object:

....
extern AnyType *globalAnyType;
....

globalAnyType = new AnyType(....); <----- Segment-Violation here
On SUN the code worked fine. On AIX I get no compile-errors and no
link errors. So I assume external references are resolved.

I found out using dbx that the assignment from "new AnyType(...)" to
globalAnyType causes the Segment-Violation. The external declared
globalAnyType appears not to be backed up by memory (dbx shows "nil").

To proove this I replaced globalAnyType by a non-extern-declared
variable of Type AnyType and....that works.

Does anyone have got an idea on why external binding of a variable
does not work in this case? Are there circumstances you can think of?

Might special compiler/linker options help?

I have to mention that I port from an old compiler without
namespace-support to a compiler with namespace-support. I already
checked if the variables may be in different namespaces because of
side effects of include files. But I concluded that this would be
logically impossible.

Thanks for any idea what I could try.

Cheers
Thomas


So the new and the constructor succeeded, but the pointer assignment
failed? Is there any funky operator overloading related to AnyType? Can
you look at &globalAnyType (the address of your global) in your
debugger? Try reversing the two declarations by putting the actual
variable in b.cc and the extern declaration in a.cc. Now do you have a
problem with accessing it in the latter?

I'm guessing that this might be a weird symptom of an initialization
order fiasco (cf.
http://www.parashift.com/c++-faq-lit...html#faq-10.12 and
following), and a different order of initialization allowed the code to
work on your other compiler but kills it here. Subtle things can happen
with the order of initialization. See the FAQ for a solution to such
problems.

You may also want to ask in a newsgroup related to your compiler (see
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9 for some
ideas).

Cheers! --M

Mar 6 '06 #2
On 6 Mar 2006 13:01:45 -0800, "mlimber" <ml*****@gmail.com> wrote:
So the new and the constructor succeeded, but the pointer assignment
failed? Yes!
Is there any funky operator overloading related to AnyType? No!
Can
you look at &globalAnyType (the address of your global) in your
debugger? Yes!

Result is: definition in a.cc &globalAnyType: 47114711 (Can't remember
the exact number. But it appears to be a proper address.

extern declaration in bcc &globalAnyType: 0 (zero)
Try reversing the two declarations by putting the actual
variable in b.cc and the extern declaration in a.cc. Now do you have a
problem with accessing it in the latter? Unfortunately I haven't had the time to try. But I will!

I'm guessing that this might be a weird symptom of an initialization
order fiasco (cf.
http://www.parashift.com/c++-faq-lit...html#faq-10.12 and
following), and a different order of initialization allowed the code to
work on your other compiler but kills it here. Subtle things can happen
with the order of initialization. See the FAQ for a solution to such
problems.

You may also want to ask in a newsgroup related to your compiler (see
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9 for some
ideas).


Thanks a lot for your great hints and recommendations. I didn't know
the FAQ and about the initialization order fiasco. It's really
interesting and I will look into this a bit deeper.

But I'm a bit sceptical wether this is really the problem. In the end
"new AnyType(...)" is the only Object or Class-Reference involved and
globalAnyType is just a variable supposed to hold the pointer to the
AnyType-Instance.

For me it seems weird that the "extern declared globalAnyType"
doesn't have the the same address like the "defined globalAnyType"
after startup and the linker hasn't complained about anything
unresolved.

Thanks a lot for your help again. I will post the solution, when I
(hopfully) find it. :-)

Cheers
Thomas
Mar 7 '06 #3
On Mon, 06 Mar 2006 19:59:53 GMT, Th***********@bigfoot.de (Thomas
Lenarz) wrote:
Source a.cc --> compiled and linked into a binary together with the
shared object underneath

.....
AnyType *globalAnyType;
....
Source b.cc --> compiled and linked into a shared object:

....
extern AnyType *globalAnyType;
....

globalAnyType = new AnyType(....); <----- Segment-Violation here
Does anyone have got an idea on why external binding of a variable
does not work in this case? Are there circumstances you can think of?

Might special compiler/linker options help?

Solution for this problem is:

There are different link-types on AIX for shared-libraries. In this
case it is necessary to use "Run-Time-Linking". This means that
symbolic information is resolved at program-load-time rather than
link-time.

This is forced by generating the the library with the exra option -G
and generating the main-application with the extra option -rtl.

Using "Default Linking" did not resolve the external variable
correctly.

I am sorry. I know it is OT here, but I just wanted to document the
solution for completeness.

Thomas
Mar 25 '06 #4

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

Similar topics

47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
1
by: peteh | last post by:
Hi All; I'm having a problem running an external routine (C language) under DB2 8.2 (FP 9) on AIX 5.3. Since the code was mostly copied from the DB2 sample library, I'm pretty sure it's sound....
1
by: Praveen | last post by:
Hi, I have installed WebSphere Portal on AIX and connected to DB2 on a remote machine, Getting the followin errors when trying to get the values from database thru applications installed on...
19
by: J. J. Farrell | last post by:
After many years of dealing with definition and linkage issues in ways that I know to be safe, I've decided it's time to try to understand this area properly. Consider a header file with the file...
4
by: Peter Ammon | last post by:
I would like to share a variable between two functions defined in two separate source files; no other functions will need the global variable so I'd prefer to not give it file scope. Thus, I want...
3
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
5
by: bravo.loic | last post by:
hi, I'm trying to make a local install of python 2.5 on AIX and I'm getting some trouble with _curses. Here is how I tried to compile it : export BASE=/usr/local/python251
1
by: Kurt | last post by:
The C++ standard (in 3.5:6, p42Example) said: static int i = 0; // 1 void g() { int i; //2: i has no linkage { extern int i; //3: external linkage
3
by: pompeyoc | last post by:
Hi. I was wondering if anyone out here knows if there is a limit to the size of an external stored procedure? I am currently using VB programs in Windows to call small COBOL stored procs residing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.