以下示例显示了使用 -filt 选项编译该代码的效果。
// filt_demo.cc
class type {
public:
virtual ~type(); // no definition provided
};
int main()
{
type t;
}
|
如果编译代码时不使用 -filt 选项,编译器就假定 -filt=errors,names,returns,stdlib 并显示标准输出。
example% CC filt_demo.cc Undefined first referenced symbol in file type::~type() filt_demo.o type::__vtbl filt_demo.o [Hint: try checking whether the first non-inlined, non-pure virtual function of class type is defined] ld: fatal: Symbol referencing errors. No output written to a.out |
以下命令禁止还原 C++ 损坏链接程序名称,并禁止链接程序错误的 C++ 解释。
example% CC -filt=no%names,no%errors filt_demo.cc Undefined first referenced symbol in file __1cEtype2T6M_v_ filt_demo.o __1cEtypeG__vtbl_ filt_demo.o ld: fatal: Symbol referencing errors. No output written to a.out |
现在考虑以下代码:
#include <string>
#include <list>
int main()
{
std::list<int> l;
std::string s(l); // error here
}
|
下面是指定了 -filt=no%stdlib 时的输出:
Error: Cannot use std::list<int, std::allocator<int>> to initialize std::basic_string<char, std::char_traits<char>, std::allocator<char>>. |
下面是指定了 -filt=stdlib 时的输出:
Error: Cannot use std::list<int> to initialize std::string . |