linux编译动态库未定义,自定义动态库 对‘*’未定义的引用解决方法

自定义动态库 对‘*’未定义的引用

本帖最后由 longruliang 于 2015-05-25 16:02:26 编辑

自己编写了一个串口方面的动态库,想写一个测试程序,在编译的时候冒出对‘*’未定义的引用,怎么解决,我用的CodeBlock

卡在这一步好多天了,先谢谢各位兄弟了。

//Main

#include        //标准输入输出定义

#include       //标准函数库定义

#include "3000StandardCommand.h"

#define FALSE -1

#define TRUE 0

int main(int argc, char **argv)

{

int fd =FALSE;

fd=  PortOpen("/dev/ttyS0",9600,0,8,1,'N');

if(FALSE == fd){

printf("open error\n");

exit(1);

}

else

{

printf("open OK\n");

}

PortClose();

return 0;

}

//3000StandardCommand.h

#ifdef _cplusplus

extern"C"

{

#endif

/*******************************************************************

* 名称: PortOpen

* 功能: 设置串口号,数据位,停止位和效验位

* 入口参数:

× port 串口号

* speed 串口速度

* flow_ctrl 数据流控制

* databits 数据位 取值为 7 或者8

* stopbits 停止位 取值为 1 或者2

* parity 效验类型 取值为N,E,O,,S

*出口参数: 正确返回为1,错误返回为0

*******************************************************************/

int PortOpen(char* port ,int speed,int flow_ctrl,int databits,int stopbits,int parity);

/*******************************************************************

* 名称: PortClose

* 功能: 关闭串口

*******************************************************************/

void PortClose();

#ifdef _cplusplus

extern"C"

}

#endif

;

-------------- 生成: Debug in 3000ComLinuxTest (compiler: GNU GCC Compiler)---------------

g++  -o bin/Debug/3000ComLinuxTest obj/Debug/main.o

obj/Debug/main.o:在函数‘main’中:

/home/longruliang/桌面/Project/3000Linux/3000ComLinuxTest/main.c:14:对‘PortOpen’未定义的引用

/home/longruliang/桌面/Project/3000Linux/3000ComLinuxTest/main.c:24:对‘PortClose’未定义的引用

collect2: error: ld returned 1 exit status

Process terminated with status 1 (0 minute(s), 0 second(s))

0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

154956108.png

------解决思路----------------------

extern"C" 去掉

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值