免费注册 查看新帖 |

Chinaunix

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

[C++] c++程序可以直接调用c函数吗? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-05-08 18:07 |只看该作者 |倒序浏览
我对c和c++都不是很熟。现在要通过c++使用LDAP的api函数。但是不知道为什么,c文件可以调用ldap的函数,而c++程序则不能调用。希望各位路过的大侠能够帮帮忙,告诉我到底怎么办?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2006-05-08 18:23 |只看该作者
#ifdef __cplusplus
extern "C" {
#endif
/*...*/
#ifdef __cplusplus
}
#endif
#endif
在注释处加上ldap的头文件。

论坛徽章:
0
3 [报告]
发表于 2006-05-08 18:48 |只看该作者
非常感谢您的帮助。我照下面的做,可是仍然有错。不知我哪里是否有误?

#ifdef __cplusplus
extern "C" {
#endif
#include <ldap.h>
#ifdef __cplusplus
}
#endif

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
int main(int argc, char* argv[])
{
   .....
   ldap_init(ldap_host,LDAP_PORT);
   ....
}

编译: g++ -c test.cpp -o test

出错:test.cpp: In function `int main(int, char**)':
test.cpp:68: `ldap_init' undeclared (first use this function)
test.cpp:68: (Each undeclared identifier is reported only once for each
   function it appears in.)

论坛徽章:
0
4 [报告]
发表于 2006-05-09 13:16 |只看该作者

回复 3楼 wenziyan 的帖子

man ldap_init

find where your ldap library installed

论坛徽章:
0
5 [报告]
发表于 2006-05-09 20:53 |只看该作者
事实证明位置没有问题.我最后以一个笨方法解决了,就是把调用ldap_init的操作放在一个c程序中,然后c++程序通过调用这个c程序来达到我的目的。谢谢大家的帮助。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP