I'm trying to include header files from the atmel avr folder to work with arduino. Despite trying to include the directory of the files, it still prompts me with "No such file or directory" when compyling. The files are located inside "C:\repositories\arduino_testing\include\avr" What am I doing wrong?
main.c
#include <stdio.h>
#include "avr\io.h"
int main(){
printf("This is a C code");
return 0;
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C : g .exe build active file",
"command": "C:\\MinGW\\bin\\g .exe",
"args": [
"-I C:\\repositories\\arduino_testing\\include",
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C : cpp.exe build active file",
"command": "C:\\MinGW\\bin\\cpp.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
c_cpp_properties
{
"configurations": [
{
"name": "Win32",
"includePath": [
//"${workspaceFolder}/**",
//"C:\\repositories\\arduino_testing\\avr",
"C:\\repositories\\arduino_testing\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c17",
"cppStandard": "c 17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
CodePudding user response:
In your c_cpp_properties.json file, you need to add the path to the avr folder in the includePath array.
"includePath": [
//"${workspaceFolder}/**",
"C:\\repositories\\arduino_testing\\include\\avr"
],
CodePudding user response:
#include "avr\io.h"
#include
always uses forward slashes /
as path separator, no matter what host system you are using.
That system header is part of the GNU tools for AVR and provided by AVR-LibC, hence:
#include <avr/io.h>
Also notice that this is a sytem header, thus enclose in <
and >
, not in "
's.
There is no need for -isystem <path>
(or -I <path>
for that matter) as far as the GNU tools are concerned. You might need to provide the headers to IDEs that need their contents to display locations of macro definitions, though.
If you can only compile with -isystem <path>
(or -I <path>
for that matter) your toolchain installation is broken, and you should get a working toolchain. Same if it doesn't work with -isystem
(or -I
): toolchain is broken.
So show the include paths, add -v
to the compiler options and inspect its output:
> avr-gcc -v ...
[snip many lines]
#include "..." search starts here:
#include <...> search starts here:
$install/bin/../lib/gcc/avr/8.5.0/include
$install/bin/../lib/gcc/avr/8.5.0/include-fixed
$install/bin/../lib/gcc/avr/8.5.0/../../../../avr/include
End of search list.
...
where the last line belongs to the AVR-LibC system includes. Resolving all these ..
's, the path is $install/avr/include
, and it should contain a folder avr
which contains io.h
etc.