gcc动态库及静态库

来源:互联网 发布:查询淘宝页面历史快照 编辑:程序博客网 时间:2024/06/03 13:26
//libt.h#ifdef __cplusplusextern "C" {#endifvoid PrintMsg(const char* msg);#ifdef __cplusplus}#endif//libt.cpp#include"libt.h"#include<iostream>using namespace std;void PrintMsg(const char* msg){cout << "PrintMsg : " << msg << endl;}//libt2.cpp#include<iostream>using namespace std;void PrintMsg(const char* msg){cout << "PrintMsg : " << msg << endl;}//test.c#include"libt.h"#include<stdio.h>#include<stdlib.h>#include<math.h>int main(){PrintMsg("Hello World!");printf("sinx(x)=%lf\n",sin(3.1415926/3));return 0;}//makefileALL:g++ -shared -o libt.so libt.cppg++ -shared -o libt2.so libt2.cppnm libt.so | grep PrintMsgnm libt2.so | grep PrintMsggcc -c test.cgcc -o t1 test.o -L$(PWD) -lt -lmldd t1g++ -c libt.cppar rvs t.a libt.og++ -o t2 test.o -L$(PWD) -l:t.a -lmldd t2g++ -o t3 test.o libt.o -lmg++ -o t4 test.c libt.cpp -lm./t1./t2./t3./t4clean:rm *.o *.so *.a  t1 t2 t3 t4


0 0
原创粉丝点击