0

I'm getting "undefined reference to `get_metadata_record_new'" right on the get_metadata_record_new(sz) in memory.c

{memory.c}

#include "metadata_record.h"

bool add_tohashtable(struct memory *mem, char *key_address, size_t sz) {
    //Getting the error on this next line
    struct metadata_record * metarec = get_metadata_record_new(sz);
    ...
}

{metatdata_record.h}

#ifndef METADATA_H_
#define METADATA_H_
struct metadata_record {
    size_t size;
    bool allocated;
};

struct metadata_record *get_metadata_record_new(size_t);
...
#endif /* METADATA_H_ */

I tried copying and pasting this definition from my metadata_record.c file to the top of my memory.c and the error goes away:

struct metadata_record *get_metadata_record_new(size_t sz) {
...
}
2
  • 3
    Gotta link the two files together... Commented Sep 28, 2012 at 20:36
  • Of course. I added the new file and forgot to update my make file. Thanks Commented Sep 28, 2012 at 20:38

2 Answers 2

3

You have to link the two files together in order the one to see the other.

ProTip: don't write Makefiles like

myprog: file_one.o file_two.o

you are going to forget to update them. Also, it's just a bad concept. Instead, write Makefile like

OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
myprog: $(OBJECTS)

That would break way less frequently.

Sign up to request clarification or add additional context in comments.

Comments

0

I forgot to link the file (in my make file).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.