The code compiles, and based off what I've seen in the linear search video, this should work. Tad bit confused why with this code below this error, I'm getting this error.

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

Here is the respective code.

bool search(int value, int values[], int n)
 for (int i = 0; i <= n; i++)
  if (n <= 0)
    return false;
  if (value == values[i]) 
    return true;

return false;  

Any help would be appreciated.

  • Did you make helpers or make find? – Cliff B Jul 19 '16 at 20:57
  • I used make helpers. – jayfeather31 Jul 19 '16 at 21:01

One of the lessons of this pset is how to build an executable from multiple source files using a makefile. The link error is happening because you are trying to make helpers. Because there are no instructions in the makefile on how to compile and link helpers, it tries to use default rules. The default rule says to create an executable based on the name of the .c file. It also requires that there is a main() function in the source code. Since there isn't a main() function in helpers.c, you get this error.

The build here is for find, not helpers. find.c is the primary source file. There are build instructions in the makefile file that say to compile and combine find.c and helpers.c, among others. You need to make find to compile this pset.

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

| improve this answer | |
  • Thanks for the help. Kind of feeling a tad bit stupid that I had the code correct but failed to execute it correctly. Whole lot of Dohs! are occurring right now. – jayfeather31 Jul 19 '16 at 21:17
  • 1
    eh, don't worry about it. You're not a real programmer until you notice the bruises on your face from slapping your forehead! ;-D – Cliff B Jul 19 '16 at 21:35

You must log in to answer this question.

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