C与C++ 混合编译
来源:互联网 发布:成都软件测试工资 编辑:程序博客网 时间:2024/06/06 09:14
通常情况下,在用g++对源文件编译时,无论.c 还是.cpp 都是按照c++编译的,所以不会存在混合编译的问题
但是若用c++调用c编译器编译出来的库,就涉及到混合编译了
请看列子:
1.c
#include <stdio.h>#include "1.h"void out(int a,int b){printf("%d\n",a+b);}
gcc -c 1.c 生成1.o
接下来在c++中调用
main.cpp
#include <iostream>#include "1.h"/*class point{public:void printout(){out(1,3);}};*/int main(){/*point st;st.printout();*/out(1,3);}这个时候需要1.h头文件
#ifdef __cplusplusextern "C"{#endifvoid out(int a,int b); #ifdef __cplusplus}#endifg++ main.cpp 1.o 编译成功
若去掉extern “C”
则提示:
root@ymzhi-desktop:/opt/vc# g++ main.cpp 1.o
/tmp/ccuNjqIj.o: In function `point::printout()':
main.cpp:(.text._ZN5point8printoutEv[point::printout()]+0x16): undefined reference to `out(int, int)'
collect2: ld returned 1 exit status
0 0
- C与C++ 混合编译
- matlab与C/C++混合编译
- 解决C++与object-c混合编译
- 关于swift与objective-c混合编译
- c/cpp混合编译
- CMake混合编译C/C++与object-C
- python与C混合
- C和C++混合编译
- C和C++混合编译
- C和C++混合编译
- C和C++混合编译
- C和C++混合编译
- C和C++混合编译
- c和C++混合编译
- linux下C与C++混合编译、C++调用C、C++使用C中的函数
- C与shell混合编程
- C与C#混合编程
- C与C++混合编程
- C语言 指针
- 操作系统---进程/线程 间通信
- android中的AIDL进程间通信
- python的异步IO模块asyncio学习
- 操作系统---进程/线程 间通信
- C与C++ 混合编译
- 安卓自定义控件卡券CouponView
- 认识繁体字
- c++ opencv读取图片像素值并进行加密
- Java中 intValue,parseInt,Valueof 这三个关键字的区别
- CentOS7搭建SVN服务器
- Android网络之HttpUrlConnection和Socket关系解析
- c++开坑
- 371. Sum of Two Integers