jainvishal / agentx-tutorial

12 stars 8 forks source link

make: *** No rule to make target `agentxTutorial_data_get.o', needed by `agentxTutorial'. Stop. #2

Closed bernardoaraujor closed 7 years ago

bernardoaraujor commented 7 years ago

Hey Jain, it's me again.

I put AGENTX-TUTORIAL-MIB into ~/.snmp/mibs, generated the .c, .h, and makefile with mib2c, and copied (from a repo with step1_scalars_implement tag) the modified versions to introduce the monitor variables and alarm handler.

But now I'm having problems with the Makefile generated by mib2c. Note that if I overwrite it with the one from step1_scalars_implement tagged repo, it compiles alright. Am I doing something wrong??

bernardo@bernardo-ThinkCentre-Edge72:~/Documents$ mkdir subagent_tutorial
bernardo@bernardo-ThinkCentre-Edge72:~/Documents$ cd subagent_tutorial/

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ env MIBS=AGENTX-TUTORIAL-MIB mib2c -c mib2c.scalar.conf agentxTutorial
writing to agentxTutorial.h
writing to agentxTutorial.c
running indent on agentxTutorial.h
running indent on agentxTutorial.c

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ env MIBS=AGENTX-TUTORIAL-MIB mib2c -c mfd-makefile.m2m agentxTutorial
writing to agentxTutorial_Makefile

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ env MIBS=AGENTX-TUTORIAL-MIB mib2c -c subagent.m2c agentxTutorial
writing to agentxTutorial_subagent.c
running indent on agentxTutorial_subagent.c

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ cp ../agentx-tutorial/agentxTutorial.c .

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ cp ../agentx-tutorial/agentxTutorial_subagent.c .

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ make -f agentxTutorial_makefile
make: agentxTutorial_makefile: No such file or directory
make: *** No rule to make target `agentxTutorial_makefile'.  Stop.

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ make -f agentxTutorial_Makefile
make: *** No rule to make target `agentxTutorial_data_get.o', needed by `agentxTutorial'.  Stop.

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ cat agentxTutorial_Makefile 

CC=gcc
TABLE_PREFIX=agentxTutorial

NETSNMPCONFIG=net-snmp-config

# uncomment this if you have GNU make
#NETSNMPCFLAGS := $(shell $(NETSNMPCONFIG) --base-cflags)
#NETSNMPLIBS := $(shell $(NETSNMPCONFIG) --agent-libs)
NETSNMPCFLAGS=`$(NETSNMPCONFIG) --base-cflags`
NETSNMPLIBS=`$(NETSNMPCONFIG) --agent-libs`

LIBS=$(NETSNMPLIBS)

STRICT_FLAGS = -Wall -Wstrict-prototypes
CFLAGS=-I. $(NETSNMPCFLAGS) $(STRICT_FLAGS)

USER_SRCS = \
    $(TABLE_PREFIX)_data_get.c \
    $(TABLE_PREFIX)_data_set.c \
    $(TABLE_PREFIX)_data_access.c

SRCS = $(USER_SRCS) \
    $(TABLE_PREFIX).c \
    $(TABLE_PREFIX)_subagent.c \
    $(TABLE_PREFIX)_interface.c

USER_OBJS =  \
    $(TABLE_PREFIX)_data_get.o \
    $(TABLE_PREFIX)_data_set.o \
    $(TABLE_PREFIX)_data_access.o 

OBJS =  $(USER_OBJS) \
    $(TABLE_PREFIX).o \
    $(TABLE_PREFIX)_subagent.o \
    $(TABLE_PREFIX)_interface.o

TARGETS=$(TABLE_PREFIX)

.SUFFIXES:
.SUFFIXES: .c .o .deps

all: $(TARGETS)

user: $(USER_OBJS)

$(TARGETS): $(LIB_DEPS)

$(TABLE_PREFIX): $(OBJS) $(TABLE_PREFIX)_Makefile
    $(CC) -o $(TABLE_PREFIX) $(OBJS) $(LIBS)

clean:
    rm -f $(OBJS) $(TARGETS)

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ cp ../agentx-tutorial/agentxTutorial_Makefile .

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ make -f agentxTutorial_Makefile
gcc -I. `net-snmp-config --base-cflags` -Wall -Wstrict-prototypes   -c -o agentxTutorial.o agentxTutorial.c
gcc -I. `net-snmp-config --base-cflags` -Wall -Wstrict-prototypes   -c -o agentxTutorial_subagent.o agentxTutorial_subagent.c
gcc -o agentxTutorial agentxTutorial.o agentxTutorial_subagent.o `net-snmp-config --agent-libs`

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ cat agentxTutorial_Makefile 

CC=gcc
TABLE_PREFIX=agentxTutorial

NETSNMPCONFIG=net-snmp-config

# uncomment this if you have GNU make
#NETSNMPCFLAGS := $(shell $(NETSNMPCONFIG) --base-cflags)
#NETSNMPLIBS := $(shell $(NETSNMPCONFIG) --agent-libs)
NETSNMPCFLAGS=`$(NETSNMPCONFIG) --base-cflags`
NETSNMPLIBS=`$(NETSNMPCONFIG) --agent-libs`

LIBS=$(NETSNMPLIBS)

STRICT_FLAGS = -Wall -Wstrict-prototypes
CFLAGS=-I. $(NETSNMPCFLAGS) $(STRICT_FLAGS)

USER_SRCS = \
    $(TABLE_PREFIX)_data_get.c \
    $(TABLE_PREFIX)_data_set.c \
    $(TABLE_PREFIX)_data_access.c

SRCS =  \
    $(TABLE_PREFIX).c \
    $(TABLE_PREFIX)_subagent.c

USER_OBJS =  \
    $(TABLE_PREFIX)_data_get.o \
    $(TABLE_PREFIX)_data_set.o \
    $(TABLE_PREFIX)_data_access.o 

OBJS =  \
    $(TABLE_PREFIX).o \
    $(TABLE_PREFIX)_subagent.o

TARGETS=$(TABLE_PREFIX)

.SUFFIXES:
.SUFFIXES: .c .o .deps

all: $(TARGETS)

user: $(USER_OBJS)

$(TARGETS): $(LIB_DEPS)

$(TABLE_PREFIX): $(OBJS) $(TABLE_PREFIX)_Makefile
    $(CC) -o $(TABLE_PREFIX) $(OBJS) $(LIBS)

clean:
    rm -f $(OBJS) $(TARGETS)

bernardo@bernardo-ThinkCentre-Edge72:~/Documents/subagent_tutorial$ 
jainvishal commented 7 years ago

Humm... So there was a typo in the instructions for makefile I can see. The command would have been make -f agentxTutorial_Makefile but I noted it to be make -f agentxTutorial_makefile. That is minor.

Coming to the issue that you are having. You cannot use the makefile as-is that is generated by mib2c. If you do a diff between the two makefiles (one that is autogenerated and one that is in step1_scalars_implement), you will see following. Basically I removed use of $(USER_SRCS), $(USER_OBJS) which requires data_get, data_set, _data_access.c, interface.c files which are not necessary for this step. And running the make is complaining about missing rule for agentxTutorial_data_get.o for which we do not have the source and we do not need it.

vishalj@dreams:~/workspace/tmp/agentx-tutorial⟫ diff -u <(git show step1_scalars_autogenerated:agentxTutorial_Makefile) <(git show step1_scalars_implement:agentxTutorial_Makefile)
--- /dev/fd/63  2017-08-07 19:26:39.917833701 -0400
+++ /dev/fd/62  2017-08-07 19:26:39.917833701 -0400
@@ -22,20 +22,18 @@
        $(TABLE_PREFIX)_data_set.c \
        $(TABLE_PREFIX)_data_access.c

-SRCS = $(USER_SRCS) \
+SRCS =  \
        $(TABLE_PREFIX).c \
-       $(TABLE_PREFIX)_subagent.c \
-       $(TABLE_PREFIX)_interface.c
+       $(TABLE_PREFIX)_subagent.c

 USER_OBJS =  \
        $(TABLE_PREFIX)_data_get.o \
        $(TABLE_PREFIX)_data_set.o \
        $(TABLE_PREFIX)_data_access.o 

-OBJS =  $(USER_OBJS) \
+OBJS =  \
        $(TABLE_PREFIX).o \
-       $(TABLE_PREFIX)_subagent.o \
-       $(TABLE_PREFIX)_interface.o
+       $(TABLE_PREFIX)_subagent.o

 TARGETS=$(TABLE_PREFIX)

@@ -53,5 +51,4 @@
        $(CC) -o $(TABLE_PREFIX) $(OBJS) $(LIBS)

 clean:
-       rm -f $(OBJS) $(TARGETS)
-
+       rm -f $(OBJS) $(TARGETS)
\ No newline at end of file
vishalj@dreams:~/workspace/tmp/agentx-tutorial⟫ 
bernardoaraujor commented 7 years ago

Hey Jain, thanks for the quick reply!

Now that makes sense! Perhaps you could talk about these changes in the tutorial, so other people don't get confused like me with these modifications.