使用 rvct 编译时未调用全局静态成员的构造函数

发布于 2024-10-16 04:29:32 字数 757 浏览 4 评论 0原文

嗯,解释起来有点复杂。 我正在编译一个静态库,它的标头看起来与此类似:

class Foo{
    static int Goo(){
        DoSomethingExciting();
        return 0;       
    }
    static int fooMember;
}

在 Cpp 中,我对 fooMember 进行了初始化:

int Foo::fooMember = Foo::Goo();

当将静态库链接到我正在编写的应用程序时,Goo 方法应该是被叫没有被叫。确切地说,DoSomethingExciting() 方法根本没有被调用。我确实在应用程序中使用了 Foo 类。当我将行:

int Foo::fooMember = Foo::Goo();

放在应用程序的 cpp 中时(当然我从静态库中删除了同一行),我看到调用了 Goo() 。

我不知道如何命名我遇到的问题,我想这是全局静态成员初始化或类似问题的问题。

我正在使用 RVCT 进行编译。在 Visual Studio 中编译相同的场景时,一切都运行良好。我猜测 RVCT 的行为有所不同,我可能需要添加一些编译标志。

顺便说一句,我还尝试在已编译的可执行文件上使用反编译器,但没有看到任何对 Goo() 的调用,尽管我确实看到该方法位于文件中。

我希望我对我的问题足够清楚:)

提前致谢......

Well, this is kind of complex to explain.
I'm compiling a static library which has a header that looks something similar to this:

class Foo{
    static int Goo(){
        DoSomethingExciting();
        return 0;       
    }
    static int fooMember;
}

In the Cpp i have an initialization of the fooMember:

int Foo::fooMember = Foo::Goo();

When linking the static library to an application i'm writing, the Goo method which is supposed to be called isn't being called. To be exact, the DoSomethingExciting() method isn't called at all. I do use the Foo class in the application. When i put the line:

int Foo::fooMember = Foo::Goo();

in a cpp in my application (of course i remove the same line from the static library), I see that the Goo() is called.

I'm not sure how to name the problem i'm experiencing, I guess it is a problem with global static member initialization or something like that.

I'm using RVCT to compile. When compiling the same scenario in Visual Studio, everything works great. I'm guessing that RVCT behaves differently and I might need to add some compilation flags.

Btw, I've also tried using a decompiler on my compiled executable and I didn't see any calls to Goo(), although i did see that the method is in the file.

I hope i was clear enough with my problem :)

Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

享受孤独 2024-10-23 04:29:32

如果它是静态对象的构造函数,就会调用它,但既然它只是一个静态方法,为什么会自动生成对它的调用呢?

It would be called if it was a constructor of a static object, but since it is only a static method, why would a call to it be generated automatically?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文