0

I just tried to compile this file(helpers.c), as a function implementation that is already included as a header for the main programme(find.c). I am not sure what else to do anymore, I have tried declaring the search function at the top of my code too.

#include <cs50.h>
#include "helpers.h"

bool linear_search(int value, int values[], int n) ;

/**
 * Returns true if value is in array of n values, else false.
 */
bool search(int value, int values[], int n)
{
    // TODO: implement a searching algorithm
    if (value < 0)
    {
        return false ;
    }
    else
    {
        return linear_search (value, values, n) ;
    }
}

/**
 * searches accorrding the linear method
 */
bool linear_search(int value, int values[], int n)
{
    for (int i = 0 ; i < n ; i++)
    {
        if (values[i] == value)
        {
            return true ;
        }
    }
    return false ;
}

ERROR MESSAGE THAT I GET

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 
  • did you make helpers or make find? – Cliff B Sep 11 '16 at 9:16
  • I used make helpers to check that the programme compiles, and that is what gave the error message above. – Kgotso Koete Sep 11 '16 at 9:21
1

This error means that there was no main() in the source files. By doing make helpers it tried to compile the program using the default rule of building an executable based on the name given - helpers.

This pset is, among other things, about learning to build an executable program from multiple source files and using the concept of a makefile. I'll refer you back to class lectures and notes on the subject for details.

The short answer though, is to make find.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |
  • Bless you Cliff B! It works fine. Before I check the mark to accept, quick Q. I see that the programme still compiles even if I did not declare the linear search function at the top helpers.C. Is there any negative implication of this exclusion down the road? – Kgotso Koete Sep 11 '16 at 9:38
  • If the function (with code) appears before it is called by any other code, the one line signature declaration is not needed. If it were to be called by code in a different source code file, then it should be included in the .h header file. Also, if the declaration were needed but missing, an error would be thrown during compile. So, no. – Cliff B Sep 11 '16 at 20:16
  • Of course. I see now that the signature declaration are included in the header files. Thank you again :). – Kgotso Koete Sep 11 '16 at 20:20

You must log in to answer this question.

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