简体   繁体   English

如何在Eclipse(Linux)中使用自己的C ++书面库?

[英]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. 大家好,我想在另一个C ++程序中使用自己的库。 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". 首先,我创建了一个新的C ++项目,称为静态库“ a”。 After that I create a new class called "aClass" with the following static method: 之后,我使用以下静态方法创建一个名为“ aClass”的新类:

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. 我制作了一个名为“ b”的新C ++项目作为hello world项目。 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 将项目“ a”的包含路径添加到项目“ b”,以便eclipse可以看到aClass.h文件
  • I add the workspace of project "a" to the linker libraries 我将项目“ a”的工作区添加到链接器库
  • I add the "a" to the libraries 我将“ a”添加到库中

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": 然后,在“ b”项目中更改主文件的代码,并添加头文件“ a”,并编写一小段代码,应使用“ a”功能:

int i = aClass::addTwo(1);

When compiling with eclipse I get the following error: 使用eclipse编译时,出现以下错误:

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? 您的lib文件的名称是什么?

Is it liba.so? 是liba.so吗?

Some time library build with ".a" or "so.1" kind of extension this may cause issue. 某些时间库使用“ .a”或“ so.1”这类扩展名构建,可能会引起问题。

Try to do following 尝试执行以下操作

ln -s <current name> liba.so

Is the liba.a file actually present in /home/barti/workspace/a ? liba.a文件实际上存在于/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). 我不熟悉使用Eclipse进行C ++开发,但是GCC似乎在该目录中找不到它(据说该目录是Eclipse添加到链接路径中的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM