This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Possible bug with __attribute__((constructor)) and static libraries


$ make
g++ module.cpp -c -O2
ar cq libmodule.a module.o
g++ test.cpp module.o -o from-object
g++ test.cpp -Wl,--whole-archive libmodule.a -Wl,--no-whole-archive \
    -o from-lib

$ ./from-object
Yay life is good.

$ ./from-lib
Yay life is good.
#include "module.hpp"
#include <iostream>

using namespace std;

void foo()
{
  cout << "Yay life is good." << endl;
}
#include "module.hpp"
int main()
{
  return 0;
}
void foo() __attribute__((constructor));
default:
	g++ module.cpp -c -O2
	ar cq libmodule.a module.o
	g++ test.cpp module.o -o from-object
	g++ test.cpp -Wl,--whole-archive libmodule.a -Wl,--no-whole-archive -o from-lib

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]