0

This is the error when I run make:

Undefined symbols for architecture arm64:
"\_add", referenced from:
\_main in a4-1-989722.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: \*\*\* \[a4-1\] Error 1

note (one of the functions in my module is add()

This is the makefile:

CC = gcc
CFLAGS = -Wall -Wextra -pedantic
TARGET = a4-1
DEP1 = myMath

all:    $(TARGET)

debug:  CFLAGS += -DDBUG
debug:  $(TARGET)

&(TARGET): $(TARGET).c $(DEP1).o
$(CC) $(CFLAGS) $(DEP1).o -o $(TARGET) $(TARGET).c

$(DEP1).o: $(DEP1).c
$(CC) $(CFLAGS) -c $(DEP1).c

clean:
rm $(TARGET) *.o

This is the module .c file:

#include <stdio.h>
#include <stdlib.h>

int add(int x, int y)
{
    return(x + y);
}

This is the module .h file:

int add(int, int);
3
  • 1
    Please use the Edit link in your question and edit it to have correct formatting: all your newlines are messed up and it's hard to tell what is what. You don't want to make each line use a fixed-width font individually, you want to create a block of quoted code. You can do that by indenting each line with 4 spaces. You can look here: stackoverflow.com/editing-help for more help. Also, please take advantage of the automatic preview feature of your question to make sure it is readable before finishing the edit. Then we can help! Commented Mar 25, 2022 at 19:51
  • Is the name of "the module .c file" in fact module.c? Because in that case, I have no idea what it has to do with the question, as the makefile given does not reference any such file. For its part, the makefile is either mangled or flat wrong, as each line in the recipe part of a make rule must be indented with a leading tab character, and there is no sign of any indentation of any kind in the makefile presented. Commented Mar 25, 2022 at 20:07
  • Plus there's a & before the $(TARGET) rule which is certainly wrong, and the output quoted here has bizarre backslashes before various characters. Also, it's weird to have a program depend on one .o file and one .c file, then link together the .o with the compiled .c file. It's not wrong, probably, but it's weird. Commented Mar 25, 2022 at 23:51

1 Answer 1

1
#include "module.h"

in module.c

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

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.