C++ 和 SDL : Why can't I compile this program?

标签 c++ visual-studio visual-c++ sdl

出于某种原因,我无法编译该程序,因为我可能缺少 SDL。它在 Debug 模式下编译良好,但在 Release 模式下编译不佳。我正在使用 Visual C++ 2010。我使用 VC++ 目录链接到 SDL。这是我的(小)代码。

//main.cpp
#include "main.h"

void logger::log(string logging)
{
    file << logging << "\n";
}

int main(int argc, char* argv[])
{
    logger logObj;
        logObj.log("uShootZombies started.");

    SDL_Init(SDL_INIT_EVERYTHING);
        logObj.log("SDL initalized.");

    SDL_Quit();
        logObj.log("SDL quit.");

    return 0;
}


//main.h
#include <SDL.h>
#include <fstream>
#include <string>

using namespace std;

class game
{
    public:
    private:
};

class logger
{
    public:
    void log(string logging);
    logger()
    {
        file.open("Log.txt", ios::out);
    }

    ~logger()
    {
        file.close();
    }
    private:
    ofstream file;
};

我做错了什么?如果您需要更多信息,请询问。 ;)

最佳答案

确保将库引用添加到 Release模式和 Debug模式。我不是 100% 确定 SDL,但一些第 3 方库带有 2 种风格,即调试和发布。我相信您必须使用库文件的 Release模式来设置 IDE 的 Release模式。

关于C++ 和 SDL : Why can't I compile this program?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4160113/

相关文章:

c++ - 崇高文字3中的gdb:调试器不会在断点处停止并立即退出

visual-studio - 用于自定义项目类型的 NuGet 包管理器

visual-studio-2010 - 通过宏/环境变量定义解决方案中的项目路径

c++ - 如何在 Googletest 中运行两个不同的测试

c++ - CreateCompatibleBitmap() 返回黑色 HBITMAP

c++ - 如何将 Boost::shared_ptr<T> 暴露给 Tcl + SWIG 接口(interface)文件?

c++ - 链接 QtCreator && OpenCv

html - 组织一个带有 Visual Studio 扩展名的巨大 .css 文件?

c++ - 在 MSVC++ 的 STL 中插入 std::unordered_map 两次调用散列函数,糟糕的设计还是特殊原因?

winapi - Win32 API - RegisterClassEx 错误