我在编译一些非常简单的代码时遇到问题,我不知道它有什么问题:/
看一看:
class A{
public:
virtual void func() = 0;
};
class B : public A
{
public:
virtual void func() {};
};
int main()
{
A* obj = new B();
return 0;
}
这是我从 g++ 得到的信息:
Info: resolving vtable for _cxxabiv1::__si_class_type_info by
linking to __imp __ZTVN10__cxxabiv120__si_class_type_infoE (auto-import)
Info: resolving vtable for __cxxabiv1::__class_type_info by
linking to __imp___Z TVN10__cxxabiv117__class_type_infoE (auto-import)
k:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe:
warning: auto-importing has been activated without
--enable-auto-import specified on the c ommand line. This should work
unless it involves constant data structures referencing symbols from
auto-imported DLLs
编译没有任何问题,链接有问题(更准确地说,只是警告)。见:
d:\alqualos\pr\testpq>g++ -Wall -c main.cpp
main.cpp: In function 'int main()':
main.cpp:14:8: warning: unused variable 'obj'
d:\alqualos\pr\testpq>g++ -Wall main.o
Info: resolving vtable for __cxxabiv1::__si_class_type_info by linking to __imp_
__ZTVN10__cxxabiv120__si_class_type_infoE (auto-import)
Info: resolving vtable for __cxxabiv1::__class_type_info by linking to __imp___Z
TVN10__cxxabiv117__class_type_infoE (auto-import)
d:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.
这是 MinGW 的一个广泛使用的“特性”。如果您的程序需要标准 C++ 库中的任何内容,甚至只是 std::cout,就会发生这种情况。在这种情况下,它与 vtables 有关。要摆脱它:
d:\alqualos\pr\testpq>g++ -Wall -Wl,--enable-auto-import main.o
我不知道“应该工作,除非它涉及引用来自自动导入的 DLL 的符号的常量数据结构”是什么意思。我试过谷歌搜索但没有发现任何有用的东西。如果有人知道它的真正含义以及什么时候可能有危险,请在此处发布答案。