Cpp development environment settings in Windows - githeim/windheim_archive GitHub Wiki
์๋์ฐ์ฆ ํ๊ฒฝ์์ C++ ๊ฐ๋ฐํ๊ฒฝ์ ๊ตฌ์ถํ๋ ๋ฐฉ๋ฒ์ ๋ํ ๋ฉ๋ชจ.
์๋ ๋ฌธ์๋ฅผ ๋ ํผ๋ฐ์ค๋ก ์์ฑํ๋ค. https://code.visualstudio.com/docs/cpp/config-mingw?originUrl=%2Fdocs%2F
https://code.visualstudio.com/Download
Install the package
then install the c/c++ extension
https://github.com/msys2/msys2-installer/releases/download/2024-12-08/msys2-x86_64-20241208.exe
์ค์น ๋๋ ํ ๋ฆฌ๋ฅผ
D:\Installed\msys64
๋ผ๊ณ ์์
msys ํ๋กฌํํธ์์
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
๋ํดํธ๋ก ์ ์ฒด ์ค์น - ๋๋ต 1GB ์์ชฝ
์ค์ ๊ฒ์ --> ์ค์ ์ผ๋ก ์ง์
ํ๊ฒฝ๋ณ์ ์ค์ ๊ฒ์ --> ๊ณ์ ์ ๋ํ ํ๊ฒฝ๋ณ์ ์ ํ
์๋์ ๊ฐ์ด mingw64 bin ์์น ์ค์
D:\Installed\msys64 ์์น์ ์ค์นํ๋ค๋ฉด
์์น๋ ๋ค์์ด ๋๋ค
D:\Installed\msys64\ucrt64\bin
ํ๊ฒฝ๋ณ์ Path์ ์ ๊ฒฝ๋ก ์ถ๊ฐ
๋ช ๋ น ํ๋กฌํํธ๋ฅผ ํ๋ ๋์ฐ๊ณ ์๋์ฒ๋ผ ์ค์น์ฌ๋ถ ํ์ธ
gcc --version
msys console ์์ ๋ค์๊ณผ ๊ฐ์ด ์ค์น
pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_image mingw-w64-x86_64-SDL2_mixer mingw-w64-x86_64-SDL2_ttf
main.cpp
#include <SDL2/SDL.h>
#include <iostream>
#undef main
int main(int argc, char* argv[]) {
// SDL ์ด๊ธฐํ
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
// SDL ์ฐฝ ์์ฑ
SDL_Window* window = SDL_CreateWindow("Main Window",
100, 100, 800, 600, SDL_WINDOW_SHOWN);
if (!window) {
std::cerr << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
// SDL ๋ ๋๋ฌ ์์ฑ
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
std::cerr << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// ํ
์ค์ฒ ์์ฑ์ ์ํ surface ์์ฑ
SDL_Surface* surface = SDL_CreateRGBSurface(0, 80, 400, 32, 0, 0, 0, 0);
if (!surface) {
std::cerr << "Surface creation failed: " << SDL_GetError() << std::endl;
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// surface๋ฅผ ๋
น์์ผ๋ก ์ฑ์ฐ๊ธฐ
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 0, 255, 0));
// surface๋ก๋ถํฐ ํ
์ค์ฒ ์์ฑ
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface); // surface๋ ๋ ์ด์ ํ์์์
if (!texture) {
std::cerr << "Texture creation failed: " << SDL_GetError() << std::endl;
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
bool quit = false;
SDL_Event e;
while (!quit) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
quit = true;
}
if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.sym == SDLK_LEFT) {
// ์ผ์ชฝ ํ์ดํ ํค
} else if (e.key.keysym.sym == SDLK_RIGHT) {
// ์ค๋ฅธ์ชฝ ํ์ดํ ํค
}
}
}
// ๊ทธ๋ฆด ์๊น ๊ฒ์์์ผ๋ก ์ค์
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
// ํ๋ฉด ์ง์ฐ๊ธฐ - ๊ฒ์์์ผ๋ก ๊ทธ๋ฆฌ๊ธฐ
SDL_RenderClear(renderer);
// ์ฌ๊ฐํ์ ์์น์ ํฌ๊ธฐ ์ค์
SDL_Rect destRect;
destRect.w = 80;
destRect.h = 400;
destRect.x = (800 - destRect.w) / 2;
destRect.y = (600 - destRect.h) / 2;
// ํ์ ์ค์ฌ์ ์ค์
SDL_Point center = {destRect.w / 2, destRect.h / 2};
// ํ
์ค์ฒ๋ฅผ 43๋ ํ์ ํ์ฌ ๊ทธ๋ฆฌ๊ธฐ
SDL_RenderCopyEx(renderer, texture, NULL, &destRect, 43.0, ¢er, SDL_FLIP_NONE);
// ํ๋ฉด ์
๋ฐ์ดํธ
SDL_RenderPresent(renderer);
// ์ฌ๊ธฐ 16ms
SDL_Delay(16);
}
// ์ ๋ฆฌ
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
SDL2 DLL ๋ณต์ฌ ๋ฃจํด์ ํฌํจํ tasks.json
.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"main.cpp",
"-o",
"main.exe",
"-I",
"D:/Installed/msys64/mingw64/include",
"-L",
"D:/Installed/msys64/mingw64/lib",
"-lSDL2main",
"-lSDL2",
"-mconsole"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": ["Copy SDL2 DLL"]
},
{
"label": "Copy SDL2 DLL",
"type": "shell",
"command": "copy",
"args": [
"D:\\Installed\\msys64\\mingw64\\bin\\SDL2.dll",
"${fileDirname}"
],
"problemMatcher": []
}
]
}
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug SDL2 Program",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file"
}
]
}