Problem Solving Process of The terminal process terminated with exit code 1

參考前輩的配置VScode C/C++環境的經驗:

成成賜我力量
bat67

參考之後我的配置

c_cpp_properties.json

    "configurations": [
        {
            "name": "Mac",
            "includePath": ["/usr/include"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        },
        {
            "name": "Linux",
            "includePath": ["/usr/include"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        },
        {
            "name": "Win32",
            "includePath": ["D:/MinGW/include"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        }
    ],
    "version": 4

launch.json

{
            "name": "(gdb) Launch", 
            "type": "cppdbg", 
            "request": "launch",
            "targetArchitecture": "x86",
            "program": "${workspaceRoot}/${fileBacenameNoExtention}.exe", 
            "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe", // 注意這裏要與本機MinGw的路徑對應
            "args": [], 
            "stopAtEntry": false, 
            "cwd": "${workspaceRoot}",
            "externalConsole": true, 
            "MIMode": "gdb",
            "preLaunchTask": "gcc",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",  
                    "text": "-enable-pretty-printing",  
                    "ignoreFailures": true
                }
            ]
 }

task.json

{
        "label": "gcc",
        "command": "gcc",
        "args": ["-g","${file}","-o","${fileBacenameNoExTention}.exe"], 
        "problemMatcher": {
          "owner": "c",
          "fileLocation": ["relative", "${workspaceRoot}"],
          "pattern": {
              "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
              "file": 1,
              "line": 2,
              "column": 3,
              "severity": 4,
              "message": 5
          }
        }
 }

出現的問題

d:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1

也看到Stack Overflow上有類似問題

分析問題

因爲看不懂報錯信息,只能暴力檢索。
Keyword:

The terminal process terminated with exit code: 1
or
undefined reference to `WinMain@16’

Result: 有個前輩說他環境變量配置不正確
and
Something probably useful from it

Project -> properties -> build targets -> Type set it to native or gui…
If it doesn’t work (I’m not a windows user anymore) search the forum for sollutions…

I made it working. It was because there was not created main script, so the main function was missing.

解決辦法

我檢查了一下自己配置的環境變量,的確有問題。

在這裏插入圖片描述
That 's all and I must be careful next time…

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章