C ++:g ++编译器:stdio与虚函数的冲突? [英] C++: g++ compiler: clash of stdio with virtual functions?

查看:189
本文介绍了C ++:g ++编译器:stdio与虚函数的冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用stdio结合虚拟函数(Windows Vista,Cygwin,GCC 4.8.2)

I am not able to use stdio combined with virtual functions (Windows Vista, Cygwin, GCC 4.8.2)

#include <stdio.h>

class A
{
    public:

    //  If I make g() as virtual, stdio doesn't print.
    virtual void g() {}
};

int main()
{
    A a; // Or I could remove this object to make stdio print.
    printf("testing\n");
}

通过Borgleader的提示我发现, -O2选项。在使用/不使用-O2时,链接似乎不同。

With hint by "Borgleader", I found that it works when used with "-O2" option. Linking seems to be different when used with/without "-O2".

/home/user> g++ test.cc
/home/user> ./a.exe
/home/user> ldd ./a.exe
    ntdll.dll => /cygdrive/c/Windows/system32/ntdll.dll (0x77540000)
    kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x75790000)
    cygwin1.dll => /usr/bin/cygwin1.dll (0x61000000)
    cyggcc_s-1.dll => /usr/bin/cyggcc_s-1.dll (0x6bf40000)
    cygstdc++-6.dll => /usr/bin/cygstdc++-6.dll (0x6c480000)

/home/user> g++ -O2 test.cc
/home/user> ./a.exe
testing
/home/user> ldd ./a.exe
    ntdll.dll => /cygdrive/c/Windows/system32/ntdll.dll (0x77540000)
    kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x75790000)
    cygwin1.dll => /usr/bin/cygwin1.dll (0x61000000)

感谢selbie的建议尝试GDB。现在事情有点更清楚。我应该忘记printf,程序甚至不加载!使用选项-O2,它工作正常(即使在GDB中)。

Thanks for selbie's suggestion to try GDB. Now things are a bit more clear. I should forget about printf, the program doesn't even load! With option "-O2", it works ok (even in GDB).

/home/user> g++ -g test.cc
/home/user> gdb ./a.exe
<<Edited for brevity>>
(gdb) break main
Breakpoint 1 at 0x40119e: file test.cc, line 14.
(gdb) run
Starting program: /home/user/a.exe
[New Thread 4888.0x13e0]
gdb: unknown target exception 0xc0000139 at 0x77549cfc
During startup program exited with code 0xc0000139.

程序没有加载的另一个提示是,即使我把sleep ,它立即存在。

Another hint that the program was not loading is that, even if I put sleep(100) in it, it exists immediately.

摘要:更新整个cygwin安装后问题解决

Summary: The problem got solved after updating the entire cygwin installation

详细:重新安装g ++编译器没有帮助。更新只是g ++编译器到新版本没有帮助。更新整个开发类别没有帮助。更新基本类别没有帮助。更新整个cygwin安装帮助。它仍然未知为什么以前的安装仍然使用-O2选项。我可以继续使用-O2选项。但是,我选择完成cygwin的更新。

Details: Reinstall of just g++ compiler did not help. Updating just g++ compiler to new version did not help. Updating the entire Development category did not help. Updating Base category did not help. Updating the entire cygwin installation helped. It remains unknown as per why the previous install was still working with "-O2" option. I could have continued to use "-O2" option. But, I chose to do complete update of cygwin.

推荐答案

我做的是更新和重新安装(擦除和下载)很多次Cygwin,但最后结果证明,我不得不将我的g ++编译器从5.2降级到4.9。我想这与某个特定版本的Cygwin C ++运行时有关。

What I did was to update and reinstall (erase & download) many times Cygwin, but at the end it turned out that I had to downgrade my g++ compiler from 5.2 to 4.9. I suppose that this has something to do with a specific version of Cygwin C++ runtime.

这篇关于C ++:g ++编译器:stdio与虚函数的冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆