gcc:编译 expected declaration specifiers or ‘...’ before
2017-02-19 09:59
4199 查看
这种错误,一般是头文件include混乱造成的。
实例:
In file included from ftpp.h:6:0,
from ftpp.c:2:
parser.h:17:30: 错误:expected declaration specifiers or ‘...’ before ‘tFtpMsg’
parser.h:19:30: 错误:expected declaration specifiers or ‘...’ before ‘tFtpMsg’
parser.h:
================
#ifndef _PARSER_H_
#define _PARSER_H_
#include "ftpp.h" //这里等于包含来自己
ftpp.h:
================
#ifndef _FTPP_H
#define _FTPP_H
#include "sockwrapper.h"
#include "common.h"
#include "parser.h" //这里是错误包含,ftpp.h中用不到parser.h,如果ftpp.h中用到parser.h中定义到数据
//那么将parser.h中定义的部分放到ftpp.h中,
//然后将此条包含删除,避免循环包含!!!!!!!!!
#include <pthread.h>
parser.c:
================
#include "parser.h"
#include "sockwrapper.h"
#include <string.h>
++++++++++++++++++
有一个好习惯得养成,#include "" 最好写在#include<>的上面,这样写,可以避免很多问题。
实例:
In file included from ftpp.h:6:0,
from ftpp.c:2:
parser.h:17:30: 错误:expected declaration specifiers or ‘...’ before ‘tFtpMsg’
parser.h:19:30: 错误:expected declaration specifiers or ‘...’ before ‘tFtpMsg’
parser.h:
================
#ifndef _PARSER_H_
#define _PARSER_H_
#include "ftpp.h" //这里等于包含来自己
ftpp.h:
================
#ifndef _FTPP_H
#define _FTPP_H
#include "sockwrapper.h"
#include "common.h"
#include "parser.h" //这里是错误包含,ftpp.h中用不到parser.h,如果ftpp.h中用到parser.h中定义到数据
//那么将parser.h中定义的部分放到ftpp.h中,
//然后将此条包含删除,避免循环包含!!!!!!!!!
#include <pthread.h>
parser.c:
================
#include "parser.h"
#include "sockwrapper.h"
#include <string.h>
++++++++++++++++++
有一个好习惯得养成,#include "" 最好写在#include<>的上面,这样写,可以避免很多问题。
相关文章推荐
- 【错误】error: expected declaration specifiers or ‘...’ before string constant
- 在Ubuntu gcc下编译c程序,错误如下: test.c:3: error: expected ';', ',' or ')' before '&' token
- gcc编译,出现错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ........
- error expected declaration specifiers or ‘...’ before ‘SElemType’
- error: expected declaration specifiers or '...' before错误
- error: expected declaration specifiers or '...' before ***
- expected declaration specifiers or ‘...’ before
- XXX.h:143: error: expected declaration specifiers or ‘...’ before ‘YYY’
- expected declaration specifiers or '...' before string constant
- /home/zhang/code/hello/hello.c:3: error: expected declaration specifiers or ‘...’ before string cons
- 安装PHP时 jpeglib.h:954: error:expected declaration specifiers or ‘...’ before ‘FILE’ 错误解决
- error: expected declaration specifiers or ‘...’ before string constant
- 3:16: 错误: expected declaration specifiers or ‘...’ before string constant
- /sysroot/usr/include/search.h:19: error: expected declaration specifiers or '...' before '__free_fn_
- C语言错误 [Error] expected declaration specifiers or '...' before 'student'
- error: expected declaration specifiers or ‘...’ before ‘FILE’
- error: expected declaration specifiers before ‘return’
- 关于gcc编译错误expected expression before token的一些想法
- gcc 编译 expected unqualified-id before '(' token 问题
- gcc 编译错误 error:expected class-name before ';' token