调用其他CPP中创建的类,编译时出现error LNK2001异常
调用其他CPP中创建的类,编译时出现error LNK2001错误
在test.h文件中创建一个类定义。
class test{
public:
void start(){
QueryPerformanceCounter(&_begin)
;}
void end(){
QueryPerformanceCounter(&_end);
costTime += (long)((_end.QuadPart - _begin.QuadPart) * 1000000 / _freq);
}
}
在a文件中#include“test.h”;并声明 test 1,并调用类1.start();
在b文件中#include“test.h”;extern test 1;并调用类1.end();
结果编译的时候出现a.obj error LNK2001:无法解析的外部符号 class test 1;
2>TLibCommon.lib(TComInterpolationFilter.obj) : error LNK2001: 无法解析的外部符号 "class MyTimer mytimer4" (?mytimer4@@3VMyTimer@@A)
这是为什么?
其实就是想统计一下从a文件开始到调用b文件中一个函数所耗费的时间。
因为中间跨越了很多cpp,不知道咋样能够实现这个功能。
------解决思路----------------------
这不就结了?main可以引用lib,lib引用不了main。所以main里面的变量可以是外部的,lib就不行
在test.h文件中创建一个类定义。
class test{
public:
void start(){
QueryPerformanceCounter(&_begin)
;}
void end(){
QueryPerformanceCounter(&_end);
costTime += (long)((_end.QuadPart - _begin.QuadPart) * 1000000 / _freq);
}
}
在a文件中#include“test.h”;并声明 test 1,并调用类1.start();
在b文件中#include“test.h”;extern test 1;并调用类1.end();
结果编译的时候出现a.obj error LNK2001:无法解析的外部符号 class test 1;
2>TLibCommon.lib(TComInterpolationFilter.obj) : error LNK2001: 无法解析的外部符号 "class MyTimer mytimer4" (?mytimer4@@3VMyTimer@@A)
这是为什么?
其实就是想统计一下从a文件开始到调用b文件中一个函数所耗费的时间。
因为中间跨越了很多cpp,不知道咋样能够实现这个功能。
------解决思路----------------------
这不就结了?main可以引用lib,lib引用不了main。所以main里面的变量可以是外部的,lib就不行