无法在Visual Studio 2010中构建Allegro C ++程序

问题描述 投票:0回答:1

我是allegro的初学者,我刚刚正确安装了allegro,这是我的代码(我的第一个代码):

#include<allegro5/allegro.h>
#include<allegro5\allegro_font.h>
#include<allegro5/allegro_native_dialog.h>
#include<allegro5\allegro_ttf.h>
#include<iostream>
int main()
{
    ALLEGRO_DISPLAY *display;
    if (!al_init())
    {
        al_show_native_message_box(display,
                                   NULL,
                                   NULL,
                                   "Could not initialize allegro 5",
                                   NULL,
                                   NULL);
    }
    display = al_create_display(800, 600);
    if (!display)
    {
        al_show_native_message_box(display,
                                   NULL,
                                   NULL,
                                   "Could not initialize allegro WINDOW ",
                                   NULL,
                                   NULL);
    }
    al_rest(5.0);
    al_destroy_display(display);
    return 0;
}

现在这是构建日志显示的内容:

1>------ Build started: Project: Allegro_intro, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\krish\desktop\projects\allegro_intro\allegro_intro\main.cpp(11): warning C4700: uninitialized local variable 'display' used
1>main.obj : error LNK2005: _main already defined in font.obj
1>C:\Users\krish\Desktop\Projects\Allegro_intro\Debug\Allegro_intro.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

然后有一个对话框显示“无法启动程序...系统找不到指定的文件”。请告诉我该怎么做

c++ c allegro allegro5
1个回答
1
投票

传递给第一次调用al_show_native_message_box时,显示是未初始化的,这将导致随机内存访问。如果需要在调用al_init和al_create_display之前调用al_show_native_message_box,则为display参数传递NULL。

始终初始化变量。 ;)

© www.soinside.com 2019 - 2024. All rights reserved.