自定义动态库 对‘*’未定义的引用
本帖最后由 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))
------解决思路----------------------
extern"C" 去掉