OSX上的C Makefile冲突类型错误

问题描述 投票:0回答:1

我一直试图通过OSX Catalina上的makefile编译C代码,但会出错。 当我在Ubuntu上编译代码时成功,但是在OSX上,在编译结束时遇到以下错误:

gcc -c -ansi   -g scan-fct_pddl.tab.c
scan-fct_pddl.y:858:6: error: conflicting types for 'fcterr'
void fcterr( int errno, char *par ) {
     ^
scan-fct_pddl.y:174:3: note: previous implicit declaration is here
  fcterr( PROBNAME_EXPECTED, NULL ); 
  ^
1 error generated.
make: *** [scan-fct_pddl.tab.o] Error 1

我感到奇怪的是,仅在OSX上编译代码时才会引发此错误。我尝试了不同版本的gcc,还更新了bison和flex,但仍然遇到此错误。

makefile如下:

#!/bin/sh
#
# Makefile for FF v 1.0
#


####### FLAGS

TYPE    = 
ADDONS  = 

CC      = gcc

CFLAGS  = -O6 -Wall -g -ansi $(TYPE) $(ADDONS) 
# -g -pg

LIBS    = -lm


####### Files

PDDL_PARSER_SRC = scan-fct_pddl.tab.c \
    scan-ops_pddl.tab.c \
    scan-probname.tab.c \
    lex.fct_pddl.c \
    lex.ops_pddl.c 

PDDL_PARSER_OBJ = scan-fct_pddl.tab.o \
    scan-ops_pddl.tab.o 


SOURCES     = main.c \
    memory.c \
    output.c \
    parse.c \
    expressions.c \
    inst_pre.c \
    inst_easy.c \
    inst_hard.c \
    inst_final.c \
    relax.c \
    search.c

OBJECTS     = $(SOURCES:.c=.o)

####### Implicit rules

.SUFFIXES:

.SUFFIXES: .c .o

.c.o:; $(CC) -c $(CFLAGS) $<

####### Build rules


ff: $(OBJECTS) $(PDDL_PARSER_OBJ)
    $(CC) -o ff $(OBJECTS) $(PDDL_PARSER_OBJ) $(CFLAGS) $(LIBS)

# pddl syntax
scan-fct_pddl.tab.c: scan-fct_pddl.y lex.fct_pddl.c
    bison -pfct_pddl -bscan-fct_pddl scan-fct_pddl.y

scan-ops_pddl.tab.c: scan-ops_pddl.y lex.ops_pddl.c
    bison -pops_pddl -bscan-ops_pddl scan-ops_pddl.y

lex.fct_pddl.c: lex-fct_pddl.l
    flex -Pfct_pddl lex-fct_pddl.l

lex.ops_pddl.c: lex-ops_pddl.l
    flex -Pops_pddl lex-ops_pddl.l


# misc
clean:
    rm -f *.o *.bak *~ *% core *_pure_p9_c0_400.o.warnings \
        \#*\# $(RES_PARSER_SRC) $(PDDL_PARSER_SRC)

veryclean: clean
    rm -f ff H* J* K* L* O* graph.* *.symbex gmon.out \
    $(PDDL_PARSER_SRC) \
    lex.fct_pddl.c lex.ops_pddl.c lex.probname.c \
    *.output

depend:
    makedepend -- $(SOURCES) $(PDDL_PARSER_SRC)

lint:
    lclint -booltype Bool $(SOURCES) 2> output.lint

# DO NOT DELETE
c macos makefile
1个回答
0
投票

您的代码正在声明/定义函数fcterr(PROBNAME_EXPECTED, NULL);之前对其进行调用。有点像这样:

// trying to use this function before it has been declared / defined
fcterr( PROBNAME_EXPECTED, NULL ); 


// Later in the code it is defined here
void fcterr( int errno, char *par ) {
     // ...
}

您可以执行以下两项操作之一:

在使用前移动功能的定义

// Later in the code it is defined here
void fcterr( int errno, char *par ) {
     // ...
}

// trying to use this function before it has been declared / defined
fcterr( PROBNAME_EXPECTED, NULL ); 

在使用前声明函数-通常在头文件中完成:

// Declare the function (this could/should go in a header)
void fcterr(int errno, char *par);

// Now the compiler knows about this function
fcterr( PROBNAME_EXPECTED, NULL ); 

// Later in the code it is defined here
void fcterr( int errno, char *par ) {
     // ...
}

我很惊讶您在Ubuntu版本中没有遇到这个问题-您确定这两个版本之间没有区别吗? -我怀疑您可以通过更改Makefile来解决此问题! -除非我缺少一些信息...

© www.soinside.com 2019 - 2024. All rights reserved.