如何在 Eclipse 中的远程计算机上构建 C++ 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/856444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to build a c++ project on a remote computer in Eclipse?
提问by r0u1i
I have a Windows pc with Eclipse Ganymede installed, and a Linux pc where my C++ project files are located. I use Eclipse to edit the files through SMB, and would like to build the project using Eclipse as well. Currently I connect using putty to my linux machine, and run ./make from the appropriate directory. How would I run the same command within Eclipse and see the results in it? I have installed the RSE plugin, but still can't grasp how to do so.
我有一台安装了 Eclipse Ganymede 的 Windows 电脑和一台 Linux 电脑,我的 C++ 项目文件所在的位置。我使用 Eclipse 通过 SMB 编辑文件,并希望使用 Eclipse 构建项目。目前我使用 putty 连接到我的 linux 机器,并从适当的目录运行 ./make。我将如何在 Eclipse 中运行相同的命令并查看其中的结果?我已经安装了 RSE 插件,但仍然无法掌握如何安装。
Just to made myself clear - I can use VNC to work on Eclipse that is installed on my linux machine, but I prefer not do so. Eclipse through VNC is slow and not as responsive as the Eclipse installed on my windows machine.
只是为了让自己清楚 - 我可以使用 VNC 在我的 linux 机器上安装的 Eclipse 上工作,但我不想这样做。通过 VNC 的 Eclipse 很慢,而且响应速度不如安装在我的 Windows 机器上的 Eclipse。
Thanks, Rouli
谢谢,鲁莉
回答by Ismael
I was in a similar situation, developing in a windows workstation, compiling in a linux server. This is what I ended doing:
我处于类似的情况,在 Windows 工作站中开发,在 linux 服务器中编译。这是我结束做的事情:
- Setup a passwordless login to the compiler server with putty, for example you can follow this tutorial.
- Create a login session with putty, make sure that in Connections/SSH/Auth is pointing to your private key.
- Modify eclipse make command to
plink.exe -load "saved_session" make -C /remote/path/project
(This setting is in Project/Properties/C++Build/Builder Settings/Build command). You can automate this with a batch/shell file if you have to pass more parameters and/or your setup is more complex.
- 使用 putty 设置无密码登录到编译器服务器,例如您可以按照本教程进行操作。
- 使用 putty 创建登录会话,确保在 Connections/SSH/Auth 中指向您的私钥。
- 将 eclipse make 命令修改为
plink.exe -load "saved_session" make -C /remote/path/project
(此设置在 Project/Properties/C++Build/Builder Settings/Build 命令中)。如果您必须传递更多参数和/或您的设置更复杂,您可以使用批处理/外壳文件自动执行此操作。
If you have stored a passphrase with your private key then you can use pageant.exe to load your key only once, so you dont have to type your passphrase every time.
如果您使用私钥存储了密码,那么您可以使用 pageant.exe 只加载一次您的密钥,因此您不必每次都输入密码。
回答by Mike Kucera
You can create a project on a remote machine using RSE. To do so you must have the RSE server component installed on the remote machine. Create a connection to the machine using the RSE Remote Systems view. Create a new C/C++ project and on the first page of the wizard uncheck the checkbox that says "use default location". This enables a dropdown of file system providers, choose RSE. Then when you click Browse you will get a dialog that lets you browse the remote system for the folder where you want your project to live.
您可以使用 RSE 在远程机器上创建项目。为此,您必须在远程计算机上安装 RSE 服务器组件。使用 RSE 远程系统视图创建与机器的连接。创建一个新的 C/C++ 项目,然后在向导的第一页取消选中“使用默认位置”复选框。这将启用文件系统提供程序的下拉列表,选择 RSE。然后,当您单击“浏览”时,您将看到一个对话框,可让您浏览远程系统以查找您希望项目所在的文件夹。
There are a few issues with this approach. First of all when the CDT indexer wants to build the index it needs to parse all the files in your project, which means downloading all the files to your local machine. This can be slow if you have a large project or a slow connection.
这种方法存在一些问题。首先,当 CDT 索引器要构建索引时,它需要解析您项目中的所有文件,这意味着将所有文件下载到您的本地机器。如果您有一个大型项目或连接速度较慢,这可能会很慢。
Another issue is that when you restart eclipse the remote projects will be closed. This is because you don't have a connection to the remote machine yet so eclipse can't read the .project file. You will have to reopen your remote projects every time you start eclipse.
另一个问题是,当您重新启动 eclipse 时,远程项目将被关闭。这是因为您还没有连接到远程机器,所以 eclipse 无法读取 .project 文件。每次启动 eclipse 时,您都必须重新打开远程项目。
There is currently a project in the works called RDT (Remote Development Tools) which adds remote indexing capabilities to CDT. That means the indexer will live on the remote machine with your code, so the files don't have to be downloaded for the indexer. Its still in "alpha" status, but if you are adventurous and want to try it out go here.
目前有一个名为 RDT(远程开发工具)的项目正在为 CDT 添加远程索引功能。这意味着索引器将与您的代码一起存在于远程计算机上,因此不必为索引器下载文件。它仍处于“alpha”状态,但如果您喜欢冒险并想尝试一下,请到这里。
回答by wr.
回答by Mark
For working from a Linux host, compiling in a [different] Linux remote environment, the order of instructions would be,
对于在 Linux 主机上工作,在 [不同的] Linux 远程环境中进行编译,指令的顺序是,
1 $ ssh-keygen
to create a passphraseless ssh key pair [here, id_rsa_nopassphrase
], then scp
the id_rsa_nopassphrase.pub
key from host's ~/.ssh/
to the remote's ~/.ssh/authorized_keys
[append content in case there is already such a file on the remote]; then
1$ ssh-keygen
创建一个无密码的 ssh 密钥对 [here, id_rsa_nopassphrase
],然后scp
是id_rsa_nopassphrase.pub
从主机~/.ssh/
到远程的密钥~/.ssh/authorized_keys
[附加内容,以防远程上已经有这样的文件];然后
2 Add an entry to the host's ~/.ssh/config
such as
Host my_remote_ssh_alias
HostName MY_REMOTE_SERVER
User remote_username
Port 22
IdentityFile /home/<host_username>/.ssh/id_rsa_nopassphrase
then
2 向主机添加一个条目,~/.ssh/config
例如
Host my_remote_ssh_alias
HostName MY_REMOTE_SERVER
User remote_username
Port 22
IdentityFile /home/<host_username>/.ssh/id_rsa_nopassphrase
then
3 Eclipse make command is then ssh my_remote_ssh_alias -F /home/host_username/.ssh/config 'make -C /remote/path/to/project'
3 Eclipse make 命令然后 ssh my_remote_ssh_alias -F /home/host_username/.ssh/config 'make -C /remote/path/to/project'
回答by Liran Orevi
Have you tried running Eclipse from the Linux machine with X11 forwarding? You should have Eclipse installed on the Linux machine first.
您是否尝试过使用X11 转发从 Linux 机器运行 Eclipse ?您应该首先在 Linux 机器上安装 Eclipse。
Haven't tried it myself.
自己没试过。
回答by iain
Like Liran Orevi said you can use x windows.
就像 Liran Orevi 说的,你可以使用 x windows。
- Install the cygwin x server on your windows system.
- Enable remote connections to this X server using "xhost +" or similar (xhost + is not considered secure so don't do it on a public network but its ok for most cases)
- ssh on to the linux box
- set the DISPLAY environment variable eg "export DISPLAY=":0"
- run eclipse from the command line Eclipse should now appear on xserver on the windows system.
- 在 Windows 系统上安装 cygwin x 服务器。
- 使用“xhost +”或类似方法启用与此 X 服务器的远程连接(xhost + 不被认为是安全的,因此不要在公共网络上执行此操作,但在大多数情况下可以)
- ssh 到 linux 机器
- 设置 DISPLAY 环境变量,例如“export DISPLAY=":0”
- 从命令行运行 Eclipse Eclipse 现在应该出现在 Windows 系统的 xserver 上。
ssh can automate the forwarding, removing the need for xhost + and the DISPLAY env.
ssh 可以自动转发,无需 xhost + 和 DISPLAY 环境。