How to use my own written library in C++ in eclipse (linux)?
Hey guys I have a problem, I want to use my own library in another C++ program. I will describe what I do and then want to know what's wrong.
First I create a new C++ project as a static lib called "a". After that I create a new class called "aClass" with the following static method:
static int addTwo(int num);
Now I create a program that should use the created library. I make a new C++ project called "b" as a hello world project. Now I go to the options of this project and change the following:
- Add the include path of project "a" to project "b" so eclipse sees the aClass.h file
- I add the workspace of project "a" to the linker libraries
- I add the "a" to开发者_开发百科 the libraries
Then I change my code of the main file in the "b" project and adds the header file of "a" and write a small line of code which should use a function of "a":
int i = aClass::addTwo(1);
When compiling with eclipse I get the following error:
Building target: b
Invoking: GCC C++ Linker
g++ -L"/home/barti/workspace/a" -o"b" ./src/b.o -la
/usr/bin/ld: cannot find -la
collect2: ld returned 1 exit status
make: *** [b] Fehler 1
What should I do?
What is name of your lib file?
Is it liba.so?
Some time library build with ".a" or "so.1" kind of extension this may cause issue.
Try to do following
ln -s <current name> liba.so
Is the liba.a
file actually present in /home/barti/workspace/a
? I'm not familiar with C++ development using Eclipse, but GCC does not seem to find it in that directory (which was supposedly added to the link path by Eclipse).
精彩评论