如何通过主机端Eclipse C/C++实现目标机直接编译C/C++项目?
Absolutely, I’ve set this up multiple times for embedded and remote server projects—Eclipse can absolutely handle compiling directly on your target machine, just like you did with Netbeans. Here’s a step-by-step breakdown of how I got it working:
1. Set Up Remote System Explorer (RSE)
First, make sure you have the Remote System Explorer plugin installed (search for it in the Eclipse Marketplace if it’s not already there). Once installed:
- Open the Remote Systems view (Window > Show View > Other > Remote Systems > Remote Systems)
- Add a new connection to your target machine—SSH is the most reliable option here. Enter your target’s IP/hostname, username, and either password or SSH key for authentication. Test the connection to confirm you can access the target’s file system.
2. Link Your Project to Remote Source Files
You don’t need to copy source code locally. Instead:
- Either create a new C/C++ project in Eclipse, then go to project properties > Resource > Linked Resources to add a link to the source directory on your target machine.
- Or, browse to your target’s source folder via the RSE view, right-click it, and select Import > Project from Folder or Archive to import it as a local Eclipse project linked to the remote files.
3. Configure Remote Build Commands
This is the core part—telling Eclipse to run compilation commands on the target instead of locally:
- Right-click your project > Properties > C/C++ Build > Builder Settings
- Change the Builder Type to Custom builder (this lets you define your own build command)
- In the Build command field, enter an SSH command that runs your build process on the target. For example:
If you use CMake, adjust it to:ssh your-username@target-ip "cd /path/to/your/project && make"ssh your-username@target-ip "cd /path/to/your/project/build && cmake .. && make" - Under Build Steps, you can add pre-build commands if you have dependent projects—for example, to compile a linked library first:
ssh your-username@target-ip "cd /path/to/dependency-project && make"
4. Handle Project Dependencies & Sync
For recursive project dependencies, I’ve found it’s more reliable to manage them directly on the target machine using Makefile or CMake (setting up proper SUBDIRS or add_subdirectory directives) instead of relying on Eclipse’s internal dependency management. This way, when you run the remote build command, the target’s build system automatically handles recursive compilation.
To keep your local Eclipse view in sync with remote source changes:
- Use the RSE view’s Synchronize feature (right-click the remote folder > Synchronize) to push local edits to the target, or pull remote changes to your local linked project. You can also set up automatic sync on save if needed.
5. Optional: Remote Debugging
If you need to debug the compiled binary, Eclipse supports remote GDB debugging:
- Install
gdbserveron your target machine - On the target, run
gdbserver :port /path/to/your/binary - In Eclipse, go to Run > Debug Configurations > C/C++ Remote Application, set up a new configuration pointing to your target’s IP/port, and link it to your project. You’ll be able to set breakpoints, inspect variables, and debug just like you would locally.
Pro Tips
- Use SSH key authentication instead of passwords to speed up connections and avoid repeated login prompts. Configure this in your RSE connection settings.
- Ensure your target machine has all required build tools installed (gcc/g++, make, cmake, etc.)—same as you did for Netbeans.
内容的提问来源于stack exchange,提问作者BeatIdo

