[Linker Error] C++Build的问题求高手指点

CAINIAOXIANGFEI 2011-06-20 12:41:15
我建了一个cosle工程
里面有ab.h,ab.c,lll.cpp
3个程序
ab.h代码如下:
typedef struct Stash
{
int size;//size of each space
int quantity;//Number of storage space
int next;//next empty space
unsigned char* storage;//
}Stash;

void initialize(Stash* s,int Size);
void cleanup(Stash* s);
int add(Stash* s,void* element);
void* fetch(Stash* s,int index);
int count(Stash* s);
void inflate(Stash* s,int increase);
ab.c是它的实现,是没问题的
lll.cpp是程序main函数的地方
内容如下:
#include <vcl.h>
#include"ab.h"
#include<stdio.h>
#include<assert.h>
#define BUFSIZE 80
#pragma hdrstop

#pragma argsused
void main(int argc, char* argv[])
{

Stash intStash,stringStash;
int i;
FILE* file;
char buf[BUFSIZE];
char* cp;
initialize(&intStash,sizeof(int));//出错的地方,不要这句就是对的
}
编译运行时报错
[Linker Error] Unresolved external 'initialize(Stash *, int)' referenced from D:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\LLL.OBJ
求高手指点啊!!!

...全文
134 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
开始领悟 2011-06-20
  • 打赏
  • 举报
回复
提示找不到函数
tst1255 2011-06-20
  • 打赏
  • 举报
回复
linker 没有找到函数initialize(Stash *, int)的二进制目标代码。

解决办法:
把包含函数initialize(Stash *, int)的源码文件加入工程,或在工程的其它cpp里包含该源代码。
lz既然用C++,就不要用.c文件了,把含'initialize(Stash *, int)的文件名改成.cpp按c++语法编译。
lifesider 2011-06-20
  • 打赏
  • 举报
回复
void initialize(Stash* s,int Size);
这个函数没有实现?
缘中人 2011-06-20
  • 打赏
  • 举报
回复
lll.cpp文件添加一句话
#include"ab.c"
Acmed 2011-06-20
  • 打赏
  • 举报
回复
不知道是不是结构的取地址&intStash这又问题啊。
你可以把Stash intStash直接定义成Stash *intStash.然后调用呢。
另外你的结构成员用到了指针,如果你的initialize只是给结构成员赋值的话,最好还写一下拷贝构造函数,否则再用容器或者赋值时会出现内存问题。
Acmed 2011-06-20
  • 打赏
  • 举报
回复
不知道是不是结构的取地址&intStash这又问题啊。
你可以把Stash intStash直接定义成Stash *intStash.然后调用呢。
另外你的结构成员用到了指针,如果你的initialize只是给结构成员赋值的话,最好还写一下拷贝构造函数,否则再用容器或者赋值时会出现内存问题。

13,826

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧