• AVR Freaks

Hot!Include file "magic"

Author
robert.galaxy
CTO
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2019/12/28 20:45:42
  • Location: East Coast
  • Status: offline
2020/01/24 08:04:10 (permalink)
0

Include file "magic"

I am trying to understand how included files are found.  I am using this sample project:  
           async_usart_echo_pic32mx470_curiosity.X
as a guide, basically trying to get the same functionality on a Digilent MAX32 board.
 
In the folder nbproject there is a file configurations.xml   It seems this file is rebuilt by the process of compiling/building, because if I change the line:    <property key="extra-include-directories" value=""/>
It changes back when rebuilding my project.
 
In the original project; the line looks like this:
<property key="extra-include-directories"
value="../src;../src/config/pic32mx470_curiosity;../src/packs/PIC32MX470F512H_DFP;../src/mips"/>
 
So my question is, if the file is created during the build, where does it get the information to build it?
----------------
Also when trying to build my version of the project, it fails on this line (No such file or directory):   
          #include <device.h>
This header file is located in the project, but I am guessing because of the "<>" is not looked for in my project.  But due to something I do not understand, the file is found in the original project.  So my questions are:  how is the file device.h found and why does the sample project use "<>" in the include statement?
 
Robert
 
#1

8 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 6474
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Include file "magic" 2020/01/24 08:25:33 (permalink)
    0
    maybe this page will help to answer your question about default search paths
    https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html
    #2
    Jim Nickerson
    User 452
    • Total Posts : 6474
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Include file "magic" 2020/01/24 08:29:09 (permalink)
    0
    my cmd window output looks like this

     


    C:\Users\jimni>"C:\Program Files (x86)\Microchip\xc32\v2.30\bin\xc32-cpp.exe" -v /dev/null -o /dev/null
    Microchip Language Tool Shell Version 2.30 (Build date: Aug 15 2019).
    Copyright (c) 2012-2017 Microchip Technology Inc. All rights reserved
    pic32m-cpp.exe: error: /dev/null: No such file or directory
    pic32m-cpp.exe: warning: '-x c' after last input file has no effect
    Using built-in specs.
    COLLECT_GCC=C:\Program Files (x86)\Microchip\xc32\v2.30\bin\bin/pic32m-cpp.exe
    Target: pic32mx
    Configured with: /data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/src/pic32m-gcc/gcc/configure --target=pic32mx --prefix=/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/install-mingw --program-prefix=pic32m- --with-sysroot=/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/install-mingw/pic32mx --with-bugurl=http://www.microchip.com/support --host=i686-w64-mingw32 --build=x86_64-linux-gnu --bindir=/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/install-mingw/bin/bin --infodir=/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/install-mingw/share/doc/xc32-pic32m-gcc/info --mandir=/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/install-mingw/share/doc/xc32-pic32m-gcc/man --libdir=/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/install-mingw/lib --libexecdir=/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/install-mingw/bin/bin --with-build-sysroot=/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/install-mingw/pic32mx --enable-stage1-languages=c --enable-languages=c,c++ --disable-hosted-libstdcxx --disable-libstdcxx-pch --disable-libstdcxx-verbose --disable-libssp --disable-libmudflap --disable-libffi --disable-libfortran --disable-bootstrap --disable-shared --disable-__cxa_atexit --disable-nls --disable-libgomp --disable-threads --disable-sim --disable-decimal-float --disable-libquadmath --disable-shared --disable-checking --disable-maintainer-mode --enable-lto --enable-fixed-point --enable-gofast --enable-static --enable-sgxx-sde-multilibs --enable-sjlj-exceptions --enable-poison-system-directories --enable-obsolete --enable-cxx-flags=-mno-smart-io --without-isl --without-cloog --without-headers --with-newlib --with-dwarf2 --with-gnu-as --with-gnu-ld CC_FOR_TARGET=pic32m-gcc CXX_FOR_TARGET=pic32m-g++ AS_FOR_TARGET=pic32m-as AR_FOR_TARGET=pic32m-ar RANLIB_FOR_TARGET=pic32m-ranlib 'CFLAGS_FOR_TARGET=-O2 -mno-smart-io -fno-short-double -fno-exceptions -fomit-frame-pointer -fshort-wchar' 'CXXFLAGS_FOR_TARGET=-O2 -mno-smart-io -fno-short-double -fno-exceptions -fomit-frame-pointer -fshort-wchar -fno-rtti -fno-enforce-eh-specs' CXX=i686-w64-mingw32-g++ CC=i686-w64-mingw32-gcc CPPFLAGS='-D_BUILD_MCHP_ -DSKIP_LICENSE_MANAGER -I/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/build-mingw/opt/include -D_BUILD_XC32_' LDFLAGS='-static -L/data01/build/bamboo/xml-data/build-dir/M32DEV-PT22-BMT/build-mingw/opt/lib'
    Thread model: single
    gcc version 4.8.3 MPLAB XC32 Compiler v2.30 (Microchip Technology)
     
    C:\Users\jimni>
     
     
     

    edit: formatting problems
    post edited by Jim Nickerson - 2020/01/24 08:32:38
    #3
    LdB_ECM
    Super Member
    • Total Posts : 236
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Include file "magic" 2020/01/24 08:51:26 (permalink)
    0
    Unless you were trying to override the system files (and you therefore have the same names) you never need to know just use the -I in the makefile or go to project settings and set the files in the include directory list.
     
    Your unit headers and code should have non system names and generally it will search the include list before looking in the standard library files.
     
    I would also add the below is generally a NO NO .. diagonal brackets are reserved for system files in many company standards. GCC is a bit flexible with it but many other company compilers are not forgiving, and I would stay out of that habit
    #include <device.h>

    Your own units go in normal quote includes
    #include "device.h"

    It also helps you to know what belongs to the compiler system and libraries and what is user code.
     
    It isn't written in stone but many companies won't accept it any other way.
     
     
     
    post edited by LdB_ECM - 2020/01/24 09:12:25
    #4
    robert.galaxy
    CTO
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/12/28 20:45:42
    • Location: East Coast
    • Status: offline
    Re: Include file "magic" 2020/01/24 11:10:03 (permalink)
    0
    @LdB_ECM  I agree with your post, which is one of the reasons I am confused.  The statement with brackets  #include <device.h>  was not written by me, it comes from the sample app downloaded from Microchip resources.
     
    I am just trying to understand WHY it works at all, since the file in question device.h is not a system file, but is rather contained in the project directories.  As a second question, why did the Microchip folks code it this way?  Maybe they had a good reason.  If so, I want to know what it is.
     
    Of course I can just modify the code to make it work, changing it to use quotes and place the file is a project  directory, that would be easy.  But I have refrained from just doing that, since I am trying to learn.
     
    I have been designing hardware and writing firmware for embedded processors for a long time (anyone remember the 4004?).  But learning is an ongoing requirement in the field we have chosen.
     
    Thanks for everyone's comments,
    Robert
    #5
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11577
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Include file "magic" 2020/01/24 11:46:15 (permalink)
    +1 (1)
    The behavior of the #include directive is almost entirely implementation-defined by the C standard, so you have to look at the compiler's documentation to see how it's implemented.  E.g., there is no such thing as "system files" in C.  The only rule enforced by the standard is that #include "file" will behave the same as #include <file> if "file" was not found.
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 18266
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Include file "magic" 2020/01/24 12:21:24 (permalink)
    +2 (2)
    Instead of looking at configurations.xml look at the  project compiler settings.  And Note you can not change configurations.xml with MPLabX Open, It will overwrite it with its in memory copy.
     
    There are Paths in:
    Project->General (Source Folders)
    Project->XC32->XC32-gcc->(Common Includes)
    Project->XC32->XC32-gcc-> Preprocessor (Include directories)
     
    Harmony will Change these.
    #7
    1and0
    Access is Denied
    • Total Posts : 10346
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Include file "magic" 2020/01/24 12:31:19 (permalink)
    +2 (2)
    As jtemples said, the only way to know is to read your implementation's documentation.
    ISO/IEC 9899:1999 6.10.2/2-4
    • A preprocessing directive of the form
      #include <h-char-sequence> new-line
      searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.
    • A preprocessing directive of the form
      #include "q-char-sequence" new-line
      causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read # include <h-char-sequence> new-line with the identical contained sequence (including > characters, if any) from the original directive.
    • A preprocessing directive of the form
      #include pp-tokens new-line
      (that does not match one of the two previous forms) is permitted. The preprocessing tokens after include in the directive are processed just as in normal text. (Each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens.) The directive resulting after all replacements shall match one of the two previous forms.143) The method by which a sequence of preprocessing tokens between a < and a > preprocessing token pair or a pair of " characters is combined into a single header name preprocessing token is implementation-defined.

    #8
    LdB_ECM
    Super Member
    • Total Posts : 236
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Include file "magic" 2020/01/24 23:03:10 (permalink)
    0
    @robert basically you are like me used to compilers that would not work. I would still just change it because it doesn't meet the normal standards and it is to hard to remember which compilers do what with search paths.
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5