最近在弄一个进程间通信,原始测试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. 跨 Docker 宿主机 macvlan 类型

    跨 Docker 宿主机 macvlan 类型 前言 a. 本文主要为 Docker的视频教程 笔记. b. 环境为 三台 CentOS 7.0 虚拟机 (Vmware Workstation 15 ...

  2. CodeForce-734C Anton and Making Potions(贪心+二分)

    CodeForce-734C Anton and Making Potions  C. Anton and Making Potions time limit per test 4 seconds m ...

  3. gentoo(贱兔) Linux作业系统的基本使用

    emerge是gentoo linux的portage包管理器的命令行工具emerge的基础使用:emerge 软件包名:安装某软件包 emerge nanoemerge --ask 软件包名:交互式 ...

  4. 使用Visual Studio Code 开发 ESP8266

    使用Visual Studio Code 开发 ESP8266 ESP8266+ArduinoIDE+VSCode开发ESP8266. 首先说明一下ESP8266并不是某一WiFi模块的名字(我以前是 ...

  5. windows2012安装django

    第一步:下载python3.6.8或者到(https://www.python.org/downloads/release/python-368/)官网下载(Windows x86-64 execut ...

  6. re.findall用法

    其中,re.findall() 函数可以遍历匹配,可以获取字符串中所有匹配的字符串,返回一个列表. 在python源代码中,展示如下: 搜索string,返回一个顺序访问每一个匹配结果(Match对象 ...

  7. P5956-[POI2017]Podzielno【数学】

    正题 题目链接:https://www.luogu.com.cn/problem/P5956 题目大意 \(B\)进制下,给出序列\(a\),\(a_i\)表示数字\(i\)有多少个.求一个最大的\( ...

  8. asp.net core使用identity+jwt保护你的webapi(一)——identity基础配置

    前言 用户模块几乎是每个系统必备的基础功能,如果每次开发一个新项目时都要做个用户模块,确实非常无聊.好在asp.net core给我们提供了Identity,使用起来也是比较方便,如果对用户这块需求不 ...

  9. CSS常见的5种垂直水平居中(面试够用)

    方法一 (flex) <div id='box'> <div class='child'></div> </div> #box{ width:200px ...

  10. 利用水文分析方法提取山脊线和山谷线(ArcPy实现)

    一.背景 作为地形特征线的山脊线.山谷线对地形.地貌具有一定的控制作用.它们与山顶点.谷底点以及鞍部点等一起构成了地形起伏变化的骨架结构.同时由于山脊线具有分水性,山谷线具有合水性特征,使得它们在地形 ...