【问题标题】:C++ and SDL: Why can't I compile this program?C++ 和 SDL:为什么我不能编译这个程序?
【发布时间】:2010-11-11 22:59:10
【问题描述】:

由于某种原因,我无法编译该程序,因为据说我缺少 SDL。它在调试模式下编译得很好,但不是发布。我正在使用 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;
};

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

【问题讨论】:

  • 在 Visual Studio 中,不同的配置(Debug、Release、不同的 CPU)有不同的设置。即使您为 Debug 添加了正确的目录和库,您也必须对 Release 进行相同的更改才能正确编译。
  • 您确定要在两种配置(调试和发布)中链接 SDL 库吗?

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    打开您的项目属性并验证您是否在调试和发布配置中链接到 SDL 库:属性对话框的左上角有一个组合框,您可以在其中选择要编辑的配置。

    【讨论】:

      猜你喜欢
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多