0

I have some useful functions in another project (project 2) but do not want to copy and paste all of them into a file within the project i'm currently working on (project one). I've tried making and including a header file within project one but it hasn't worked. Do I have to copy paste project 1 into project 2? My IDE is codelite. Thanks<3

EDIT: my header file is called hewwo.h and the code is

extern int readln(char[], int);

extern int searchstring(char[], char[]);

this file is within project 1.

and at the top of main.c in project 1 I have

#include < stdio.h> #include <stdlib.h> #include <string.h> #include "hewwo.h"

I'm trying to use the readln function in main.c and its throwing an "undefined symbols" error

push33n
  • 398
  • 4
  • 12

1 Answers1

0

The reason you're getting the error is because with the function declarations in the header file you're telling the compiler this function exists somewhere and it doesn't care where. Thus it compiles, but the links to the actual function implementations aren't there. You need to bring in the implementations via a static or dynamically linked library.

samuelnj
  • 1,627
  • 1
  • 10
  • 19
  • Although you're right that the header provides external declarations, that's the default for functions. The OP would get the same result if he omitted the `extern` keywords, so it's not really about them specifically. – John Bollinger Jun 07 '18 at 20:03
  • Ah, good point. – samuelnj Jun 07 '18 at 20:41