6

我正在尝试编译原始 doom 的源代码作为学习 C 的一种方式。我从github下载了它并修复了 i_video.c 第 49 行(errnos.h -> errno.h)中的一个明显错误。

我现在明白了:

m_misc.c:257:5: warning: initialization from incompatible pointer type [enabled by default]
m_misc.c:257:5: warning: (near initialization for ‘defaults[14].location’) [enabled by default]
m_misc.c:257:5: error: initializer element is not computable at load time
m_misc.c:257:5: error: (near initialization for ‘defaults[14].defaultvalue’)
m_misc.c:264:35: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:264:5: error: initializer element is not constant
m_misc.c:264:5: error: (near initialization for ‘defaults[16].defaultvalue’)
m_misc.c:265:37: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:265:5: error: initializer element is not constant
m_misc.c:265:5: error: (near initialization for ‘defaults[17].defaultvalue’)
m_misc.c:288:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:288:5: error: initializer element is not constant
m_misc.c:288:5: error: (near initialization for ‘defaults[31].defaultvalue’)
m_misc.c:289:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:289:5: error: initializer element is not constant
m_misc.c:289:5: error: (near initialization for ‘defaults[32].defaultvalue’)
m_misc.c:290:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:290:5: error: initializer element is not constant
m_misc.c:290:5: error: (near initialization for ‘defaults[33].defaultvalue’)
m_misc.c:291:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:291:5: error: initializer element is not constant
m_misc.c:291:5: error: (near initialization for ‘defaults[34].defaultvalue’)
m_misc.c:292:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:292:5: error: initializer element is not constant
m_misc.c:292:5: error: (near initialization for ‘defaults[35].defaultvalue’)
m_misc.c:293:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:293:5: error: initializer element is not constant
m_misc.c:293:5: error: (near initialization for ‘defaults[36].defaultvalue’)
m_misc.c:294:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:294:5: error: initializer element is not constant
m_misc.c:294:5: error: (near initialization for ‘defaults[37].defaultvalue’)
m_misc.c:295:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:295:5: error: initializer element is not constant
m_misc.c:295:5: error: (near initialization for ‘defaults[38].defaultvalue’)
m_misc.c:296:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:296:5: error: initializer element is not constant
m_misc.c:296:5: error: (near initialization for ‘defaults[39].defaultvalue’)
m_misc.c:297:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
m_misc.c:297:5: error: initializer element is not constant
m_misc.c:297:5: error: (near initialization for ‘defaults[40].defaultvalue’)
m_misc.c: In function ‘M_LoadDefaults’:
m_misc.c:395:5: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
make: *** [linux/m_misc.o] Error 1

在此声明期间的 m_misc.c 文件中包含强制转换的行:

default_t   defaults[] =
{
    {"mouse_sensitivity",&mouseSensitivity, 5},
    {"sfx_volume",&snd_SfxVolume, 8},
    {"music_volume",&snd_MusicVolume, 8},
    {"show_messages",&showMessages, 1},


#ifdef NORMALUNIX
    {"key_right",&key_right, KEY_RIGHTARROW},
    {"key_left",&key_left, KEY_LEFTARROW},
    {"key_up",&key_up, KEY_UPARROW},
    {"key_down",&key_down, KEY_DOWNARROW},
    {"key_strafeleft",&key_strafeleft, ','},
    {"key_straferight",&key_straferight, '.'},

    {"key_fire",&key_fire, KEY_RCTRL},
    {"key_use",&key_use, ' '},
    {"key_strafe",&key_strafe, KEY_RALT},
    {"key_speed",&key_speed, KEY_RSHIFT},

// UNIX hack, to be removed. 
#ifdef SNDSERV
    {"sndserver", (int *) &sndserver_filename, (int) "sndserver"},
    {"mb_used", &mb_used, 2},
#endif

#endif

#ifdef LINUX
    {"mousedev", (int*)&mousedev, (int)"/dev/ttyS0"},
    {"mousetype", (int*)&mousetype, (int)"microsoft"},
#endif

    {"use_mouse",&usemouse, 1}, 
    {"mouseb_fire",&mousebfire,0},
    {"mouseb_strafe",&mousebstrafe,1},
    {"mouseb_forward",&mousebforward,2},

    {"use_joystick",&usejoystick, 0}, 
    {"joyb_fire",&joybfire,0},
    {"joyb_strafe",&joybstrafe,1},
    {"joyb_use",&joybuse,3},
    {"joyb_speed",&joybspeed,2},

    {"screenblocks",&screenblocks, 9}, 
    {"detaillevel",&detailLevel, 0}, 

    {"snd_channels",&numChannels, 3}, 



    {"usegamma",&usegamma, 0},
    {"chatmacro0", (int *) &chat_macros[0], (int) HUSTR_CHATMACRO0 },
    {"chatmacro1", (int *) &chat_macros[1], (int) HUSTR_CHATMACRO1 },
    {"chatmacro2", (int *) &chat_macros[2], (int) HUSTR_CHATMACRO2 },
    {"chatmacro3", (int *) &chat_macros[3], (int) HUSTR_CHATMACRO3 },
    {"chatmacro4", (int *) &chat_macros[4], (int) HUSTR_CHATMACRO4 },
    {"chatmacro5", (int *) &chat_macros[5], (int) HUSTR_CHATMACRO5 },
    {"chatmacro6", (int *) &chat_macros[6], (int) HUSTR_CHATMACRO6 },
    {"chatmacro7", (int *) &chat_macros[7], (int) HUSTR_CHATMACRO7 },
    {"chatmacro8", (int *) &chat_macros[8], (int) HUSTR_CHATMACRO8 },
    {"chatmacro9", (int *) &chat_macros[9], (int) HUSTR_CHATMACRO9 }

};

这与现代编译器不兼容吗?有没有人设法通过它?

4

2 回答 2

6

如果您使用的是 64 位编译器,请尝试使用该-m32标志并链接到-L/usr/lib/i386-linux-gnu/32 位库。

顺便说一句,如果你要编译这个源代码,你仍然会遇到运行问题,因为这个构建需要 320x200 的屏幕分辨率。否则它不会运行。

我正在开发 DOOM 的 SDL 端口,所以你可以试试我在GitHub 上的源代码。

您需要安装 SDL 库才能运行它。此外,那里没有声音。

于 2013-02-27T15:37:43.350 回答
2

至于初始化列表错误,它就在那里——初始化列表中的元素不是常量表达式。看看这个:

{"mousedev", (int*)&mousedev, (int)"/dev/ttyS0"},

我猜mousedev是另一个变量。你有它。

我现在不记得了,但我认为初始化列表中的非常量是在后来的 C 标准之一中引入的。尝试使编译器坚持使用不同的编译器 - 我会尝试使用 C99。 http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options

Alex 正确回答了关于整数与指针大小的问题。

于 2013-02-27T15:41:09.763 回答