Obtaining a clang: error: linker command failed with exit code 1 when running makefile. Specifically when trying to create an executable:
gcc powers.c -Wall -pedantic -ansi -c
gcc bounds.o powers.o -o pracTwo
duplicate symbol '_power' in:
bounds.o
powers.o
Makefile:
pracTwo: bounds.o powers.o
gcc bounds.o powers.o -o pracTwo
bounds.o : bounds.c macros.h
gcc bounds.c -Wall -pedantic -ansi -c
powers.o : powers.c
gcc powers.c -Wall -pedantic -ansi -c
clean:
rm -f pracTwo bounds.o powers.o
Expected result, 2 .o files created (bounds.o and powers.o) then they are linked together to make a pracTwo executable. Tried looking through the my files however unable to locate the problem?
Here are the headers of the .c files: bounds.c
#include <stdio.h>
#include "macros.h"
void intCheck();
void doubleCheck();
void charCheck();
And powers.c
#include <stdio.h>
#include <stdlib.h>
int power();
And here is the header file:
#ifndef MACROS_H
#define MACROS_H
#include "powers.c"
#define FALSE 0
#define TRUE !FALSE
#define BETWEEN (n<lower) || (n>upper)
#endif
Unsure what the issue is, cannot locate any error of the code. Unsure what duplicate symbol '_power' in: means.
When you include
powers.cinbounds.cand link bothbounds.oandpower.oyou end up with the same symbol linked twice. The code only includes declaration so I was not able to reproduce the error as my gcc complained aboutpowernot_poweron my system.I suggest you don't include the .c file and rely on just linking (
power.o). You may also be able to declare the function static to make it file local.Unrelated, identifiers that start with
_are reserved (7.1.3) so it's advisable that you don't use that in your code.BETWEENshould probably be:and you may want to use a function-like macro instead with the arguments passed in: