一个静态链接库调用静态链接库的问题

liao5189 2015-03-05 07:43:54
****第一个静态库:
static1.h
#ifndef STA123123_H
#define STA123123_H
extern "C"
int add(int a,int b);
#endif

static1.cpp
#include <stdio.h>
#include "static1.h"
int add(int a,int b)

{
return a+b;
}

第二个静态库:
static2.h
#ifndef STA55555555_H
#define STA55555555_H
extern "C"
int compute(int a,int b);
#endif

static2.cpp
#include <stdio.h>
#include "static2.h"
#include "static1.h"
int compute(int a,int b)

{
return add(a,b);
}

可执行文件
main.cpp
#include <stdio.h>
#include "static2.h"
int main(int argc, char **argv)

{
int a=3,b=5;

int c=compute(a,b);
return 0;
}
已经在工程属性里面添加好了各自需要的lib文件;
但是main函数运行时报错
static2.cpp:7: undefined reference to `add'
为什么?静态库调用静态库要注意什么问题吗?****
...全文
119 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
假正经的班长 2015-03-06
  • 打赏
  • 举报
回复
要么把static1填进static2的 Additional Dependencies里边 要么把static1填进可执行文件的 Additional Dependencies里边
qiaoba0701 2015-03-05
  • 打赏
  • 举报
回复
你这连个库是依赖关系,第二个依赖第一个,应该用第二个生成一个包含第一个静态库的静态库,然后应用。出错的原因是你将两个库单独使用,忽略了它们之间的依赖关系。
Peter_Wang 2015-03-05
  • 打赏
  • 举报
回复
没见你lib库里export你的函数啊

64,643

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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