zoukankan      html  css  js  c++  java
  • c/c++混编

    /* head.h */
    #ifndef __SUM_H__ #define __SUM_H__ #ifdef __cplusplus extern "C" { #endif int add(int a, int b); int sub(int a, int b); #ifdef __cplusplus } #endif #endif /* __SUM_H__ */

    sum.cpp

    #include <iostream>
    
    #include "head.h"
    
    using namespace std;
    
    int main()
    {
        int a, b;
        cout << "请输入两个数字:" ;
        
        cin >> a >> b;
    
        cout << "相加:" << add(a, b) << endl;
        cout << "相减:" << sub(a, b) << endl;
    }

    test.c

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

     编译测试:g++ sum.cpp test.c

    或者将c文件编译成.o文件:gcc -c test.c 生成test.o 然后: g++ sum.cpp test.o

  • 相关阅读:
    docker容器之启动容器
    docker镜像之registry
    docker镜像之镜像命名
    习题3
    习题二(1)
    课堂作业4
    课堂作业(电费)
    课堂作业2
    实验4
    实验3
  • 原文地址:https://www.cnblogs.com/porkerface/p/12088032.html
Copyright © 2011-2022 走看看