免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1422 | 回复: 1
打印 上一主题 下一主题

[SCO UNIX] C++程序能不能调用C的静态库? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-20 00:58 |只看该作者 |倒序浏览
请教各位高手在SCO5.05环境下,C++的程序里能不能调用C的静态库?
我试了没用成功。以下是我的测试例子
/******tools.c************/
#include  <stdio.h>;
#include  <stdlib.h>;
#include  <time.h>;
#include  <sys/times.h>;
#include  <sys/select.h>;

void Get_sys_time(char * buftime)
{
              struct tm *t;
              long tim;

             tim=time((long *)0);  /*Get current system time*/
              t=localtime(&tim);
              sprintf(buftime,"%d-%02d-%02d,%02d:%02d:%02d",t->;tm_year+1900,t->;tm_mon+1,t->;tm_mday,t->;tm_hour,t->;tm_min,t->;tm_sec);
}


/**************test1.cpp************/
#include  <stdio.h>;
#include  <stdlib.h>;
#include <iostream.h>;
#include  <time.h>;
#include  <sys/times.h>;
#include  <sys/select.h>;

extern int Get_sys_time(char * buftime);

int main()
{
  char buftime[50]={0};
  Get_sys_time(buftime);
  cout<<"data="<<buftime<<endl;
}

编译:
cc -c tools.c
CC -dy -o test1 test1.cpp tools.o
系统提示:
Undefined                       first referenced
symbol                             in file
Get_sys_time(char*)                   /tmp/CC.573/test1.o
test1: fatal error: Symbol referencing errors. No output written to test1
我把tools.c 改成tools.cpp,再用CC编译一次就可以用了
这是测试时可以改源程序,但有时我们经常会用到别人提供的.o文件,没有.c是不是就没办法了呢?

论坛徽章:
0
2 [报告]
发表于 2005-06-20 10:36 |只看该作者

C++程序能不能调用C的静态库?

要把test1.cpp文件中的
extern int Get_sys_time(char * buftime);
这行改为
extern “C”
{
int Get_sys_time(char * buftime);
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP