如何从终端运行在eclipse中编写的c++程序

时间:2022-08-29 17:30:46

I'm using Ubuntu and I have written my c++ code in Eclipse Neon. My workspace contain 4 projects. The main project is called BaseCppProjectRun (it contains main.cpp file) and I have other projects with these names: Encoders, frmwrk, NetworkLayer - the BaseCppProjectRun using each one of them.

我正在使用Ubuntu,我已经在Eclipse霓虹灯上写了我的c++代码。我的工作区包含4个项目。主要项目叫做BaseCppProjectRun(它包含main)。我还有其他项目有这些名字:编码器,frmwrk, NetworkLayer——BaseCppProjectRun使用它们中的每一个。

If I running my program directly from eclipse everything works. But I want to running my program from terminal - and I can't. Because When I'm trying to run my progrm like this:

如果我直接从eclipse运行我的程序,那么一切都可以工作。但是我想在终端上运行我的程序——我不能。因为当我试着这么做的时候:

root@ubuntu:/builds/BaseCppProject/BaseCppProjectRun# ./Debug/BaseCppProjectRun

I'm getting this error:

我得到这个错误:

./Debug/BaseCppProjectRun: error while loading shared libraries: libfrmwrk.so: cannot open shared object file: No such file or directory

As I said before, if I'm running it directly from eclipse everything works.

如前所述,如果我直接从eclipse运行它,那么一切都可以工作。

How can I run my program from terminal?

如何从终端运行程序?

2 个解决方案

#1


2  

How is Linux supposed to know where to find libfrmwrk.so, if you don't put that either where it normally looks nor tell it where it can be found.

Linux怎么知道在哪里可以找到libfrmwrk呢?所以,如果你不把它放在正常的位置上,也不要告诉它在哪里可以找到。

Eclipse seems to set up the paths the runtime linker looks into so, that when your program is loaded, the runtime linker knows where to find your libfrmwrk.so and so on.

Eclipse似乎设置了运行时链接器查看的路径,以便在加载程序时,运行时链接器知道在哪里找到libfrmwrk。所以,等等。

You'll either have to

你要么

  • install these libraries (.so's) so that they are found in default locations, or
  • 安装这些库(.so's),以便在默认位置找到它们
  • set LD_LIBRARY_PATH to contain all the folders to look into.
  • 设置LD_LIBRARY_PATH以包含要查看的所有文件夹。

I haven't worked with Eclipse CDT in ages, but you can by now probably export some project formats that allow you to easily install things.

我已经很久没有使用过Eclipse CDT了,但是现在您可能可以导出一些项目格式,使您能够轻松地安装东西。

Another thing: It seems you're running software you're still debugging as root: That is a terrible idea, and if it can be avoided, avoid it.

另一件事:似乎你正在运行的软件,你仍在调试:这是一个可怕的想法,如果可以避免,避免它。

#2


0  

I finally figure it out!

我终于明白了!

Refere to Marcus Muller's answer + my steps this is how I have fixed it ( all steps via terminal):

参考马库斯·穆勒的答案+我的步骤这是我如何修复的(所有步骤通过终端):

  1. Create new directory in my workspace directory and called it libs.
  2. 在我的工作空间目录中创建新目录,并将其命名为libs。
  3. In each one of your projects do: right click > c/C++ Build > Build Steps (tab) and in Post-build steps paste this:
  4. 在你的每一个项目中:右击> c/ c++构建>构建步骤(tab),然后在构建后的步骤中粘贴如下:

cp ${BuildArtifactFilePrefix}${BuildArtifactFileName} "${WorkspaceDirPath}/libs/"

This code copy the so files directly into your libs directory when you compile your program.

此代码在编译程序时将so文件直接复制到libs目录中。

And finally, in your terminal execute this:

最后,在你的终端执行

export LD_LIBRARY_PATH=/builds/BaseCppProject/libs/

Now you can run your program via terminal.

现在你可以通过终端运行你的程序了。

#1


2  

How is Linux supposed to know where to find libfrmwrk.so, if you don't put that either where it normally looks nor tell it where it can be found.

Linux怎么知道在哪里可以找到libfrmwrk呢?所以,如果你不把它放在正常的位置上,也不要告诉它在哪里可以找到。

Eclipse seems to set up the paths the runtime linker looks into so, that when your program is loaded, the runtime linker knows where to find your libfrmwrk.so and so on.

Eclipse似乎设置了运行时链接器查看的路径,以便在加载程序时,运行时链接器知道在哪里找到libfrmwrk。所以,等等。

You'll either have to

你要么

  • install these libraries (.so's) so that they are found in default locations, or
  • 安装这些库(.so's),以便在默认位置找到它们
  • set LD_LIBRARY_PATH to contain all the folders to look into.
  • 设置LD_LIBRARY_PATH以包含要查看的所有文件夹。

I haven't worked with Eclipse CDT in ages, but you can by now probably export some project formats that allow you to easily install things.

我已经很久没有使用过Eclipse CDT了,但是现在您可能可以导出一些项目格式,使您能够轻松地安装东西。

Another thing: It seems you're running software you're still debugging as root: That is a terrible idea, and if it can be avoided, avoid it.

另一件事:似乎你正在运行的软件,你仍在调试:这是一个可怕的想法,如果可以避免,避免它。

#2


0  

I finally figure it out!

我终于明白了!

Refere to Marcus Muller's answer + my steps this is how I have fixed it ( all steps via terminal):

参考马库斯·穆勒的答案+我的步骤这是我如何修复的(所有步骤通过终端):

  1. Create new directory in my workspace directory and called it libs.
  2. 在我的工作空间目录中创建新目录,并将其命名为libs。
  3. In each one of your projects do: right click > c/C++ Build > Build Steps (tab) and in Post-build steps paste this:
  4. 在你的每一个项目中:右击> c/ c++构建>构建步骤(tab),然后在构建后的步骤中粘贴如下:

cp ${BuildArtifactFilePrefix}${BuildArtifactFileName} "${WorkspaceDirPath}/libs/"

This code copy the so files directly into your libs directory when you compile your program.

此代码在编译程序时将so文件直接复制到libs目录中。

And finally, in your terminal execute this:

最后,在你的终端执行

export LD_LIBRARY_PATH=/builds/BaseCppProject/libs/

Now you can run your program via terminal.

现在你可以通过终端运行你的程序了。