У меня есть следующие декларации
FILE *fptr;
FILE *optr;
в algo.h у меня есть главный файл main.c, который открывает эти файлы. Я получаю указанную выше ошибку, если помещаю объявления в файл заголовка. Если я помещу его в main.c, я получаю несколько ошибок определения, например
srcmain.o:main.c:(.bss+0xc88): multiple definition of rcount'
condi'
srcnew_algo.o:new_algo.c:(.bss+0xc88): first defined here
srcmain.o:main.c:(.bss+0xc8c): multiple definition of
srcnew_algo.o:new_algo.c:(.bss+0xc8c): first defined here
4 ответы
Похоже, вы (1) не включили <stdio.h>
где вы используете FILE
, и / или (2) имеют некоторые не-static
исполняемый код или не-extern
определения переменных в ваших заголовках (и / или #include
файл C).
Первый обычно вызывает FILE
не быть определенным (или быть typedef
‘d к типу, который в некоторых случаях не существует). Во втором случае в каждой единице перевода, включающей файл, будет определен материал, что сбивает компоновщик с толку.
Чтобы исправить: (1) #include <stdio.h>
в файле, где FILE
используется, и (2) переместить общие определения из заголовков в файл .c (и / или объявить их как static
or extern
по мере необходимости), и только когда-либо #include
.h файлы.
ответ дан 07 апр.
То, что у вас есть в algo.h, — это определение не декларация. Если у тебя есть ФАЙЛ * fptr; ФАЙЛ * optr; и в исходном, и в заголовочном файле вы объявляете переменные дважды.
Вам потребуется:
алго.ч
extern FILE *fptr;
extern FILE *optr;
алго.с
FILE *fptr;
FILE *optr;
ответ дан 07 апр.
Похоже, вы не включаете stdio. Добавлять
#include <stdio.h>
в вашем заголовочном файле над этими объявлениями.
Ошибки компоновщика не имеют ничего общего с FILE
опубликованные вами переменные.
В вашем источнике есть две переменные с именем rcount
и condi
, который, согласно компоновщику, определен в обоих ваших исходных файлах. Причина, я полагаю, в том, что вы определяете эти переменные в файле заголовка, который включен в оба исходных файла. Некоторые старые компиляторы до сих пор не справляются с этим.
Создан 22 ноя.
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками
c
file-io
header-files
or задайте свой вопрос.
Hello,
I am very very very new to Unix, but experienced in C. I wasn’t sure whether this Message fits the Unix forum (if there’s one), or C. But, since it is a compiling Error, I felt it fits here best.
I did a «make», compilation, to a program called ioquake3. I get these errors. I tried to google them. It seems that these errors are caused by double inclusions, or something of the sort.
I tried endlessly to see how to make the write edits to the code. But, I couldn’t fix it.
Thank you in advance.
Code:
#include <stdio.h> #include "../qcommon/q_shared.h" #include "../qcommon/qcommon.h" #ifdef WIN32 #define DEFAULT_CURL_LIB "libcurl-3.dll" #elif defined(MACOS_X) #define DEFAULT_CURL_LIB "libcurl.dylib" #else #define DEFAULT_CURL_LIB "libcurl.so.4" #define ALTERNATE_CURL_LIB "libcurl.so.3" #endif #ifdef USE_LOCAL_HEADERS //#include <../libcurl/curl/curl.h> #else //#include <../libcurl/curl/curl.h> #endif #ifdef USE_CURL_DLOPEN extern char* (*qcurl_version)(void); extern cvar_t *cl_cURLLib; extern CURL* (*qcurl_easy_init)(void); extern CURLcode (*qcurl_easy_setopt)(CURL *curl, CURLoption option, ...); extern CURLcode (*qcurl_easy_perform)(CURL *curl); extern void (*qcurl_easy_cleanup)(CURL *curl); extern CURLcode (*qcurl_easy_getinfo)(CURL *curl, CURLINFO info, ...); extern void (*qcurl_easy_reset)(CURL *curl); extern const char *(*qcurl_easy_strerror)(CURLcode); extern CURLM* (*qcurl_multi_init)(void); extern CURLMcode (*qcurl_multi_add_handle)(CURLM *multi_handle, CURL *curl_handle); extern CURLMcode (*qcurl_multi_remove_handle)(CURLM *multi_handle, CURL *curl_handle); extern CURLMcode (*qcurl_multi_fdset)(CURLM *multi_handle, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *exc_fd_set, int *max_fd); extern CURLMcode (*qcurl_multi_perform)(CURLM *multi_handle, int *running_handles); extern CURLMcode (*qcurl_multi_cleanup)(CURLM *multi_handle); extern CURLMsg *(*qcurl_multi_info_read)(CURLM *multi_handle, int *msgs_in_queue); extern const char *(*qcurl_multi_strerror)(CURLMcode); #else #define qcurl_version curl_version #define qcurl_easy_init curl_easy_init #define qcurl_easy_setopt curl_easy_setopt #define qcurl_easy_perform curl_easy_perform #define qcurl_easy_cleanup curl_easy_cleanup #define qcurl_easy_getinfo curl_easy_getinfo #define qcurl_easy_duphandle curl_easy_duphandle #define qcurl_easy_reset curl_easy_reset #define qcurl_easy_strerror curl_easy_strerror #define qcurl_multi_init curl_multi_init #define qcurl_multi_add_handle curl_multi_add_handle #define qcurl_multi_remove_handle curl_multi_remove_handle #define qcurl_multi_fdset curl_multi_fdset #define qcurl_multi_perform curl_multi_perform #define qcurl_multi_cleanup curl_multi_cleanup #define qcurl_multi_info_read curl_multi_info_read #define qcurl_multi_strerror curl_multi_strerror #endif qboolean CL_cURL_Init( void ); void CL_cURL_Shutdown( void ); void CL_cURL_BeginDownload( const char *localName, const char *remoteURL ); void CL_cURL_PerformDownload( void ); void CL_cURL_Cleanup( void );</stdio.h>
Errors:
make[2]: `build/release-linux-x86_64/ioq3ded.x86_64' is up to date. CC code/client/cl_cgame.c In file included from code/client/cl_cgame.c:24: code/client/client.h:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token code/client/client.h:41: error: expected declaration specifiers or '...' before '*' token code/client/client.h:41: error: expected ')' before '*' token code/client/client.h:42: error: expected declaration specifiers or '...' before '*' token code/client/client.h:42: error: expected ')' before '*' token code/client/client.h:43: error: expected ')' before '*' token code/client/client.h:44: error: expected declaration specifiers or '...' before '*' token code/client/client.h:44: error: expected ')' before '*' token code/client/client.h:45: error: expected ')' before '*' token code/client/client.h:46: warning: parameter names (without types) in function declaration code/client/client.h:48: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token code/client/client.h:49: error: expected declaration specifiers or '...' before '*' token code/client/client.h:49: error: expected ')' before '*' token code/client/client.h:51: error: expected declaration specifiers or '...' before '*' token code/client/client.h:51: error: expected ')' before '*' token code/client/client.h:53: error: expected declaration specifiers or '...' before '*' token code/client/client.h:53: error: expected ')' before '*' token code/client/client.h:58: error: expected declaration specifiers or '...' before '*' token code/client/client.h:58: error: expected ')' before '*' token code/client/client.h:60: error: expected declaration specifiers or '...' before '*' token code/client/client.h:60: error: expected ')' before '*' token code/client/client.h:61: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token code/client/client.h:63: warning: parameter names (without types) in function declaration In file included from code/client/cl_cgame.c:24: code/client/client.h:264: error: expected specifier-qualifier-list before 'CURL' code/client/cl_cgame.c: In function 'CL_GetServerCommand': code/client/cl_cgame.c:276: error: 'clientConnection_t' has no member named 'demoplaying' code/client/cl_cgame.c: In function 'CL_InitCGame': code/client/cl_cgame.c:751: error: 'clientConnection_t' has no member named 'demoplaying' code/client/cl_cgame.c: In function 'CL_CGameRendering': code/client/cl_cgame.c:799: error: 'clientConnection_t' has no member named 'demoplaying' code/client/cl_cgame.c: In function 'CL_AdjustTimeDelta': code/client/cl_cgame.c:834: error: 'clientConnection_t' has no member named 'demoplaying' code/client/cl_cgame.c: In function 'CL_FirstSnapshot': code/client/cl_cgame.c:900: error: 'clientConnection_t' has no member named 'timeDemoBaseTime' code/client/cl_cgame.c:919: error: 'clientConnection_t' has no member named 'speexInitialized' code/client/cl_cgame.c:921: error: 'clientConnection_t' has no member named 'speexEncoderBits' code/client/cl_cgame.c:922: error: 'clientConnection_t' has no member named 'speexEncoderBits' code/client/cl_cgame.c:924: error: 'clientConnection_t' has no member named 'speexEncoder' code/client/cl_cgame.c:926: error: 'clientConnection_t' has no member named 'speexEncoder' code/client/cl_cgame.c:927: error: 'clientConnection_t' has no member named 'speexFrameSize' code/client/cl_cgame.c:928: error: 'clientConnection_t' has no member named 'speexEncoder' code/client/cl_cgame.c:929: error: 'clientConnection_t' has no member named 'speexSampleRate' code/client/cl_cgame.c:931: error: 'clientConnection_t' has no member named 'speexPreprocessor' code/client/cl_cgame.c:931: error: 'clientConnection_t' has no member named 'speexFrameSize' code/client/cl_cgame.c:932: error: 'clientConnection_t' has no member named 'speexSampleRate' code/client/cl_cgame.c:935: error: 'clientConnection_t' has no member named 'speexPreprocessor' code/client/cl_cgame.c:939: error: 'clientConnection_t' has no member named 'speexPreprocessor' code/client/cl_cgame.c:943: error: 'clientConnection_t' has no member named 'speexDecoderBits' code/client/cl_cgame.c:944: error: 'clientConnection_t' has no member named 'speexDecoderBits' code/client/cl_cgame.c:945: error: 'clientConnection_t' has no member named 'speexDecoder' code/client/cl_cgame.c:946: error: 'clientConnection_t' has no member named 'voipIgnore' code/client/cl_cgame.c:947: error: 'clientConnection_t' has no member named 'voipGain' code/client/cl_cgame.c:949: error: 'clientConnection_t' has no member named 'speexInitialized' code/client/cl_cgame.c:950: error: 'clientConnection_t' has no member named 'voipMuteAll' code/client/cl_cgame.c:953: error: 'clientConnection_t' has no member named 'voipTarget1' code/client/cl_cgame.c:953: error: 'clientConnection_t' has no member named 'voipTarget2' code/client/cl_cgame.c:953: error: 'clientConnection_t' has no member named 'voipTarget3' code/client/cl_cgame.c: In function 'CL_SetCGameTime': code/client/cl_cgame.c:969: error: 'clientConnection_t' has no member named 'demoplaying' code/client/cl_cgame.c:972: error: 'clientConnection_t' has no member named 'firstDemoFrameSkipped' code/client/cl_cgame.c:973: error: 'clientConnection_t' has no member named 'firstDemoFrameSkipped' code/client/cl_cgame.c:1006: error: 'clientConnection_t' has no member named 'demoplaying' code/client/cl_cgame.c:1045: error: 'clientConnection_t' has no member named 'demoplaying' code/client/cl_cgame.c:1061: error: 'clientConnection_t' has no member named 'timeDemoStart' code/client/cl_cgame.c:1062: error: 'clientConnection_t' has no member named 'timeDemoStart' code/client/cl_cgame.c:1062: error: 'clientConnection_t' has no member named 'timeDemoLastFrame' code/client/cl_cgame.c:1063: error: 'clientConnection_t' has no member named 'timeDemoMinDuration' code/client/cl_cgame.c:1064: error: 'clientConnection_t' has no member named 'timeDemoMaxDuration' code/client/cl_cgame.c:1067: error: 'clientConnection_t' has no member named 'timeDemoLastFrame' code/client/cl_cgame.c:1068: error: 'clientConnection_t' has no member named 'timeDemoLastFrame' code/client/cl_cgame.c:1071: error: 'clientConnection_t' has no member named 'timeDemoFrames' code/client/cl_cgame.c:1073: error: 'clientConnection_t' has no member named 'timeDemoMaxDuration' code/client/cl_cgame.c:1074: error: 'clientConnection_t' has no member named 'timeDemoMaxDuration' code/client/cl_cgame.c:1076: error: 'clientConnection_t' has no member named 'timeDemoMinDuration' code/client/cl_cgame.c:1077: error: 'clientConnection_t' has no member named 'timeDemoMinDuration' code/client/cl_cgame.c:1083: error: 'clientConnection_t' has no member named 'timeDemoDurations' code/client/cl_cgame.c:1083: error: 'clientConnection_t' has no member named 'timeDemoFrames' code/client/cl_cgame.c:1087: error: 'clientConnection_t' has no member named 'timeDemoFrames' code/client/cl_cgame.c:1088: error: 'clientConnection_t' has no member named 'timeDemoBaseTime' code/client/cl_cgame.c:1088: error: 'clientConnection_t' has no member named 'timeDemoFrames' make[2]: *** [build/release-linux-x86_64/client/cl_cgame.o] Error 1 make[2]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/best_linux_20111012/ioquake3dev_clean' make[1]: *** [targets] Error 2 make[1]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/best_linux_20111012/ioquake3dev_clean' make: *** [release] Error 2
Language C
Linux
Произошла ошибка, когда я загрузил этот код в Arduino Atmega2560. Это файл библиотеки, который я создал для файлов .c в моей программе.
Ошибка:
herkulex.c:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
Слово «класс» выделяется при появлении ошибки, которая находится в файле (код показан ниже)
#ifndef herkulex_lib
#define herkulex_lib
#include <Arduino.h>
#include <Wire.h>
#include<inttypes.h>
class herkulex
{
public:
herkulex();
void hklx_Init(unsigned long ulBaudRate);
void hklx_SendPacket(DrsPacket stPacket);
unsigned char hklx_ucReceivePacket(DrsPacket *pstPacket);
void hklx_RemoveInvalidData(void);
//no private
};
#endif /* HERKULEX_H_ */
Могу ли я узнать, что не так с этим кодом? Спасибо!
2
Решение
Вы компилируете файл C, который содержит C ++. Компилятор C отклоняет синтаксис C ++.
Вместо этого скомпилируйте его как программу на C ++.
6
Другие решения
Разве нет space
здесь отсутствует 😕
#include<inttypes.h>
0