gcc与g++编译链接库文件兼容性
来源:互联网 发布:台湾艺人知乎 编辑:程序博客网 时间:2024/06/10 16:43
使用静态库的时候,gcc编译出来的静态链接库g++编译代码的时候有时候链接不了,而g++编译的静态链接库gcc在编译的时候有时候也使用不了。
下面举例说明:
编写库文件:
hello.h
#ifndef HELLO_H_#define HELLO_H_#include <stdio.h>void HelloFunc();#endif /*HELLO_H_*/
hello.c
#include "hello.h"void HelloFunc(){ printf("Hello World!\n");}hello.cc
#include "hello.h"void HelloFunc(){ printf("Hello World!\n");}
测试代码:
main.c
#include <stdio.h>int main() { printf("Hello World!\n"); return 0;}
main.cc
#include <stdio.h>int main() { printf("Hello World!\n"); return 0;}
test.c
#include "hello.h"int main(){ HelloFunc(); return 0;}
test.cc
#include "hello.h"int main(){ HelloFunc(); return 0;}
Makefile
gcc -o Test test.cc -I.../include/ -L.../lib/ -lhellogcc -o Test test.c -I.../include/ -L.../lib/ -lhellog++ -o Test test.cc -I.../include/ -L.../lib/ -lhellog++ -o Test test.c -I.../include/ -L.../lib/ -lhellogcc main.cgcc main.ccg++ main.cg++ main.cc
结论:
1.gcc编译hello.c形成libhello.a
gcctest.c正确gcctest.cc错误g++test.c错误g++test.cc错误2.g++编译hello.cc形成libhello.a
gcctest.c错误gcctest.cc正确g++test.c正确g++test.cc正确3.gcc编译hello.c形成libhello.so
gcctest.c正确gcctest.cc错误g++test.c错误g++test.cc错误4.g++编译hello.cc形成libhello.so
建议:
使用g++编写静态链接库和动态链接库
0 0
- gcc与g++编译链接库文件兼容性
- gcc/g++ 链接库的编译与链接
- gcc/g++ 链接库的编译与链接
- 【C++】gcc/g++ 链接库的编译与链接
- cpp g++与gcc编译链接区别
- gcc g++ 编译链接
- gcc与g++的编译链接的示例详解
- gcc/g++编译makefile文件
- gcc(g++)多文件编译
- gcc & g++ 编译链接生成详解
- gcc,g++编译链接有关的路径
- gcc/g++ 动态编译和链接问题
- gcc,g++编译链接有关的路径
- g++如何链接gcc生成的静态库文件
- gcc编译链接c++文件
- gcc编译链接多文件
- GCC编译链接多文件
- G++编译:动态链接库的链接与使用
- Eclipse快捷键整理
- MoviePlayerViewController
- Ubuntu配置静态IP
- Python练习-- List Comprehensions
- Berland National Library
- gcc与g++编译链接库文件兼容性
- Linux下安装maven
- iOS 开发 -- Swift 语法篇 (三) 控制流
- Python——运算符重载(2)
- Log4j使用及配置
- 源代码管理工具SVN的使用(三)(命令行)
- AngularJS如何下载Excel文件
- 基于Servlet&Jsp的网上书店设计(二)
- OpenJudge百炼习题解答(C++)--题2704:竞赛评分