VScode + gcc でDXライブラリの環境構築

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
アバター
goma_gohan
記事: 2
登録日時: 2年前

VScode + gcc でDXライブラリの環境構築

#1

投稿記事 by goma_gohan » 2年前

https://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
ビルドの設定

コード:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format

        "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"
                ]
            }
        ]
    }
デバッグの設定

コード:

{
    // 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": "(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

アバター
みけCAT
記事: 6734
登録日時: 13年前
住所: 千葉県
連絡を取る:

Re: VScode + gcc でDXライブラリの環境構築

#2

投稿記事 by みけCAT » 2年前

DXライブラリのファイルはどこに置いていますか?
それは、Intellisenseの設定の

コード:

"C:/8_1_0_i686_w64_posix_dwarf_rt_v6_rev0/"
や、ビルドの設定の

コード:

"-I\\8_1_0_i686_w64_posix_dwarf_rt_v6_rev0",
と合っていますか?
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

アバター
goma_gohan
記事: 2
登録日時: 2年前

Re: VScode + gcc でDXライブラリの環境構築

#3

投稿記事 by goma_gohan » 2年前

ダウンロードファイルにDXライブラリのファイルからプロジェクトに追加すべきファイル_GCC(MinGW)用というファイルの中にある”8_1_0_i686_w64_posix_dwarf_rt_v6_rev0”だけを抜き取ってCドライブ直下に入れているので、
DXライブラリのフォルダ自体はDドライブのダウンロードファイルの中にあります
スクリーンショット 2021-04-30 211753.png
スクリーンショット 2021-04-30 211753.png (38.92 KiB) 閲覧数: 3197 回

返信

“C言語何でも質問掲示板” へ戻る