"VScode + gcc でDXライブラリの環境構築をしてみた話" (//szshow.hatenablog.com/entry/2020/01/11/164506)で検索して
上記にでてくるサイトを参考に VScodeでgccを使って環境構築を行おうとしたのですが、プログラミングの知識も乏しいため、理解しないまま書いてある通りにビルドやデバッグの設定をしたのですが、デバッグを実行した結果
> Executing task: g++.exe -g -c main.cpp "-I\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\include" -I\8_1_0_i686_w64_posix_dwarf_rt_v6_rev0 -I . -DDX_GCC_COMPILE -DDX_NON_INLINE_ASM <
main.cpp:1:10: fatal error: DxLib.h: No such file or directory
#include "DxLib.h"
compilation terminated.
The terminal process "C:\Windows\System32\cmd.exe /d /c g++.exe -g -c main.cpp "-I\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\include" -I\8_1_0_i686_w64_posix_dwarf_rt_v6_rev0 -I . -DDX_GCC_COMPILE -DDX_NON_INLINE_ASM" failed to launch (exit code: 1).
DXライブラリのincludeパスが認識しないエラーをたたかれてしまいました。多分根本的な何かが欠けているのだと思いますがさっぱり検討がつきません。
ちなみに自分の"Intellisenseの設定", "ビルドの設定", "デバッグの設定" "ソースコード"は以下になります。
Intellisenseの設定
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/include",
"C:/8_1_0_i686_w64_posix_dwarf_rt_v6_rev0/"
],
"defines": [
"_DEBUG",
"MBCS",
"_MBCS"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "windows-gcc-x86",
"compilerArgs": [
"-DDX_GCC_COMPILE",
"-DDX_NON_INLINE_ASM"
]
}
],
"version": 4
ビルドの設定
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"compile",
"link"
],
"dependsOrder": "sequence"
},
{
"label": "compile",
"type": "shell",
"command": "g++.exe",
"args": [
"-g",
"-c",
"main.cpp",
"-I\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\include",
"-I\\8_1_0_i686_w64_posix_dwarf_rt_v6_rev0",
"-I",
".",
"-DDX_GCC_COMPILE",
"-DDX_NON_INLINE_ASM",
],
"problemMatcher": [
"$gcc"
]
},
{
"label": "link",
"type": "shell",
"command": "g++",
"args": [
"main.o",
"-L\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\lib",
"-L\\8_1_0_i686_w64_posix_dwarf_rt_v6_rev0",
"-lDxLib",
"-lDxUseCLib",
"-lDxDrawFunc",
"-ljpeg",
"-lpng",
"-lzlib",
"-ltiff",
"-ltheora_static",
"-lvorbis_static",
"-lvorbisfile_static",
"-logg_static",
"-lbulletdynamics",
"-lbulletcollision",
"-lbulletmath",
"-lopusfile",
"-lopus",
"-lsilk_common",
"-lcelt",
"-o",
"test.exe"
],
"problemMatcher": [
"$gcc"
]
}
]
}
デバッグの設定
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 起動",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\test.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb の再フォーマットを有効にする",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}
ソースコード (ファイル名:main.cpp)
#include "DxLib.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
unsigned int Cr;
ChangeWindowMode(TRUE);
SetGraphMode(1280, 720, 32);
if(DxLib_Init() == -1){
return -1;
}
Cr = GetColor(255, 255, 255);
DrawString(250, 240 - 32, "Hello DxLib!", Cr);
WaitKey();
DxLib_End();
return 0;
}
ファイルのディレクトリ(main.cppの保存場所)
D://Downloads
↓
dxlib_code
↓
.vscode → c_cpp_properties.json , launch.json , tasks.json
main.cpp
main.o