在vc中实现怎样静态库的调用??
tseny 2005-05-02 02:49:11 一直不太清楚, 终于又碰上了这问题了!
谢谢大侠了, 帮忙解释一下!!!
首先我已在IDE中设置好路径
如 在include files 中 设置了 D:\xxx\include
在library files中 设置了 D:\xxx\lib
然后我建立实现库的工程 win32-Static library
然后添加类:
///////////////////////////////////////////////////
// toy.h
#pragma once
class Toy
{
public:
Toy(void);
~Toy(void);
};
///////////////////////////////////////////////////
// toy.cpp
#include "toy.h"
#include <iostream>
Toy::Toy(void)
{
std::cout << "I'm a toy." << std::endl;
}
Toy::~Toy(void)
{
std::cout << "I'm leaving." << std::endl;
}
///////////////////////////////////////////////////
成功编译生成 toy.lib 文件
然后我将toy.h放入 D:\xxx\include 中
将toy.lib放入 D:\xxx\lib 中
最后编写测试test.cpp(控制台程序)
///////////////////////////////////////////////////
// test.cpp
#include <toy.h>
int main(void)
{
Toy theToy;
return 0;
}
///////////////////////////////////////////////////
编译都为release版本
发生链接错误
test.obj : error LNK2019: unresolved external symbol "public: __thiscall Toy::~Toy(void)" (??1Toy@@QAE@XZ) referenced in function _main
test.obj : error LNK2019: unresolved external symbol "public: __thiscall Toy::Toy(void)" (??0Toy@@QAE@XZ) referenced in function _main
????????????????????????????????????????????????????