0

I am very new to programming. When I try and compile helpers.c using the command "make helpers" I get the following error messages:

 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [helpers] Error 1

Can anyone help me understand what this means, as I have no idea? This is my code for helpers.c:

 /**
 * helpers.c
 *
 * Helper functions for Problem Set 3.
 */
#include <stdio.h> 
#include <cs50.h>
#include "helpers.h"

void swap(int a, int b);
/**
 * Returns true if value is in array of n values, else false.
 */
bool search(int value, int values[], int n)
{
    for(int i = 0; i <= n; i++)
    {
        if(value == values[i])
        {
            return true;
        }
    }

    return false;
}

/**
 * Sorts array of n values.
 */
void sort(int values[], int n)
{
   int swap_count = 2;
   while (swap_count != 0)
   {
      for (int i = 0; i < n; i++)
      {
          swap_count = 0;
          if(values[i] > values[i+1])
          {
               swap(values[i], values[i+1]);
               swap_count++;
          }
          n--;
      }

    } 
    return;
}



void swap(int a, int b)
{
    a = b;
    b = a;
}

enter code here

1

no function main () in helpers, hence the error when compiling, you only have to type make in the terminal, if you are located in the appropriate directory, by the way the swap function will not work, see passing parameters to a function by values or by reference.

For more information you can see the link

https://cs50.stackexchange.com/questions/10145/why-cant-i-compile-the-program-that-i-wrote-to-test-helpers-c?rq=1

3
  • Thank you very much for your help. However, when I dowloaded the helpers.c file as instructed in pset3, it did not include a 'main' function, is it supposed to? May 11 '17 at 18:02
  • For this particular problem we have five files, find.c, generate.c, helpers.c, helpers.h, and a special file called makefile, the latter is responsible for binding all files in a single executable file. It is enough to write make in the terminal, we can not compile separately helpers.c, to check if the programs of sorting and search work we can write a test program, it is not difficult and it will serve us as an exercise.
    – MARS
    May 11 '17 at 19:43
  • MARS, your comment was very helpful. To make this file you MUST use 'make' NOT 'make helpers'
    – Seyah
    Jun 25 '17 at 13:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .