首页 > 解决方案 > Visual Studio 没有正确调试我的程序

问题描述

当我尝试运行简单程序以检查它是否正确编译和调试时,它已编译但在 Visual Studio 代码中它没有正确调试

当我在入口处停止调试并尝试执行步骤时,它没有显示变量并给出了这个错误......

Single stepping until exit from function main,
which has no line number information.
Single stepping until exit from function _fu0___ZSt4cout,
which has no line number information.
Hello

我的程序

#include <iostream>
#include <string>
#include <vector>

int main() {
    std::vector<std::string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
    for(std::string const& i : msg) {
        std::cout << i << std::endl;
    }
}

和我的launch.json 文件

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "cppdbg",
            "request": "launch",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb.exe",
            "program": "${workspaceFolder}/bin/main.exe",
            "preLaunchTask": "build"
        }
    ]
}

和我的makefile ...

CC      := g++
CFLAGS  := -std=c++17 -Wall -Wextra -ggdb

BIN     := bin
SRC     := src
INCLUDE := include
LIB     := lib

LIBRARIES   :=

ifeq ($(OS),Windows_NT)
EXECUTABLE  := main.exe
SOURCEDIRS  := $(SRC)
INCLUDEDIRS := $(INCLUDE)
LIBDIRS     := $(LIB)
else
EXECUTABLE  := main
SOURCEDIRS  := $(shell find $(SRC) -type d)
INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
LIBDIRS     := $(shell find $(LIB) -type d)
endif

CINCLUDES   := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
CLIBS       := $(patsubst %,-L%, $(LIBDIRS:%/=%))

SOURCES     := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
OBJECTS     := $(SOURCES:.cpp=.o)

all: $(BIN)/$(EXECUTABLE)

.PHONY: clean
clean:
    -$(RM) $(BIN)/$(EXECUTABLE)
    -$(RM) $(OBJECTS)


run: all
    ./$(BIN)/$(EXECUTABLE)

$(BIN)/$(EXECUTABLE): $(OBJECTS)
    $(CC) $(CFLAGS) $(CINCLUDES) $(CLIBS) $^ -o $@ $(LIBRARIES)

什么可能导致调试器的这种行为......

标签: c++visual-studio-codemingw

解决方案


推荐阅读