我遇到了一种情况,因为我把文件拆分了,因为我觉得它太大了,所以无法编译程序。 一旦文件全部合并为一个,它就完美无缺。现在我拆分了它们,编译器给了我以下错误:
||=== Snake_Game, Debug ===|
D:\Projects\Snake_Game\Graph_Funcs.c||In function 'snake_crashed':|
D:\Projects\Snake_Game\Graph_Funcs.c|24|warning: 'textprintf_centre' is deprecated (declared at c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:\Projects\Snake_Game\Graph_Funcs.c||In function 'read_string':|
D:\Projects\Snake_Game\Graph_Funcs.c|91|warning: 'textout' is deprecated (declared at c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:157)|
D:\Projects\Snake_Game\Highscore.c||In function 'set_hscore':|
D:\Projects\Snake_Game\Highscore.c|30|warning: implicit declaration of function 'sort_scores'|
D:\Projects\Snake_Game\Menus.c||In function 'option_menu':|
D:\Projects\Snake_Game\Menus.c|114|warning: 'textprintf_centre' is deprecated (declared at c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:\Projects\Snake_Game\Menus.c|115|warning: 'textprintf_centre' is deprecated (declared at c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:\Projects\Snake_Game\Menus.c|116|warning: 'textprintf_centre' is deprecated (declared at c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:\Projects\Snake_Game\Menus.c|117|warning: 'textprintf_centre' is deprecated (declared at c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:\Projects\Snake_Game\Menus.c|118|warning: 'textprintf_centre' is deprecated (declared at c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
D:\Projects\Snake_Game\GamePlay.c||In function 'game_play':|
D:\Projects\Snake_Game\GamePlay.c|59|warning: 'textprintf_centre' is deprecated (declared at c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/allegro/alcompat.h:178)|
obj\Debug\Highscore.o||In function `check_hscore':|
D:\Projects\Snake_Game\Highscore.c|13|multiple definition of `img_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\Highscore.o||In function `check_hscore':|
D:\Projects\Snake_Game\Highscore.c|14|multiple definition of `snd_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\Highscore.o||In function `check_hscore':|
D:\Projects\Snake_Game\Highscore.c|14|multiple definition of `fnt_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|33|first defined here|
obj\Debug\Init_Stuff.o||In function `init_allegro':|
D:\Projects\Snake_Game\Init_Stuff.c|14|multiple definition of `img_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\Init_Stuff.o||In function `init_allegro':|
D:\Projects\Snake_Game\Init_Stuff.c|14|multiple definition of `snd_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\Init_Stuff.o||In function `init_allegro':|
D:\Projects\Snake_Game\Init_Stuff.c|15|multiple definition of `fnt_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|33|first defined here|
obj\Debug\Menus.o||In function `main_menu':|
D:\Projects\Snake_Game\Menus.c|13|multiple definition of `img_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\Menus.o||In function `main_menu':|
D:\Projects\Snake_Game\Menus.c|13|multiple definition of `snd_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\Menus.o||In function `main_menu':|
D:\Projects\Snake_Game\Menus.c|14|multiple definition of `fnt_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|33|first defined here|
obj\Debug\main.o||In function `mangled_main':|
D:\Projects\Snake_Game\main.c|12|multiple definition of `img_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\main.o||In function `mangled_main':|
D:\Projects\Snake_Game\main.c|12|multiple definition of `snd_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\main.o||In function `mangled_main':|
D:\Projects\Snake_Game\main.c|13|multiple definition of `fnt_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|33|first defined here|
obj\Debug\Algorithms.o||In function `qsort_helper_by_score':|
D:\Projects\Snake_Game\Algorithms.c|13|multiple definition of `img_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\Algorithms.o||In function `qsort_helper_by_score':|
D:\Projects\Snake_Game\Algorithms.c|14|multiple definition of `snd_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\Algorithms.o||In function `qsort_helper_by_score':|
D:\Projects\Snake_Game\Algorithms.c|14|multiple definition of `fnt_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|33|first defined here|
obj\Debug\GamePlay.o||In function `game_play':|
D:\Projects\Snake_Game\GamePlay.c|13|multiple definition of `img_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\GamePlay.o||In function `game_play':|
D:\Projects\Snake_Game\GamePlay.c|13|multiple definition of `snd_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|32|first defined here|
obj\Debug\GamePlay.o||In function `game_play':|
D:\Projects\Snake_Game\GamePlay.c|13|multiple definition of `fnt_datafile'|
obj\Debug\Graph_Funcs.o:c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\allegro\alcompat.h|33|first defined here|
ld.exe||cannot find -lalleg|
||=== Build finished: 37 errors, 9 warnings (0 minutes, 1 seconds) ===|
这让我发疯了。当我拆分它时,我无法使这些工作。 而且我觉得它更有条理,我真的想做。
我要处理这些文件,所以你们可以查看是否需要。
标题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
答案 0 :(得分:1)
文件include\allegro\alcompat.h
似乎多次定义相同的符号(fnt_datafile
,snd_datafile
),无论您将其包含在何处。
如果这些都是全局变量,则应在标题中声明extern
并在单个实现文件中定义。
如果它们是方法,则应将其声明为inline
。
当只有一个文件时它起作用,因为这意味着只有一个翻译单元导出这些符号。
答案 1 :(得分:0)
尝试在头文件的开头添加保护,例如#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
答案 2 :(得分:-1)
每个文件可能都不包含他们需要的所有内容 有了一个大文件,所有内容都会看到所有包含。
您可能需要在每个spitted文件中添加缺少的包含。