最近在弄一个进程间通信,原始测试demon用c语言写的,经过测试ok,然后把接口封装起来了一个send,一个recv。

使用的时候send端是在一个c语言写的http服务端使用,编译ok没有报错,但是recv的使用在QT里面是C++的,编译的时候出现

undefined reference to `recvIpcMsg(int, ipc_msg*)'

报错。

检查了头文件和实现文件都在,编译成动态库了都,同样的方法在C文件里调用都没有报错,搬到C++里面就都报错了,突然想起来一件事我的头文件声明没有对C++编译器专门处理。

如下:

/*
*ipcmsg.h */
#ifndef H_MSGIPC_H
#define H_MSGIPC_H

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

#define MSGKEY 8888
#define BUF_SIZE 64 typedef enum ipc_msg_type
{
APP_MSG,
INPUT_MSG,
GPS_MSG
}ipc_type; typedef struct msgIpc
{
ipc_type type;
char buf[BUF_SIZE];
}ipc_msg_t;
//send ipc msg
extern int sendIpcMsg(key_t msgkey, const ipc_msg_t *msg);
//recv ipc msg
extern int recvIpcMsg(key_t msgkey, ipc_msg_t *msg);
#endif

如果C的方法要在C++编译器里链接使用应该加上如下宏包含

#ifdef __cplusplus
extern "C" {
#endif #ifdef __cplusplus
}
#endif

如此才能正常编译链接。

最后修改如下就可以编过了

/*
*ipcmsg.h
*/
#ifndef H_MSGIPC_H
#define H_MSGIPC_H

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

 

typedef enum ipc_msg_type
{
APP_MSG,
INPUT_MSG,
GPS_MSG
}ipc_type; typedef struct msgIpc
{
ipc_type type;
char buf[BUF_SIZE];
}ipc_msg_t;
//send ipc msg
extern int sendIpcMsg(key_t msgkey, const ipc_msg_t *msg);
//recv ipc msg
extern int recvIpcMsg(key_t msgkey, ipc_msg_t *msg);
 
#ifdef __cplusplus
}
#endif

#endif

undefined reference to `recvIpcMsg(int, ipc_msg*)'——#ifdef __cplusplus extern "C" { #endif的更多相关文章

  1. #ifdef __cplusplus extern "C" { #endif

    1.在好多程序中我们会遇到下面代码段 #ifdef __cplusplus        extern "C" {        #endif //c语法代码段 #ifdef __ ...

  2. #ifdef __cplusplus extern c #endif 的作用

    #ifdef __cplusplus // C++编译环境中才会定义__cplusplus (plus就是"+"的意思) extern "C" { // 告诉编 ...

  3. “#ifdef __cplusplus extern "C" { #endif”的定义

    平时我们在linux c平台开发的时候,引用了一些Cpp或者C的代码库,发现一些头文件有如下代码条件编译. #ifdef __cplusplus extern "C" { #end ...

  4. “#ifdef __cplusplus extern "C" { #endif”的定义-----C和C++的互相调用

    "#ifdef __cplusplus extern "C" { #endif"的定义 看一些程序的时候老是有 "#ifdef __cplusplus ...

  5. #ifdef __cplusplus extern "C" { #endif”的定义

      平时我们在linux c平台开发的时候,引用了一些Cpp或者C的代码库,发现一些头文件有如下代码条件编译. #ifdef __cplusplus extern "C" { #e ...

  6. #ifdef __cplusplus extern "C" { #endif”的定义的含义

    看一些程序的时候老是有“#ifdef __cplusplusextern "C" {#endif”的定义,搞搞清楚是怎么回事: Microsoft-Specific Predefi ...

  7. C++ 为什么要使用#ifdef __cplusplus extern "C" { #endif

    转载:http://www.cnblogs.com/ayanmw/archive/2012/03/15/2398593.html 转载:http://blog.csdn.net/zkl99999/ar ...

  8. 备忘录:“#ifdef __cplusplus extern "C" { #endif”的定义

    看一些程序的时候老是有“#ifdef __cplusplusextern "C" {#endif”的定义,搞搞清楚是怎么回事: Microsoft-Specific Predefi ...

  9. #ifdef __cplusplus extern "C" { #endif 的解释

    好多程序中都会遇到下列代码段: #ifdef __cplusplus extern "C" { #endif /****************** C语法代码段 ******** ...

随机推荐

  1. (转载)深入理解MDL元数据锁

    作者:MySQL技术本文为作者原创,转载请注明出处:https://www.cnblogs.com/kunjian/p/11993708.html 前言: 当你在MySQL中执行一条SQL时,语句并没 ...

  2. 传说中 VUE 的“语法糖”到底是啥?

    一.什么是语法糖? 语法糖也译为糖衣语法,是由英国计算机科学家彼得·约翰·兰达(Peter J. Landin)发明的一个术语.指的是计算机语言中添加的一种语法,在不影响功能的情况下,添加某种简单的语 ...

  3. disruptor笔记之三:环形队列的基础操作(不用Disruptor类)

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  4. javascript 求最大前5个数; 对象 深拷贝 deep copy

    * 用数组 function getTopN(a, n) { function _cloneArray(aa) { var n = aa.length, a = new Array(n); for ( ...

  5. 『GoLang』错误处理

    Go 没有像 Java 和 .NET 那样的 try/catch 异常机制:不能执行抛异常操作.但是有一套 defer-panic-and-recover 机制. Go 的设计者觉得 try/catc ...

  6. YbtOJ#493-最大分数【斜率优化dp,分治】

    正题 题目链接:http://www.ybtoj.com.cn/contest/117/problem/1 题目大意 \(n\)个数的一个序列,给其中的一些数打上标记. 一个标记方案的贡献为\(s_1 ...

  7. 单页应用后退不刷新方案(vue & react)

    引言 前进刷新,后退不刷新,是一个类似app页面的特点,要在单页web应用中做后退不刷新,却并非一件易事. 为什么麻烦 spa的渲染原理(以vue为例):url的更改触发onHashChange/pu ...

  8. 基于Hexo+Github Pages搭建的博客

    概念 Github Pages可以被认为是用户编写的.托管在github上的静态网页.使用Github Pages可以为你提供一个免费的服务器,免去了自己搭建服务器和写数据库的麻烦.此外还可以绑定自己 ...

  9. 演员 Or 开发者的自我修养

    演员 Or 开发者的自我修养 时至今日,我都还是很怀念小时候与一群玩伴编写剧本.拍摄,那时候的我还有一个远大的"白日梦"--成为一名导演.很可惜,终究是"白日梦" ...

  10. 洛谷2494 [SDOI2011]保密 (分数规划+最小割)

    自闭一早上 分数规划竟然还能被卡精度 首先假设我们已经知道了到每个出入口的时间(代价) 那我们应该怎么算最小的和呢? 一个比较巧妙的想法是,由于题目规定的是二分图. 我们不妨通过最小割的形式. 表示这 ...