zoukankan      html  css  js  c++  java
  • C++

    我们拿在Qt项目中加入纯C语言写的代码文件来举例

    问题

    在Qt项目中如果加入纯C语言写的代码文件后,Qt工程就会无法编译。

    解决方法

    在纯C语言写的代码文件的头文件中加入以下内容即可

    #pragma once
    //C++ 运行该文件时,extern C包含的内容用C语言方式连接
    #ifdef __cplusplus
       extern "C"{
    #endif 
     
    //C代码内容所在位置
     
    #ifdef __cplusplus
    }
    #endif 

    实例

    纯C语言写的代码文件为:test.h,test.c

    其中test.c文件内容为:

    #include "test.h"
    #include <stdio.h>
    
    int add(int a,int b)
    {
        return a+b;
    }

    则test.h文件内容应为:

    #ifndef TEST_H
    #define TEST_H
    
    //C++ 运行该文件时,extern C包含的内容用C语言方式连接
    #ifdef __cplusplus
       extern "C"{
    #endif 
     
    #include <stdio.h>
    int add();
     
    #ifdef __cplusplus
    }
    #endif

    #endif
    博客园文作者:Citrusliu 博文地址:https://www.cnblogs.com/citrus
  • 相关阅读:
    Neo4j简介
    HiBench算法简介
    Spark性能测试工具
    常用Benchmark
    Mapreduce的性能调优
    YARN node labels
    Yarn on Docker集群方案
    YARN on Docker
    HDP YARN MapReduce参数调优建议
    JVM优化:生产环境参数实例及分析
  • 原文地址:https://www.cnblogs.com/citrus/p/13322365.html
Copyright © 2011-2022 走看看