0

I'm working on creating a project on a BeagleBone Green, and am struggling to get the makefile correct.

The issue is that when I run my file, my enum declaration causes an error

#include <rc/uart.h>

enum responses {
    SUCCESS = 0,
    SEND_ERROR,
    RECEIVE_ERROR,
    RESPONSE_ERROR
};

 error: expected identifier before numeric constant
     SUCCESS = 0,

I dug around and it seemed like it might be a preprocessor issue based on this topic, but when I toss -E into my makefile (below), it results in

gcc: warning: /usr/local/lib/test.o: linker input file unused because linking not done

I'm not sure how to set this up properly and would really appreciate some help.

This is how it's all set up:

usr
|
----include
|   |
|   ----rc
|   |   | 
|   |   ----uart.h
|   |   ----time.h
|   |
----lib
|   |
|   ----librobotcontrol.so
|   |  
----local
|   |
|   ----include
|   |  |
|   |  --- testfile.h
|   |
|   ----src
|   |  |
|   |  --- testfile.c
|   |  --- makefile

I structured the makefile after the answer here:

CC = gcc
#IDIR = /usr/include /usr/local/include
#LDIR = /usr/lib

#/usr/src /usr/local/src 
SRC_DIR := /usr/local/src
OBJ_DIR := /usr/lib
BIN_DIR := .

EXE := $(BIN_DIR)/testmake
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o), /usr/lib/librobotcontrol.so

CPPFLAGS := -Iinclude -MMD -MP
CFLAGS := -Wall
LDFLAGS := -Llib
LDLIBS := -lm

.PHONY: all

all: $(EXE)

$(EXE): $(OBJ) | $(BIN_DIR)
    $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
    
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
    $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
    
$(BIN_DIR):
    mkdir -p $@
    
clean:
    @$(RM) -rv $(BIN_DIR) $(OBJ_DIR)
    
-include $(OBJ:.o=.d)
  • 5
    It looks like `SUCCESS` might be a macro somewhere. Try `#undef SUCCESS` before your enum declaration. If that fixes the problem, then consider using less "common" names for your enums. – paddy Jul 20 '22 at 02:57
  • @paddy jesus christ, that was it. At least I learned a bit more about makefiles today lol – ahzired Jul 20 '22 at 03:12
  • 1
    Just to help you in future, the key to this is the error message _"expected identifier before numeric constant"_. You know the correct syntax for an enum definition, and yours was fine. So this message is telling you that there's no identifier. You do also have a numeric constant there, but probably `SUCCESS` was defined to be a numeric constant also. So the first thing the compiler saw when parsing the enum body was a numeric constant where it expected an identifier. Sometimes error messages seem cryptic, but with practice it becomes easier to decipher what they're actually telling you. – paddy Jul 20 '22 at 04:30
  • Another thing: the `gcc` message was absolutely correct and to be expected: `-E`, issued for the compile stage, is the "emit preprocessor result and stop" flag, which obviously will not link anything. – Vroomfondel Jul 20 '22 at 08:35

0 Answers0