Different linking behavior between g++ 4.5.2 and 4.6.1

2011-11-15 Thread Carlo Pinciroli

Dear forum,

I have a problem with linking of a program I have wrote. Instead of giving
you the entire program, which is pretty large, I have prepared a basic
example that you can find attached to this message. The example uses CMake
to compile.

I have three files:

= LIB2.CPP =
#include 
class Lib2 {
public:
  Lib2() {
std::cout << "Lib2" << std::endl;
  }
};
Lib2 lib2;

= LIB1.CPP =
#include 
class Lib1 {
  Lib1() {
std::cout << "Lib1" << std::endl;
  }
};

= MAIN.CPP 
#include 
int main() {
  std::cout << "Ciao" << std::endl;
  return 0;
}

The file lib2.cpp is compiled into a dynamic library called lib2. The file
lib1.cpp is compiled into a dynamic library called lib1 and that links to
lib2. Finally, main.cpp is compiled into an executable that links to lib1.
The dependencies are thus:

lib2 --> lib1 --> testing

Now: if I compile the program with g++ 4.5.2, the programs outputs:

Lib2
Ciao

whereas if I compile with g++ 4.6.1, the program outputs:

Ciao

For me this is a problem, as my program depends on the behavior of g++
4.5.2. I would like to ask you if:

1. this is a new feature - in which case, how do fix the problem?
2. this is a known bug - in which case I apologize for asking, but I
couldn't find it in the bug list.

Thanks a lot in advance for your help.

Cheers,
Carlo


-- 
View this message in context: 
http://old.nabble.com/Different-linking-behavior-between-g%2B%2B-4.5.2-and-4.6.1-tp32849125p32849125.html
Sent from the gcc - bugs mailing list archive at Nabble.com.



Re: Different linking behavior between g++ 4.5.2 and 4.6.1

2011-11-15 Thread Carlo Pinciroli
Thank you very much Andrew, your suggestion indeed solved the problem.
And thanks also for your fast answer! :-)

Cheers,
Carlo

On Tue, Nov 15, 2011 at 6:49 PM, Andrew Pinski  wrote:
> On Tue, Nov 15, 2011 at 9:34 AM, Carlo Pinciroli  wrote:
>>
>> Dear forum,
>>
>> I have a problem with linking of a program I have wrote. Instead of giving
>> you the entire program, which is pretty large, I have prepared a basic
>> example that you can find attached to this message. The example uses CMake
>> to compile.
>>
>> I have three files:
>
> Sounds like --as-needed is the default with the linker you are using.
> That is GCC is not the issue but rather the defaults with the distros
> you are using are different.
>
> Thanks,
> Andrew Pinski
>



-- 
Guarda l'apina che vola gaudente
A questo e quel ramo lei passa radente
Poi vede qualcosa, si posa su un fiore
Io prendo il giornale, la schiaccio e lei muore.

Invia il necrologio a ilpi...@gmail.com.

Look at the bee that happily flits
>From tree to tree no branches she hits
Then something she sees, to the flower she flies
I take the newspaper, swat her and she dies.

Send the necrology to ilpi...@gmail.com.