VC++6.0静态库的调用

oken2 2014-01-25 09:34:18
我是个初学者,这是个书上的例子,为什么我在编写的时候,不能出现书上的结果呢?有报警
有两个工程放到了一个工作区上(libtest和libcall)
libtest工程:

.h
#ifdef LIB_H
#define LIB_H
extern "C" int add(int x,int y);//声明为C编译、连接方式的外部函数
#endif

.cpp
#include "lib.h"
int add(int x,int y)
{
return x+y;
}

libcall工程:
main.cpp
#include <stdio.h>
#include "..\lib.h"
#pragma comment( lib, "..\\debug\\libTest.lib" ) //指定与静态库一起连接
int main(int argc, char* argv[])
{
printf( "2 + 3 = %d", add( 2, 3 ) );
}

编译以后出现一个报警还有一个警告
D:\libTest\libCall\main.cpp(6) : error C2065: 'add' : undeclared identifier
D:\libTest\libCall\main.cpp(7) : warning C4508: 'main' : function should return a value; 'void' return type assumed

请大侠们解释一下,谢了,小弟不胜感激。
...全文
118 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
michael2988 2014-01-25
  • 打赏
  • 举报
回复
main 后面 return 0; 吧
michael2988 2014-01-25
  • 打赏
  • 举报
回复
最好是像下面这样子写: lib.h #ifdef DLL_API #else #define DLL_API extern "C" _declspec(dllimport) #endif DLL_API int add(int x,int y); lib.cpp #define DLL_API extern "C" _declspec(dllexport) #include "lib.h" int add(int x,int y) { return x+y; }
michael2988 2014-01-25
  • 打赏
  • 举报
回复
要声明为导出函数 extern "C" _declspec(dllexport) int add(int x,int y);

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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