Jump to content
 
  • 0
Orunmila

Preprocessor defines for XC32 used to select include file

Question

I am trying to pass an include file name on the command line to XC32 to select the file to include in the code. Don't ask why, this is not my code, I am just trying to compile it with this compiler without modifying the code ...

I am passing 

-DCONFIG_FILE=\"demo_config.h\"

but the compiler does not seem to like this, error message is 

 error: #include expects "FILENAME" or <FILENAME>

Anyone know how to bend XC32 to my will here to do this correctly?

 

EDIT: I have confirmed that this works fine on vanilla GCC. On MCHP XC32 I can do this and then it compiles fine

#undef CONFIG_FILE
#define CONFIG_FILE "demo_config.h"
  
#include CONFIG_FILE

It seems like when I pass in the filename via the command line something weird and unexpected is happening ...

I used a trick to print the value and the filename is ending up in the code correctly it seems ...

#define XSTR(x) STR(x)
#define STR(x) #x

#pragma message "The include is " XSTR(CONFIG_FILE)
#ifdef CONFIG_FILE
    #include CONFIG_FILE
#endif

This will produce:

#pragma message: The include is "demo_config.h"

error: #include expects "FILENAME" or <FILENAME>

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I was able reproduce that, XC16 and XC32 seem to strip the quotes from your string literal definition, no matter what you do 😞

 

Share this post


Link to post
Share on other sites
  • 0

The weird thing is that printing out the value in the file like I did it includes the quotes though. 

When I played around with the command line I eventually managed to get it to work by passing in something like:

-D'CONFIG_FILE=\\\"demo_config.h\\\"'

The disappointing thing for me was that passing in the exact same thing that I am passing to GCC does not seem to work with the Microchip version.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 


  • Popular Contributors

  • Similar Content

    • By Orunmila
      I am trying to use a linker script with MPLAB-X for my PIC32 project but for some reason the script is not being passed to the linker at all. I expected that all I had to do was add the .ld file to my project, typically by placing it in the "Linker Files" virtual folder in MPLAB-X in my project. I did this and the linker script is being ignored by the linker.
      This is one of those $100 questions (if you know the story of the mechanic asking $100 for knowing where to hit ...).
      So my question is how do I get MPLAB-X to use my linker script which I have added to the PIC32 project?
    • By Orunmila
      I have a MPLAB-X project which uses a loadable (it is combining my program with a bootloader which is in another project). 
      I need to compile this project from the command line for CI automation. For the entire build process every command executed is nicely printed in the build window, but for the loadable it claims to be using Hexmate, but the command line to execute it is not shown at all.
      Can anyone help me with the syntax using Hexmate to get the same behavior as adding the Loadable from MPLAB-X?
    • By Orunmila
      I just downloaded XC32 V2.15, I was using V2.10 before. I find that some of my projects no longer compile. On my first check I noticed that the problems seem to occur when inline functions are used and the same header where the inline implementation is done is included in more than one compilation unit?
      Has any of you seen similar issues?
      I will investigate further and post here if I arrive at an answer.
       
      UPDATE: Ok, I managed to make a small test project to replicate the problem. I am attaching it here. 
      TestInlineXC32_2.15.zip
       
      Next I am going to test this on some other compilers to see what the deal is. I have confirmed that with that project when you switch it to V2.10 or older it all compiles just fine, but if you use V2.15 it failes to link with the following error:
      "/Applications/microchip/xc32/v2.15/bin/xc32-gcc"   -mprocessor=32MZ2048EFM100  -o dist/default/production/TestInlineXC32_2.15.X.production.elf build/default/production/main.o build/default/production/otherFile.o          -DXPRJ_default=default  -legacy-libc    -Wl,--defsym=__MPLAB_BUILD=1,--no-code-in-dinit,--no-dinit-in-serial-mem,-Map="dist/default/production/TestInlineXC32_2.15.X.production.map",--memorysummary,dist/default/production/memoryfile.xml
      nbproject/Makefile-default.mk:151: recipe for target 'dist/default/production/TestInlineXC32_2.15.X.production.hex' failed
      make[2]: Leaving directory '/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X'
      nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
      make[1]: Leaving directory '/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X'
      nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
      build/default/production/otherFile.o: In function `myInlineFunction':
      /Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X/inlinedheader.h:6: multiple definition of `myInlineFunction'
      build/default/production/main.o:/Users/ejacobus/MPLABXProjects/TestInlineXC32_2.15.X/inlinedheader.h:6: first defined here
      /Applications/microchip/xc32/v2.15/bin/bin/gcc/pic32mx/4.8.3/../../../../bin/pic32m-ld: Link terminated due to previous error(s).
      collect2: error: ld returned 255 exit status
      make[2]: *** [dist/default/production/TestInlineXC32_2.15.X.production.hex] Error 255
      make[1]: *** [.build-conf] Error 2
      make: *** [.build-impl] Error 2
      BUILD FAILED (exit value 2, total time: 680ms)
       
       
       
×
×
  • Create New...