最近在弄一个进程间通信,原始测试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. 自己实现Controller——标准型

    标准Controller 上一篇通过一个简单的例子,编写了一个controller-manager,以及一个极简单的controller.从而对controller的开发有个最基本的认识,但是细心观察 ...

  2. iNeuLink硬件网关与iNeuOS工业互联网操作系统互联互通应用案例

    目       录 1.      应用概述... 2 2.      模拟硬件设备配置... 2 3.      iNeuLink硬件网关配置... 4 3.1           硬件介绍... ...

  3. PHP方法的返回值

    不仅是PHP,大部分编程语言的函数或者叫方法,都可以用return来定义方法的返回值.从函数这个叫法来看,本身它就是一个计算操作,因此,计算总会有个结果,如果你在方法体中处理了结果,比如进行了持久化保 ...

  4. Shell系列(24)- 条件判断之文件类型

    按照文件类型进行判断 标红,记住:其他了解即可 测试选项 作用 -b 文件 判断该文件是否存在,并且是否为块设备文件(是块设备文件为真) -c 文件 判断该文件是否存在,并且是否为字符设备文件(是字符 ...

  5. Spring Cloud Hystrix 学习(三)请求合并

    什么是请求合并?我们先来看两张图: 上方的两张图中,第二张可以看出服务端只执行了一次响应,这就是请求合并.客户端新增的请求合并模块,内部存在一个等待的时间窗口,将一定时间段内满足条件的请求进行合并,以 ...

  6. Python+requests环境搭建和GET基本用法

    Python+requests环境搭建 首先你得安装Python,然后安装requests模块(第3方模块,安装方法:pip install requests)  基本用法 get 请求(不带参数的) ...

  7. SpringBoot 添加本地 jar 文件

    前言 有时候我们在项目中,会用到一些本地 jar 包文件,比如隔壁公司自己打包的: 此时无法从maven远程仓库拉取: 那么我们可以考虑把 jar 文件安装到本地 maven 库中,然后再添加依赖. ...

  8. Sentry 监控 - 全栈开发人员的分布式跟踪 101 系列教程(第一部分)

    系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...

  9. Kotlin基础入门之必知必会,查漏补缺来一手~~~

    数据类型 Kotlin跟 java 相同,基本数据类型有八种 boolean,char,int,short,long,float,double,byte 类型 位宽 最小值 最大值 Short 16 ...

  10. 势流理论笔记:03 Hess-Smith积分方法

    书接上回势流理论笔记:02 直接法与间接法 Hess-Smith方法 采用面向对象编程的思路,\(Matlab\)程序脚本,实现以下功能: 输入面元(四边形面元顶点坐标) 输出系数矩阵\([H][M] ...