0

clang testing.c -lcs50 -o testing

/tmp/testing-6c5209.o: In function `main':
testing.c:(.text+0x3f): undefined reference to `sort'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What am I doing wrong?

0

In C, you have to define/declare the functions before you use them

Ex0:

// function definition
void foo(void)
{
    // some code
}

int main(void)
{
    foo(); // call foo
}

Ex1:

// function declaration
void foo(void);

int main(void)
{
    foo();
}

// function definition
void foo(void)
{
    // some code
}

In EX1, you could define the function anywhere in the source code file. As long as it's declared before it is called, there should be no errors like this one. For more information, you may watch the short on functions!


Edit:

your need to compile the source code files together using a command like

clang testing.c helpers.c -lcs50 -o testing
2
  • I believe to have done so and there is some issue with linking the header file helpers.h when invoking clang/make? – daniel Feb 16 '15 at 19:55
  • @daniel please take a look at the Edit section in my updated answer! Thank you! – kzidane Feb 16 '15 at 20:07

You must log in to answer this question.

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