I am looking for basic examples/tutorials on:
How to write/compile libraries in C++ (
.sofiles for Linux,.dllfiles for Windows).How to import and use those libraries in other code.
I am looking for basic examples/tutorials on:
How to write/compile libraries in C++ (.so files for Linux, .dll files for Windows).
How to import and use those libraries in other code.
r.cc :
#include "t.h" int main() { f(); return 0; } t.h :
void f(); t.cc :
#include<iostream> #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 The export step is not needed if you install the shared library somewhere along the global library path.
LD_LIBRARY_PATH...LD_LIBRARY_PATH use g++ -Wl,-rpath,\$ORIGIN r.cc t.so.dllexport nonetheless.