Makefile Help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    I have been trying to make the program swap but i have been getting errors with the makefile such as
driver.o: In function `main':
driver.c:(.text+0x34): undefined reference to `swap'
driver.c:(.text+0x48): undefined reference to `swap'
driver.c:(.text+0x5c): undefined reference to `swap'
collect2: ld returned 1 exit status
make: *** [swapbig] Error 1

i dont know why the driver has a swap when i declare the function as a swap_big function. and the makefile error is a spacing error but i used my previous makefiles for reference and it is ok, i dont know what i did wrong.
2. Relevant commands, code, scripts, algorithms:
swapbig.c

#include "swapbig.h"

void swap_big(float *a, float *b)
{

   float temp;

        if ( temp <= *a )
        {temp = *a;
         *a = *b;
        *b = temp;
        }
printf(" %x, contents %f\n", a, *a);
printf(" %x, contents %f\n", b, *b);
}

swapbig.h
#include <stdio.h>

/* Given two pointer values (floats) and swap the values in cell pointed
 * return the swap value, the first has to be less than or equal to the second*/

void swap_big(float *a, float *b);

driver.c

#include "swapbig.h"
//#define DEBUG

int main()
{

        #ifdef DEBUG
        printf("Initial values:\t a = %f, b = %f, c = %f\n",a, b, c);
        #endif

        swap_big(&a, &b);

        #ifdef DEBUG
        printf("First swap:\t a = %f, b = %f, c = %f\n",a, b, c);
        #endif

        swap_big(&b, &c);

        #ifdef DEBUG
        printf("Second swap:\t a = %f, b = %f, c = %f\n",a, b, c);
        #endif

        swap_big(&a, &b);

        #ifdef DEBUG
        printf("Third swap:\t a = %f, b = %f, c = %f\n",a, b, c);
        #endif

}
  1. The attempts at a solution (include all code and scripts):
    makefile
# target to make all programs for Lab 12
 all: swap swapbig reorder

# Problem 1 - swap programs
#complete the dependency and action lines for your filenames
swap: swaptest.o swap.o
        cc swaptest.o swap.o -o swap

swaptest.o: swap.h

swap.o: swap.h

# Problem 2 - swapbig programs
swapbig:swapbig.o
        cc driver.o swapbig.o -o swapbig

driver.o: swapbig.h

swapbig.o: swapbig.h

# Problem 3 - reorder programs
reorder: reorder.o
        cc driver1.o  reorder.o -o reorder

driver1.o: reorder.h

reorder.o: reorder.h

# source file dependencies
# add target lines showing dependencies for your .o files


# utility targets

clean:
        rm -f *.o

real_clean: clean
        rm -f swap swapbig reorder
  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    University of Hawaii at Manoa, Honolulu(HI), Oahu(Hawaii), Tep Dobry, ee160 EE 160: Lab 12

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

That's weird that it'd be complaining about no 'swap', driver.c definitely doesn't use it from what I can tell. Maybe that's leftover junk from a previous build, try cleaning out your .o files. See if there's any leftover after you run 'make clean', maybe your makefile isn't deleting them all.

1 Like