高手,帮帮忙,关于连接的问题??????
第三者编写的一个文件和头文件,
我要用里面的函数到自己的文件中,编译通过了,可是连接时出问题了,该怎么解决???
下面是测试程序
//: C04:CLibTest.cpp
//{L} CLib
// Test the C-like library
#include "CLib.h "
#include <fstream>
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
int main()
{
// Define variables at the beginning
// of the block, as in C:
CStash intStash, stringStash;
int i;
char* cp;
ifstream in;
string line;
const int bufsize = 80;
// Now remember to initialize the variables:
initialize(&intStash, sizeof(int));
for(i = 0; i < 100; i++)
add(&intStash, &i);
for(i = 0; i < count(&intStash); i++)
cout < < "fetch(&intStash, " < < i < < ") = "
< < *(int*)fetch(&intStash, i)
< < endl;
// Holds 80-character strings:
initialize(&stringStash, sizeof(char)*bufsize);
in.open( "CLibTest.cpp ");
assert(in);
while(getline(in, line))
add(&stringStash, line.c_str());
i = 0;
while((cp = (char*)fetch(&stringStash,i++))!=0)
cout < < "fetch(&stringStash, " < < i < < ") = "
< < cp < < endl;
cleanup(&intStash);
cleanup(&stringStash);
return 0;
} ///:~
还有头文件
//:c04:Clib.h
//Headerf file for a c-like library
typedef struct CStashTag
{
int size;
int quantity;
int next;
//Dynamically allocated array of bytes;
unsigned char* storage;
} CStash;
void initialize(CStash* s, int size);
void cleanup(CStash* s);
int add(CStash*s, const void* element);
void* fetch(CStash* s,int index);
void inflate(CStash* s,int increase);
int count(CStash* s);
///:~
还有他的实现部分
//: C04:CLibTest.cpp
//{L} CLib
// Test the C-like library
#include "CLib.h "
#include <fstream>
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
int main()
{
// Define variables at the beginning
// of the block, as in C:
CStash intStash, stringStash;
int i;
char* cp;
ifstream in;
string line;
const int bufsize = 80;
// Now remember to initialize the variables:
initialize(&intStash, sizeof(int));
for(i = 0; i < 100; i++)
add(&intStash, &i);
for(i = 0; i < count(&intStash); i++)
cout < < "fetch(&intStash, " < < i < < ") = "
< < *(int*)fetch(&intStash, i)
< < endl;
// Holds 80-character strings:
initialize(&stringStash, sizeof(char)*bufsize);
in.open( "CLibTest.cpp ");
assert(in);
while(getline(in, line))
add(&stringStash, line.c_str());
i = 0;
while((cp = (char*)fetch(&stringStash,i++))!=0)
cout < < "fetch(&stringStash, " < < i < < ") = "
< < cp < < endl;
cleanup(&intStash);
cleanup(&stringStash);
return 0;
} ///:~
[解决办法]
把你的“xx.lib”拷到当前工程目录或者vc lib 目录下 然后
#pragma comment(lib, "xx.lib ")
[解决办法]
首先,你用的这个是什么类型的库呢
如果是静态或动态连接库,那你除了需要它的.h 还需要 lib 或(lib 和 dll)
如果你用的是一写别人写的完全开放代码的小类库只类的,.h 和.cpp 都有的那种
那你就把它们加到你工程里编译就可以,但你还要知道它的工程属性啊等等是否对了
还有,你一开始贴的代码不对啊,定义那块你又把前面的贴重复了