0

I am writing a program using the Contiki operating system.

I have the remote_firmware.c file and a folder called parser with the files parser.h and parser.c where I wrote the method void test(). I included parser.h in remote_firmware.c with:

#include "parser/parser.h"

The Makefile looks like this:

CONTIKI_PROJECT = remote_firmware
all: $(CONTIKI_PROJECT)

#UIP_CONF_IPV6=1

CONTIKI_WITH_RIME = 1
CONTIKI = $(HOME)/contiki

include $(CONTIKI)/Makefile.include

When I try to build this the Error occurs:

undefined reference to 'test'

I am aware that the Makefile needs to know about parser.h, but I do not know how. I tried several solutions which were proposed here but I guess I did something wrong. Maybe somebody of you know what to do?

Thank you a lot.

kfx
  • 8,136
  • 3
  • 28
  • 52
  • to make some line in your question look like 'code', indent the line 4 spaces. Otherwise, the lines all run together (as you can see in your question) – user3629249 Jan 11 '18 at 22:35
  • Possible duplicate of [How to fix undefined reference/unresolved external symbol error](https://stackoverflow.com/questions/12573816/how-to-fix-undefined-reference-unresolved-external-symbol-error) – Mike Kinghan Jan 12 '18 at 06:44

2 Answers2

2

Where is your source file located? Try adding the source file name to the PROJECT_SOURCEFILES preprocessor variable (i.e PROJECT_SOURCEFILES+=parser.c) and adding the location of the source file to the CONTIKIDIRS preprocessor variable (i.e CONTIKIDIRS+={Directory}).

If parser.c depends on a lot other C files you might want create an C library archive first and then adding the library to your project by adding the name of the library to the TARGET_LIBFILES variable.

KillaKem
  • 995
  • 1
  • 13
  • 29
1

The error undefined reference to test is an error from the linker not the compiler. It has nothing to do with including a header file. It means when you linked the executable you didn't include parser.o

cleblanc
  • 3,678
  • 1
  • 13
  • 16
  • 1
    Yes. Its an issue with the Makefile: `CONTIKI_PROJECT = remote_firmware all: $(CONTIKI_PROJECT) #UIP_CONF_IPV6=1 PROJECT_SOURCEFILES += parser/parser.c CONTIKI_WITH_RIME = 1 CONTIKI = $(HOME)/contiki include $(CONTIKI)/Makefile.include` I added the line `PROJECT_SOURCEFILES += parser/parser.c` But still: > opening dependency file obj_zoul/parser/parser.d: No such file or directory – Stormregion0 Jan 11 '18 at 23:38