包括指令弄乱程序
include directive messing up with the program
我遇到了一个情况,我无法编译程序,因为我拆分了文件,因为我认为它太大了。一旦文件全部合并为一个,它就可以完美运行。现在我拆分了它们,编译器给了我以下错误:
||=== Snake_Game, Debug ===|
D:ProjectsSnake_GameGraph_Funcs.c||In function 'snake_crashed':|
D:ProjectsSnake_GameGraph_Funcs.c|24|warning: 'textprintf_centre' is deprecated (declared at c:program files (x86)codeblocksmingwbin../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:ProjectsSnake_GameGraph_Funcs.c||In function 'read_string':|
D:ProjectsSnake_GameGraph_Funcs.c|91|warning: 'textout' is deprecated (declared at c:program files (x86)codeblocksmingwbin../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:157)|
D:ProjectsSnake_GameHighscore.c||In function 'set_hscore':|
D:ProjectsSnake_GameHighscore.c|30|warning: implicit declaration of function 'sort_scores'|
D:ProjectsSnake_GameMenus.c||In function 'option_menu':|
D:ProjectsSnake_GameMenus.c|114|warning: 'textprintf_centre' is deprecated (declared at c:program files (x86)codeblocksmingwbin../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:ProjectsSnake_GameMenus.c|115|warning: 'textprintf_centre' is deprecated (declared at c:program files (x86)codeblocksmingwbin../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:ProjectsSnake_GameMenus.c|116|warning: 'textprintf_centre' is deprecated (declared at c:program files (x86)codeblocksmingwbin../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:ProjectsSnake_GameMenus.c|117|warning: 'textprintf_centre' is deprecated (declared at c:program files (x86)codeblocksmingwbin../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:ProjectsSnake_GameMenus.c|118|warning: 'textprintf_centre' is deprecated (declared at c:program files (x86)codeblocksmingwbin../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:ProjectsSnake_GameGamePlay.c||In function 'game_play':|
D:ProjectsSnake_GameGamePlay.c|59|warning: 'textprintf_centre' is deprecated (declared at c:program files (x86)codeblocksmingwbin../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
objDebugHighscore.o||In function `check_hscore':|
D:ProjectsSnake_GameHighscore.c|13|multiple definition of `img_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugHighscore.o||In function `check_hscore':|
D:ProjectsSnake_GameHighscore.c|14|multiple definition of `snd_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugHighscore.o||In function `check_hscore':|
D:ProjectsSnake_GameHighscore.c|14|multiple definition of `fnt_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|33|first defined here|
objDebugInit_Stuff.o||In function `init_allegro':|
D:ProjectsSnake_GameInit_Stuff.c|14|multiple definition of `img_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugInit_Stuff.o||In function `init_allegro':|
D:ProjectsSnake_GameInit_Stuff.c|14|multiple definition of `snd_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugInit_Stuff.o||In function `init_allegro':|
D:ProjectsSnake_GameInit_Stuff.c|15|multiple definition of `fnt_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|33|first defined here|
objDebugMenus.o||In function `main_menu':|
D:ProjectsSnake_GameMenus.c|13|multiple definition of `img_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugMenus.o||In function `main_menu':|
D:ProjectsSnake_GameMenus.c|13|multiple definition of `snd_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugMenus.o||In function `main_menu':|
D:ProjectsSnake_GameMenus.c|14|multiple definition of `fnt_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|33|first defined here|
objDebugmain.o||In function `mangled_main':|
D:ProjectsSnake_Gamemain.c|12|multiple definition of `img_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugmain.o||In function `mangled_main':|
D:ProjectsSnake_Gamemain.c|12|multiple definition of `snd_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugmain.o||In function `mangled_main':|
D:ProjectsSnake_Gamemain.c|13|multiple definition of `fnt_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|33|first defined here|
objDebugAlgorithms.o||In function `qsort_helper_by_score':|
D:ProjectsSnake_GameAlgorithms.c|13|multiple definition of `img_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugAlgorithms.o||In function `qsort_helper_by_score':|
D:ProjectsSnake_GameAlgorithms.c|14|multiple definition of `snd_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugAlgorithms.o||In function `qsort_helper_by_score':|
D:ProjectsSnake_GameAlgorithms.c|14|multiple definition of `fnt_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|33|first defined here|
objDebugGamePlay.o||In function `game_play':|
D:ProjectsSnake_GameGamePlay.c|13|multiple definition of `img_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugGamePlay.o||In function `game_play':|
D:ProjectsSnake_GameGamePlay.c|13|multiple definition of `snd_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|32|first defined here|
objDebugGamePlay.o||In function `game_play':|
D:ProjectsSnake_GameGamePlay.c|13|multiple definition of `fnt_datafile'|
objDebugGraph_Funcs.o:c:program files (x86)codeblocksmingwbin..libgccmingw324.4.1........includeallegroalcompat.h|33|first defined here|
ld.exe||cannot find -lalleg|
||=== Build finished: 37 errors, 9 warnings (0 minutes, 1 seconds) ===|
这让我发疯。当我拆分它们时,我无法让它们工作。我发现这是一件更有条理的事情,我真的很想这样做。
我正在处理文件,所以你们可以检查一下。
Header main.h(项目中唯一的标头。虽然每个 .c 文件都有不止一个):
/**
Snake-Game:
A remake of the mobile game from nokia(don't know what model)
Made by Patrick Farias Bassut Souza <patrickbassut@hotmail.com
File: main.h
**/
#ifndef MAIN_H
#define MAIN_H
#include <stdio.h>
#include <stdlib.h>
#include <allegro.h>
#include <string.h>
#include <time.h>
#include "Images.h"
#include "Fonts.h"
#include "Sounds.h"
#define WINDOW_TITLE "Snake Game by Patrick Bassut"
#define VIDEO_CARD GFX_AUTODETECT_WINDOWED
#define MAX_X 800
#define MAX_Y 600
#define V_MAX_X 0
#define V_MAX_Y 0
#define COLOR_BITS 32
#define DIGI_CARD DIGI_AUTODETECT
#define MIDI_CARD MIDI_AUTODETECT
#define WHITE makecol(255, 255, 255)
#define BLACK makecol(0, 0, 0)
#define PINK makecol(255, 0, 255)
#define RED makecol(255, 0, 0)
#define BLUE makecol(0, 0, 255)
#define NORTH 0
#define EAST 1
#define SOUTH 2
#define WEST 3
#define LEFT_BORDER 18
#define RIGHT_BORDER 766
#define TOP_BORDER -13
#define BOTTOM_BORDER 577
#define WALL_COLLISION 0
#define ITSELF_COLLISION 1
#define FOOD_COLLISION 2
#define INIT_SPEED 200
#define START_TAILS 2
typedef enum{false, true}bool;
typedef struct _POS{
int x;
int y;
}Pos;
typedef struct _config{
int resolutionx;
int resolutiony;
bool window_mode;
bool changed;
bool music;
bool sound;
int volume;
}tConfig;
typedef struct _snake{
Pos pos;
int prev_snake_pos_x[400]; // Váriavel usada para 'guardar' os rastros X da snake.
int prev_snake_pos_y[400]; // Váriavel usada para 'guardar' os rastros Y da snake.
int tails_number;
int direction;
int speed;
}tSnake;
typedef struct _game{
tConfig cur_cfg;
Pos possible_food[24];
Pos food;
int food_type;
int points;
float speed_food_time;
Pos spr;
bool is_paused;
bool is_playing;
}tGame;
typedef struct _Score
{
int player_score;
char player_name[11];
}Score;
tSnake player;
tGame game;
DATAFILE *imggg_datafile = NULL;
DATAFILE *snd_datafile = NULL;
DATAFILE *fnt_datafile = NULL;
Score score_table[11];
int qsort_helper_by_score(const void *e1, const void *e2);
bool check_collision(int collision_type);
BITMAP *new_food();
inline void close_game();
void game_play();
void snake_crashed(int points);
void game_introduction();
void read_string(char *str_to, int x, int y, int size);
void fadein(BITMAP *bmp_orig, int speed, int until);
void fadeout(int speed, int until);
inline bool check_hscore(int points);
bool load_scores();
bool save_scores();
void show_hscore_list(char *name);
void set_hscore();
bool init_allegro();
bool init_game();
bool init_settings();
int main_menu();
void option_menu();
void apply_settings(tConfig new_config);
#endif
看起来文件includeallegroalcompat.h
多次定义相同的符号(fnt_datafile
,snd_datafile
),无论您将其包含在何处。
如果这些是全局变量,则应在标头中extern
声明它们,并在单个实现文件中定义。
如果它们是方法,则应将其声明为inline
。
当只有一个文件时,它可以工作,因为这意味着只有一个翻译单元导出这些符号。
尝试在头文件的开头添加保护,如 #pragma once
,这样在编译过程中就不会多次#included
。
或者,您可以指定
#ifndef _SNAKE_GAME.H // or any label you want
#define _SNAKE_GAME.H
//All other code of header file goes here
#endif
每个文件可能没有包含它们需要的所有内容使用一个大文件,所有内容都可以看到所有内容。
您可能需要在每个吐出的文件中添加缺少的包含。
相关文章:
- 我一直试图弄清楚我在这个链表程序中做错了什么
- 正在从程序内存中分解x指令
- VS-2019程序在某些服务器上的第一条浮点指令上崩溃
- 我的程序不断抛出编译错误,我无法弄清楚为什么会发生错误
- 无法弄清楚如何让 CMake 为自定义 clang 驱动程序拉入正确的标头
- 如何在导致应用程序崩溃的代码中修复指令
- 将内联程序集与序列化指令一起使用
- 我无法弄清楚我的程序的问题,即使我已经查看了错误日志消息
- _mm_fmadd_pd程序收到信号SIGILL,非法指令
- 为新的指令集扩展程序进行了优化的代码的向后兼容性
- 弄清楚如何修复二十一点程序的问题C++
- 无法弄清楚如何为用户提供启动,停止和重新启动程序的所有选项?
- PIN从指令地址获取程序集操作码
- 程序收到信号Sigill非法指令
- 我需要帮助弄清楚为什么此C 程序不会使用GNU CC编译器在代码块中构建和运行
- 为什么Folloing代码在2010年Visual Studio(X64应用程序)中抛出非法指令例外
- Flex/Yacc程序在VC++中的自由指令上引起断点
- 为什么sleep in函数忽略了程序中的几个顺序指令
- 编写程序以将指令输出到 Windows 命令行
- 包括指令弄乱程序