0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mingw-w64 DXライブラリ VisualStudioCode Makefile

Last updated at Posted at 2025-10-18

Makefileを使用するとビルド時間が短縮される
[F5]キーでビルド実行

ファイル構成.
│  main.cpp
│  Makefile
│
└─.vscode
        c_cpp_properties.json
        launch.json
        tasks.json
main.cpp
#include "DxLib.h"

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    SetUseCharCodeFormat(DX_CHARCODEFORMAT_UTF8);
    SetWindowText("サンプル");
    SetGraphMode(640, 480, 32);
    ChangeWindowMode(TRUE);
    if (DxLib_Init() == -1)
        return -1;
    SetBackgroundColor(0, 0, 0);
    SetDrawScreen(DX_SCREEN_BACK);

    while (1)
    {
        ClearDrawScreen();

        DrawString(10, 10, "サンプル", 0xffffff);

        ScreenFlip();
        WaitTimer(33);

        if (ProcessMessage() == -1)
            break;

        if (CheckHitKey(KEY_INPUT_ESCAPE) == 1)
            break;
    }

    DxLib_End();
    return 0;
}
Makefile.
# コンパイラとフラグ
CXX = g++
CXXFLAGS = -Wall -g -std=c++14 -DDX_GCC_COMPILE -DDX_NON_INLINE_ASM
INCLUDES = -IC:/dxlib -IC:/mingw64/include # DXライブラリのパス, mingw-w64のパス
LDFLAGS = -mwindows -LC:/dxlib -LC:/mingw64/lib # DXライブラリのパス, mingw-w64のパス
LIBS = -lDxLib -lDxUseCLib -lDxDrawFunc -ljpeg -lpng\
-lzlib -ltiff -ltheora_static -lvorbis_static -lvorbisfile_static\
-logg_static -lbulletdynamics -lbulletcollision -lbulletmath -lopusfile\
-lopus -lsilk_common -lcelt

# ソース・オブジェクト・ターゲット
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
TARGET = main.exe

# ルール定義
all: $(TARGET)

$(TARGET): $(OBJS)
	$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)

%.o: %.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

clean:
	del *.o *.exe

.PHONY: all clean
c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/dxlib", // DXライブラリのパス
                "C:/mingw64/include" // MinGW-w64のパス
            ],
            "defines": [
                "_DEBUG",
                "MBCS",
                "_MBCS"
            ],
            "compilerPath": "C:/mingw64/bin/gcc.exe", // MinGW-w64のパス
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "gcc-x64",
            "compilerArgs": [
                "-DDX_GCC_COMPILE",
                "-DDX_NON_INLINE_ASM"
            ]
        }
    ],
    "version": 4
}
launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 起動",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", // 実行ファイルのパス
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/mingw64/bin/gdb.exe", // MinGW-w64のパス
            "setupCommands": [
                {
                    "description": "gdb の再フォーマットを有効にする",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "make build"
        }
    ]
}
tasks.json
{
	"version": "2.0.0",
	"tasks": [
		{
			"label": "make build",
			"type": "shell",
			"command": "mingw32-make",
			"args": [],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"problemMatcher": [
				"$gcc"
			]
		},
		{
			"label": "make clean",
			"type": "shell",
			"command": "mingw32-make",
			"args": [
				"clean"
			],
			"group": "none",
			"problemMatcher": []
		}
	]
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?