簡體   English   中英

如何使用 vscode 在發布模式下編譯 c++

[英]how to compile c++ in release mode with vscode

所以我正在使用 c++ 和 sfml 制作游戲,我們都知道調試模式很慢所以我需要知道如何在發布模式下構建我的游戲這是我的 c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\MinGW\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "windows-gcc-x86"
        }
    ],
    "version": 4
}

這是我的 MakeFile:

all: compile link

compile:
    g++ -Isrc/include -c coding/main.cpp

link:
    g++ main.o -o main -Lsrc/lib -lsfml-graphics -lsfml-window -lsfml-system
@OUTSEET
Proceed your steps as per other's comments.
I thought of sharing my updated Makefile:
all:
    @if [[ ! -f main.o ]];\
    then\
        make main.o;\
    else\
        ls -tr main.o coding/main.cpp 2>&1 |\
        tail -1 |\
        grep "main.o" >/dev/null 2>&1;\
        if [[ 0 -eq $$? ]];\
        then\
            echo main.o is up to date;\
        else\
            if [[ -f main.o ]];\
            then\
                echo "Removing main.o due to updated coding/main.cpp";\
                echo rm main.o;\
                rm main.o;\
            fi;\
            make main.o;\
        fi;\
        if [[ ! -f main ]];\
        then\
            make main;\
        else\
            echo "main.exe is up to date";\
        fi;\
    fi
#BETTER TO USE -O3 DURING RELEASE.
main.o:
    @echo "g++ -Isrc/include -O3 -c coding/main.cpp -o main.o";\
    g++ -O3 -Isrc/include -c coding/main.cpp -o main.o;\
    if [[ ! -f main ]];\
    then\
        make main;\
    else\
        ls -tr main.o main.cpp main 2>&1 |\
        tail -1 |\
        grep "main$$" >/dev/null 2>&1;\
        if [[ 0 -eq $$? ]];\
        then\
            echo main is up to date;\
        else\
            if [[ -f main ]];\
            then\
                echo "Removing main.o due to updated cpp or obj files";\
                echo rm main;\
                rm main;\
            fi;\
            make main;\
        fi;\
    fi
main:
    @echo "g++ -O3 main.o -o main -Lsrc/lib -lsfml-graphics -lsfml-window -lsfml-system";\
    g++ -O3 main.o -o main -Lsrc/lib -lsfml-graphics -lsfml-window -lsfml-system
#I HAVE WRITTEN THIS MAKEFILE USING CYGWIN
#YOU CAN REPLACE main.exe TO main WHEN USING OTHER OPERATING SYSTEMS AT OTHER UNIVERSE :) => FOR MY FUN.
clean:
    @CLEANUPTODATE="y";\
    for cleanfiles in main.o \
    main.exe;\
    do\
        if [[ -f "$$cleanfiles" ]];\
        then\
            echo "rm $$cleanfiles";\
            rm "$$cleanfiles";\
            CLEANUPTODATE=$$?;\
        fi;\
    done;\
    if [[ "y" = "$$CLEANUPTODATE" ]];\
    then\
        echo "make clean is up to date";\
    fi
    Sample output from localhost:
        $ make
    make[1]: Entering directory '/home/murugesan.openssl/'
    g++ -Isrc/include -O3 -c coding/main.cpp -o main.o
    make[2]: Entering directory '/home/murugesan.openssl/'
    g++ -O3 main.o -o main -Lsrc/lib -lsfml-graphics -lsfml-window -lsfml-system
    make[2]: Leaving directory '/home/murugesan.openssl/'
    make[1]: Leaving directory '/home/murugesan.openssl/'
    $ make clean
    rm main.o
    rm main.exe
    $ make clean
    make clean is up to date
    $ make
    make[1]: Entering directory '/home/murugesan.openssl/'
    g++ -Isrc/include -O3 -c coding/main.cpp -o main.o
    make[2]: Entering directory '/home/murugesan.openssl/'
    g++ -O3 main.o -o main -Lsrc/lib -lsfml-graphics -lsfml-window -lsfml-system
    make[2]: Leaving directory '/home/murugesan.openssl/'
    make[1]: Leaving directory '/home/murugesan.openssl/'
    $ make
    main.o is up to date
    main.exe is up to date

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM