1. Build shared library project from Eclipse.
2. Create header (hello.h) and source (hello.cc) file. Build them to create the shared library.
codes of hello.h
#ifndef HELLO_H_ #define HELLO_H_ void output(); #endif /* HELLO_H_ */
codes of hello.h
#include <iostream> using namespace std; void output() { cout<<"I am shared library!"<<endl; }
3. Build test project. But hello.h could not be found and output() is not declared, if we try to build the project.
4. Add Includes so that hello.h could be found. One can also add Includes through C/C++ General->Paths and Symbols->Includes->Languages>GNU C++.
5. Add shared library so that output() is declared.
6. Now we can build the test project. However, it could not run correctly.
7. Add LD_LIBRARY_PATH and its value (shared library path) in Run Configurations.
An alternative step of step 7 is using -R option to point out the run-time path. Currently, the link-time path and run-time path are separated. This method is better than using LD_LIBRARY_PATH because LD_LIBRARY_PATH is globally effective.
Now it is ok to run!
Setting shared (dynamic) library in Eclipse c++ in Linux
原文:http://blog.csdn.net/jsc0218/article/details/19237737