首页 > 解决方案 > 每当我有一个类构造函数和析构函数 c++ 时,我就无法运行用 mingw 制作的“a.exe”?

问题描述

我对 C++ 比较陌生,我刚刚完成了codecademy.com. 所以我决定下载 MinGW 和 VScode 开始做一些练习。一切都很顺利,直到我遇到无法修复的错误。

当我尝试运行我的可执行文件时出现此错误:

在此处输入图像描述

我正在输入这个cmd,没有使用 makefile:

D:\>g++ main.cpp app.cpp
D:\>a.exe

我在命令行中使用 mingw (g++) 来编译我的代码,这里是:

我的 main.cpp 文件:

    #include <iostream>
    #include "app.hpp"
    int main (int argc, char* argv[]) {

        App tomato(true);
        std::cout << tomato.get_sauce();
        tomato.~App();
        return 0;
    }

应用程序.hpp:

// Define prototype functions here:
#ifndef APP_HPP
#define APP_HPP

class App {

    public:

    bool sauce;

    App(bool set);
    ~App();

    void set_sauce (bool set);
    bool get_sauce ();
};

#endif

应用程序.cpp:

#include "app.hpp"
#include <iostream>

App::App (bool set) {
    sauce = set;
}

App::~App () {
    std::cout << "goodbye";
}

void App::set_sauce (bool set) {
    sauce = set;
}

bool App::get_sauce () {
    return sauce;
}

一切都编译得很好,但只要我运行可执行文件,我就会得到The procedure entry point __gxx_personality_v0 could not be located in the dynamic link library.

标签: c++classcmdmingwheader-files

解决方案


libstdc++-6.dll从文件夹复制 mingw到可执行文件的目录中。或者,您可以将路径添加libstdc++-6.dll到环境 PATH。


推荐阅读