2

I have the following in test.c

#include <stdio.h>
#include "stdfn.h"

int main(void)
{
    printOut(10, "Hello, world!\n");
    //bash("say hello world");
}

Source is here: https://github.com/KrasnayaSecurity/HydroCarbon

I get this error when I try to compile:

President-JohnHEden:HydroCarbon aleksandr$ gcc test.c -o test -Wall
Undefined symbols for architecture x86_64:
  "_printOut", referenced from:
      _main in test-134873.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Lieutenant S.
  • 25
  • 1
  • 4
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – n. m. could be an AI Nov 12 '14 at 06:25
  • Please make sure you keep your function declarations in .h and definitions in .c . I see .h including #include "stdfn.c" why is that? – Gopi Nov 12 '14 at 06:49

2 Answers2

0

here, your linker is not able to find the definition of printOut() function.

You have included the declaration of printOut() in your test.c file by inlcuding stdfn.h, but there is no definition fpr that function present in test.c. The definition is present in stdfn.c. So, you need to complie both the files together to produce the binary.

Change your compilation line to

gcc test.c stdfn.c -o test -Wall
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
0

You can do a

gcc test.c stdfn.c -o test -Wall 

(presuming stdfn.c is the where the definition of printOut() lies) so as to link the file containing the user defined function to the file thats currently using it.

Paul R
  • 208,748
  • 37
  • 389
  • 560
Miss J.
  • 351
  • 1
  • 5
  • 15