我正在寻找基本的示例/教程:
如何用C++编写/编译库(.so
Linux .dll
文件,Windows文件).
如何在其他代码中导入和使用这些库.
wilhelmtell.. 16
r.cc:
#include "t.h" int main() { f(); return 0; }
th:
void f();
t.cc:
#include#include "t.h" void f() { std::cout << "OH HAI. I'M F." << std::endl; }
~$ 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
export
如果沿全局库路径安装共享库,则不需要该步骤.
r.cc:
#include "t.h" int main() { f(); return 0; }
th:
void f();
t.cc:
#include#include "t.h" void f() { std::cout << "OH HAI. I'M F." << std::endl; }
~$ 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
export
如果沿全局库路径安装共享库,则不需要该步骤.