0

I am programming in CCS (based on Eclipse) to learn to use microcontrollers.

I'm having some problems with includes.


I have 4 files:

GPIO.h - macros and prototypes of GPIO functions

GPIO.c - implementation of GPIO functions declared in GPIO.h

main.c - main program

util.h - macros and typedefs essential to all other files


In each of the programs put the includes, I ctrl + c / ctrl + v of my code: I really try with " ", I would like to make my code run, it would be rewarding.

GPIO.h - #include "util.h"

GPIO.c - #include "GPIO.h"

main.c - #include "GPIO.c"

util.h - (no includes)

As in eclipse all files are placed in the project folder. Already checked manually by accessing the folder, and they are there.

When I compile and run, there are 2 errors referring to include:

"../GPIO.c", Line 9: fatal error # 1965: Can not open source file "GPIO.h"

"../main.c", Line 1: fatal error # 1965: Can not open source file "GPIO.c"

I do not understand what's wrong!

I made the edit so that people understand that even with "" the error continues (@ mame98). I made it clear that I am using the CCS IDE based on Eclipse and now my suspicion is with the operating system. I will have the opportunity to test on Windows only now.

ialsafid
  • 25
  • 6
  • 2
    Try using `""` instead of `<>`. And *never* include `*.c` files. – Eugene Sh. Apr 12 '16 at 15:29
  • In main I need include GPIO.h and util.h? – ialsafid Apr 12 '16 at 15:33
  • possible duplicate: https://e2e.ti.com/support/development_tools/code_composer_studio/f/81/t/349148 – jada12276 Apr 12 '16 at 15:34
  • Depends. If it needs the stuff defined there. – Eugene Sh. Apr 12 '16 at 15:34
  • @EugeneSh. including `*.c` files is allowed in C. Though not a good practice. read: http://stackoverflow.com/a/1109255/978399 – jada12276 Apr 12 '16 at 15:35
  • 1
    @jada12276 `a=b++ + ++b` is allowed as well. Not everything allowed should be used. I can't think of even one use case where `c` files should be included. The linked answer is not convincing. – Eugene Sh. Apr 12 '16 at 15:37
  • Possible duplicate of [What is the difference between #include and #include "filename"?](http://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename) – Antti Haapala -- Слава Україні Apr 12 '16 at 15:38
  • @EugeneSh. don't work. Reading some forums IT seems that it is because administrative privileges related to CCS software. I'm using Linux Ubuntu 15.10. – ialsafid Apr 12 '16 at 15:42
  • If I use "" -> I get 18 errors! (I remove .c include) – ialsafid Apr 12 '16 at 15:44
  • 2
    That's good. It means you have a progress. Now start fixing them. – Eugene Sh. Apr 12 '16 at 15:45
  • @EugeneSh. If something is allowed, it can be used. The OP problem is not related to the good practice you suggest. Your comment said to _never_ include `*.c` file without giving a good reason. – jada12276 Apr 12 '16 at 15:49
  • @jada12276 You can `include` `*.jpg` files if you wish. It is allowed. But I doubt it will yield anything sensible... – Eugene Sh. Apr 12 '16 at 16:01
  • @EugeneSh. Ofcourse you can include a `*.jpg` file as long as its contents are interpretable by the C compiler. I am sure a file extension means nothing here. Meanwhile, including a jpeg formatted file is not allowed to be included in C. – jada12276 Apr 12 '16 at 16:09

2 Answers2

1

You should only include H files as Eugene Sh. Points out... Also, use #include "util.h" and #include "gpio.h" as they are local files and they are not in the default search path of your compiler. If you want to include 'global' headers (which are in the search path) you have to use #include <file.h>.

Maybe also note, that it is possible to add your local folder to the search path with using the -I. option for GCC (should work with other compilers too).

For more infos about the search path, see here.

mame98
  • 1,271
  • 12
  • 26
  • I use "" and get 18 errors. I understand the problem of "" and <>, above a user sent a link explaining. After some answers entered in the project settings and added the File Search Path own path of the project folder to ensure it is no problem Compiler. I'm searching in the IT forums too. Maybe it's a bug LINUX UBUNTU 15.10 with CCS 6.1.12. – ialsafid Apr 12 '16 at 17:03
  • Hard to tell without seeing your code... You should add include guards to all header files, so you will prevent multiple declaration errors.. – mame98 Apr 12 '16 at 17:38
0

<> is for libraries like #include <stdio.h>

"" is used for your own files #include "GPIO.h"

Be careful including .c! If GPIO.h is included in GPIO.c, too, you could get errors..(multiple inclusion protection is useful here!)

michi.b
  • 264
  • 1
  • 4
  • 14
  • The errors continue to appear. And with " " GPIO.c even recognize the macros (appearing 18 errors), which is only what owned file: #define GPIO STRENGTH 2MA 0x00000001 #define GPIO STRENGTH 4mA 0x00000002 – ialsafid Apr 12 '16 at 22:00
  • Are you include paths for your project correct? Try to choose your current project, select properties and search in "Build" for "Include options". Now you can add a directory path to your source/header files and the linker will search in your added directory. – michi.b Apr 13 '16 at 05:55