1

I just started pset3 and when I try to compile my helpers function I get this crazy mess of error messages from clang. This is my code /** * helpers.c * * Computer Science 50 * Problem Set 3 * * Helper functions for Problem Set 3. */

     #include <cs50.h>

     #include "helpers.h"

     /**
     * 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

        bool returnValue = false;

        for (int i = 0; i < n; i++) {
            if (values[i] == value) {
                returnValue = true;
            }
        }

        return returnValue;

    }

    /**
    * Sorts array of n values.
    */
    void sort(int values[], int n)
    {
        // TODO: implement an O(n^2) sorting algorithm
        return;
    }

And this is the mess of error messages clang gives me

    cameronburkholder:~/workspace/pset3/find $ make helpers
    clang -ggdb3 -O0 -std=c11 -Wall -Werror    helpers.c  -lcs50 -lm -o helpers
    /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

2 Answers 2

2

$ make helpers

Part of the lesson on this pset is how to build an executable from multiple source code files - in this case, find.c and helpers.c, along with the *.h files. The file Makefile contains the build instructions for this project, but no rule for making an executable called helpers, so the system goes to the default rule of making an executable based on the make command. There are a multitude of issues with trying to build an executable called helpers, starting with the lack of a main() function.

The correct command was make find.

You might benefit from a review of the class material on building and compiling executables, and on how make works.

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

1

You do not need to make the helpers.c file because it is not an executable. It contains functions that will be used by the find program. Once you finish implementing the search and sort, just save your work then make the find.c file.

You must log in to answer this question.

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