C++ 环境设置
Visual Studio Setup (Windows)
Installation Steps
-
Download Visual Studio
- Visit visualstudio.microsoft.com
- Download the Community edition (free)
-
Install C++ Workload
- During installation, select "Desktop development with C++"
- This installs:
- MSVC compiler
- Standard Library
- Windows SDK
- Debugging tools
-
Verify Installation
Compile and Run
Using Developer Command Prompt:
GCC Setup (Linux/macOS)
Linux Installation
Ubuntu/Debian:
Fedora:
Arch Linux:
macOS Installation
Using Homebrew:
Using Xcode Command Line Tools:
Verify Installation
Compile and Run
Online IDEs
Recommended Online Compilers
-
Compiler Explorer - godbolt.org
- Real-time compilation
- Multiple compilers support
- Assembly output
-
Replit - replit.com
- Full development environment
- Collaboration features
- GitHub integration
-
OnlineGDB - onlinegdb.com
- Built-in debugger
- Simple interface
IDE Recommendations
Visual Studio Code
-
Install Extensions:
- C/C++ (Microsoft)
- C/C++ Extension Pack (Microsoft)
- Code Runner (formulahendry)
-
Configure Settings:
CLion
- Professional IDE by JetBrains
- Built-in CMake support
- Advanced debugging
- Cross-platform
Project Setup
Basic Project Structure
CMake Configuration
Build Systems
Using Make
Using CMake
Common Build Flags
Compiler Flags
Example Compile Command
Debugging Setup
Using GDB
Common GDB Commands:
Using Visual Studio Debugger
- Set breakpoints by clicking the margin
- Press F5 to start debugging
- Use F10 (step over) and F11 (step into)
- Watch window shows variables
Common Issues and Solutions
Issues
-
'g++' is not recognized
- Solution: Add compiler to PATH
-
Linker errors
- Solution: Link required libraries with
-lflag
- Solution: Link required libraries with
-
Permission denied
- Solution:
chmod +x your_program(Unix)
- Solution:
-
Library not found
- Solution: Use
-Ifor include paths and-Lfor library paths
- Solution: Use
Getting Help
Next Steps
- Create your first program
- Practice basic syntax
- Learn debugging techniques
- Explore standard library
- Build a small project