Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

Compile time error while running multiple c files

$
0
0

#Edited

I am tested on simple two files now that are add.h and add.c.

I made a Makefile in order to compile my program. Here is my makefile.

# Make file for running the projectCC=gccCFLAGS= -Wall -gLDFLAGS = -includeOBJFILES = add.oLIB = add.hTARGET = addall: ${TARGET}%.o: %.c    ${CC} ${CFLAGS} -c -o $@ $<${TARGET}: ${OBJFILES}    ${CC} ${CFLAGS} -o ${TARGET} ${OBJFILES}clean:    rm -f $(OBJFILES) $(TARGET) *~

when I run

make add

I get the following error:

gcc -Wall -g -c -o add.o add.cgcc -Wall -g -o add add.oUndefined symbols for architecture x86_64:"_b", referenced from:      _main in add.old: symbol(s) not found for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to see invocation)make: *** [add] Error 1

here are snippets of my code

add.c

#include <stdio.h>#include <stdlib.h>#include "add.h"int main(void) {    int a = 10; b=20;    add(a, b);    return 0;}

add.h

#ifndef __ADD_H_#define __ADD_H_extern int a,b;int add(a,b){    return a+b;}#endif // __ADD_H_

Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>