一 编写test1.cpp
#include <iostream>
using namespace std;
void f1(int age)
{
cout << "this is libtest1.so: " << age << endl;
}
二 编写test2.cpp
#include <iostream>
using namespace std;
void f2(int age)
{
cout << "this is libtest2.so: " << age << endl;
}
三 编写main.cpp
extern void f1(int age); //声明要使用的函数
extern void f2(int age); //声明要使用的函数
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
f1(65);
f2(66);
cout << "bye" << endl;
return 0;
}
四 生成动态库文件libtest1.so
[root@localhost test]# g++ test1.cpp test2.cpp -fPIC -shared -o libtest1.so
[root@localhost test]# ll


522

被折叠的 条评论
为什么被折叠?



