wil*_*ell 16
r.cc:
#include "t.h"
int main()
{
f();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
th:
void f();
Run Code Online (Sandbox Code Playgroud)
t.cc:
#include<iostream>
#include "t.h"
void f()
{
std::cout << "OH HAI. I'M F." << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
~$ g++ -fpic -c t.cc # get t.o
~$ g++ -shared -o t.so t.o # get t.so
~$ export LD_LIBRARY_PATH="." # make sure t.so is found when dynamically linked
~$ g++ r.cc t.so # get an executable
Run Code Online (Sandbox Code Playgroud)
export如果沿全局库路径安装共享库,则不需要该步骤.