[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Instanciation of global variables in shared library : recent changes ?

From: Helfer Thomas
Subject: Instanciation of global variables in shared library : recent changes ?
Date: Thu, 17 May 2012 10:02:05 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1


I already posted this question on fr.comp.lang.c++ without response.

I am experiencing some trouble in the instatiation of global variables in recent ubuntu versions. I don't know if this question is directly related to g++ or the linker as the following example works fine on debian squeeze with gcc 4.7 and fails on the two last versions of ubuntu. If the question is not relevant in this mailing list, please tell me where I shall redirect it.

I now show a simple code snipset to illustrate the trouble.

Consider the following code in file A.cxx :

struct A
std::cout << "A" << std::endl;

A a; // global variable !!

This file is used to produce a shared library :
g++ --shared -fPIC A.cxx -o

Consider now an empty main in file test.cxx:
int main(void){return EXIT_SUCCESS;}

This file is turned into an executable which is linked with the previous library:
g++ test.cxx -o test -L. -lA

on debian squeeze (an all previous versions of linux) : this prints "A" du to the constructor of the global variable
on ubuntu linux precise pangolin, nothing is printed !

This is really annoying and none of __attribute__ I tried solved the problem. This is also strange to see that if the libA is dlopened, the program displays the expected message ("A")...

Could anyone tell me :
1) what has changed
2) if the previous behaviour can be retrieved

Thanks for any help

reply via email to

[Prev in Thread] Current Thread [Next in Thread]