Running some small test codes on Linux from Windows can be quite tedious, especially since I have to manually execute the compilation commands on Linux. Also, using Samba on my Raspberry Pi to share the code to Windows requires me to SSH and compile it manually, which is a waste of time.
These past few days, I wrote a small Sublime Text plugin during my free time to remotely compile C/C++ code on Windows, meaning that I write the code on Windows but it actually executes on Linux. I’ve only implemented the functionality for now, and I plan to optimize it during my break after the holidays.
The code is hosted on GitHub: sublimeRemoteCompile, using some C++11
features, and the compiler must be specified during compilation.
Update: 2017.02.18
- Modified execution logic
ChangedUploadCurrentFolder
toUploadCurrentFolderAndRun
, which uploads the current file’s folder and executes the compile and run operations after the upload is complete. - Added the
UploadCurrentFolderAndTerminalRun
mode, which uploads the current file’s folder and opens it in a new window to run. - Folders uploaded using the above two modes will not be automatically deleted, with their path set as
remoteTempFolder/RunTime
in the ini, where RunTime is the timestamp when the upload operation was performed. - When the source file is in the Samba directory, the above two upload modes will not execute.
Update: 2017.01.26
- Optimized the code.
- Introduced another mechanism: If the remote host’s directory is mapped to local via Samba, compile the source files directly in that remote directory (by converting the local mapped path to the absolute path of the remote host), without executing the upload source file step (since the file already exists on the remote host).
For example: If the remote host has a Samba folder~/code
, which I mapped to my Z drive, when I create a new source filehw.cc
under Z drive (i.e., the remote host’s~/code
) and use this plugin for remote compilation, it will directly execute the compilation operation (while it would upload first and then compile if not under Samba), thus improving runtime speed.
Usage:
In setting.ini
, specify the sambaDrive
option as the drive letter mapped to the remote Samba and remoteSambaPath
as the path of the remote host’s Samba folder mapped to the local sambaDrive
.
1 | ; The remote host's ~/ directory is mapped to the local Z drive |
Thus, executing “remote compile” on files in the local Z drive
will not trigger uploads (neither UploadThisFile
nor UploadCurrentFolder
modes will execute).
Using SSH makes writing some simple test code quite enjoyable, and error messages will be captured in Sublime Text’s Panel. For complex projects, Visual Studio + VisualGDB can be utilized.
Configuration information is read from ini files, supporting seven running modes:
Updated the table according to the changes made on 2017.02.18.
Parameter | Mode |
---|---|
panelRun | Run in Sublime Text’s Panel |
terminalRun | Run in a new window |
uploadThisFile | Upload the currently opened file to the remote host’s temporary directory |
UploadCurrentFolderAndRun | Upload the folder of the currently opened file to the remote host’s temporary directory and execute in ST’s panel |
UploadCurrentFolderAndTerminalRun | Upload the folder of the currently opened file to the remote host’s temporary directory and execute in a new window |
cleanUpTemp | Clean up the temporary directory of the remote host |
openTerminal | Open an SSH connection window to the remote host |
The running mode must be specified at startup.
Two parameters need to be specified during execution: the source file path and the running mode. The source file path can be obtained through ${file}
in Sublime Text’s build system
.
During compilation, the language will be determined based on the file suffix; C language will default to using gcc, while C++ will use g++, corresponding to standard versions c99 and c++11. It is recommended to install clang on Linux and specify the compiler as clang
in setting.ini
, as error messages will be much clearer. If clang
is specified, it will automatically match the suffix to select clang
or clang++
as the compiler.
How to use?
Download the binary compressed package from here and extract it to a local directory.
Then, add a build system
in Sublime Text and fill in the following code:
1 | { |
Fill in the path
with the absolute path where you extracted the compressed package (i.e., the absolute path of this program on your computer).
Next, you can easily write some code, press Ctrl+Shift+B
, and you’ll see the build system list:
Select any option to start execution.
If this is your first time using it, a setting.ini
file will be generated in the directory of the binary, where you need to fill in your environment information:
1 | [RemoteCompileSSHSetting] |
It is recommended to fill in host
and password
or sshKey
, while keeping the others as default.
Additionally, the sshKey
must be a ppk key; it should be converted to ppk using puttygen
(found in the SSHTools directory). Using password
is advised.