0

I have a problem when i want use his scripts:

lib1.h
...
#ifdef LIB1_01
int lib1func(void);
#endif
...

lib1.c
...
#ifdef LIB1_01
int lib1func(void){
   ...
}
#endif
...

main.c

#define LIB1_01
#include <lib1.h>
int main(){
   ...
   int x = lib1func(void);
   ...
...

I want use lib1func() when #define LIB1_01 is declared but I have an 'warning : implicit declaration of function' error when i use it...why ? Can you help me ? Best regards.

1
  • Modify #include <lib1.h> as #include "lib1.h". Commented Jun 20, 2014 at 3:49

2 Answers 2

1

Recommended alternative:

lib1.h

#ifndef LIB1_H
#define LIB1_H
int lib1func(void);
#endif
...

lib1.c

#include "lib1.h"
int lib1func(void){
   ...
}

main.c

#include "lib1.h"
int main(){
   ...
   int x = lib1func(void);
   ...
...

NOTE:

1) You should declare "int lib1func(void)" in the header, but you may define it anywhere. In lib1.c (if you prefer), or even main.c. Just make sure you only define it once.

2) Note the use of the guard around the entire header body.

3) Also note the use of include "myheader.h" (for your own header files), vs. #include <systemheader.h>. The "<>" syntax should be used only for system headers.

Sign up to request clarification or add additional context in comments.

Comments

0

To use that kind of includes, compile with option I.

gcc myfile.c -o myfile -I .

The . symbol means look in the current directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.