lib文件中的c++全局类构造函数
c++ global class constructor in lib file
我有以下项目生成foo.lib.
//foo.h:
class A
{
public:
A();
static A* i;
};
//foo.cpp:
A* i = 0;
A g_A_instance;
A::A()
{
//this constructor is not called :(
i = this;
}
我有另一个生成与foo.lib链接的exe文件的项目。似乎没有调用构造函数A::A()。我该怎么做呢?我缺少一些编译器选项吗?
PS:我使用了visualstudio编译器2008
谢谢,Raxvan。
如果我更改
A* i = 0;
至
A* A::i = 0;
所以它会链接,构造函数是在VS2005中为我正确调用的,默认选项。这个确切的例子在你的编译器上重现了这个问题吗?
相关文章:
- 修改程序的入口点时未调用全局变量的构造函数
- 如何在全局变量的构造函数之前运行函数
- 何时调用全局对象的构造函数?
- C++:链接库两次,全局构造函数运行两次吗?
- std::atexit 从全局对象的构造函数调用时的排序
- 如何强制调用类的全局实例的析构函数和构造函数(以便"re-init"类实例)
- 从全局对象构造函数停止监视器计时器
- 共享库中 __attribute__((构造函数)) 的全局/静态变量初始化问题
- 未显式引用对象的全局对象构造函数在最终二进制文件 - LD 中被丢弃
- 为什么 Clang++ 不在另一个静态库中运行全局对象构造函数?
- C++-全局静态对象和本地静态对象的构造函数调用不同
- 为什么GCC将对全局实例构造函数的调用放在不同的部分(取决于目标)
- 为什么全局对象构造函数只打印 Arduino 中的前 2 个字符
- 您如何确定全局构造函数的优先级
- 全局变量构造函数/析构函数是否需要线程保护
- 具有私有构造函数的类的全局对象
- arm-none-eabi- c++调用全局构造函数
- 全局构造函数调用的顺序是什么?
- clang中如何处理全局构造函数警告
- 全局构造函数调用不在.int_array节中