从DevC++迁移至命令行编译:实验室设备C++代码部署自动化咨询
Hey there! Let's break down how to automate your lab device workflow step by step—no more manual dragging, clicking, or worrying about outdated binaries. Here's what I'd recommend based on similar lab automation setups I've helped with:
Dev-C++ uses MinGW under the hood, so you can skip the manual GUI compilation and build all modules via command line. Here's how to set it up:
- Create a batch script named
build_all.batin your project root. For each module, add a compilation line like this (tweak paths/libraries to match your code):g++ -o "C:\LabCode\bin\temperature_monitor.exe" "C:\LabCode\src\temperature_monitor.cpp" -I"C:\LabCode\includes" -L"C:\LabCode\libs" -lsensor_lib - If you have tons of modules, use a
forloop to auto-compile all.cppfiles in your source folder:for %%f in ("C:\LabCode\src\*.cpp") do ( g++ -o "C:\LabCode\bin\%%~nf.exe" "%%f" -I"C:\LabCode\includes" -L"C:\LabCode\libs" -lsensor_lib ) - Double-click this script whenever you need to build all modules—no more opening Dev-C++ for each one.
Add a line at the end of your build_all.bat to automatically copy compiled .exes to your Dropbox folder. Dropbox will handle syncing to all hosts:
copy "C:\LabCode\bin\*.exe" "C:\Users\YourName\Dropbox\LabDeviceBinaries\"
Now every time you build, fresh binaries are sent to the cloud instantly.
To make sure each host uses the newest binaries and runs them automatically:
- Create a
run_devices.batscript in your DropboxLabDeviceBinariesfolder. This script will:- Wait for Dropbox to finish syncing (use Dropbox's command-line tool to check status):
:WAIT_FOR_SYNC dropbox status | findstr "Up to date" > nul if %errorlevel% neq 0 ( timeout /t 5 /nobreak > nul goto WAIT_FOR_SYNC ) - Kill any old running instances to avoid conflicts:
taskkill /F /IM temperature_monitor.exe > nul 2>&1 taskkill /F /IM pressure_controller.exe > nul 2>&1 - Launch all modules in the background:
start /B temperature_monitor.exe start /B pressure_controller.exe
- Wait for Dropbox to finish syncing (use Dropbox's command-line tool to check status):
- Set this script to run on host startup:
- Press
Win + R, typeshell:startup, and hit Enter. - Create a shortcut to
run_devices.batand drop it into this folder.
- Press
- Pro tip: Use
NSSM(Non-Sucking Service Manager) to run each module as a Windows service. This ensures they restart if they crash and run even when no user is logged in.
To avoid syncing faulty binaries:
- Add error checking to your
build_all.bat—only copy files if compilation succeeds:set "BUILD_FAILED=0" g++ -o ... || set "BUILD_FAILED=1" if %BUILD_FAILED% equ 0 ( copy "C:\LabCode\bin\*.exe" "C:\Users\YourName\Dropbox\LabDeviceBinaries\" ) else ( echo Build failed! Binaries not synced. pause ) - Use Git to track your source code—add a
git pullline at the start ofbuild_all.batto ensure you're always building the latest code.
内容的提问来源于stack exchange,提问作者C. Parzyck

