Jump to content
43oh

How to select correct include file


Recommended Posts

I don't know why an include file would tell the linker what to link; that'd have to be an Energia thing, because it's not how C normally works.

 

But part of the problem is you don't grasp how preprocessor conditionals work. Defining things to the lexical tokens true and false is irrelevant; the key is whether the macro is defined at all or not (when using #if defined(m) or #ifdef m) and whether the macro has a value that expands to an integer expression that is not equal to zero (when using #if m).

 

Below is example code which produces the following when run through the preprocessor alone. I suggest experimenting with variations of it until you understand what's going on. Also look at the documentation for the GNU C Preprocessor.

 

llc[211]$ msp430-elf-gcc -E /tmp/x.c | sed -e '/^$/d'
# 1 "/tmp/x.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/tmp/x.c"
mTIVA=true
  6 mTIVA is not true
  9 mTIVA is defined
mTIVA=false
  20 mTIVA is not true
  23 mTIVA is defined
mTIVA=1
  32 mTIVA is 1
  37 mTIVA is defined
mTIVA=0
  48 mTIVA is 0
  51 mTIVA is defined
mTIVA=true
#define TIVA true
#if (TIVA)
  __LINE__ mTIVA is true
#else
  __LINE__ mTIVA is not true
#endif
#if defined(TIVA)
  __LINE__ mTIVA is defined
#else
  __LINE__ mTIVA is not defined
#endif

#undef TIVA
mTIVA=false
#define TIVA false
#if (TIVA)
  __LINE__ mTIVA is true
#else
  __LINE__ mTIVA is not true
#endif
#if defined(TIVA)
  __LINE__ mTIVA is defined
#else
  __LINE__ mTIVA is not defined
#endif

#undef TIVA
mTIVA=1
#define TIVA 1
#if (TIVA)
  __LINE__ mTIVA is 1
#else
  __LINE__ mTIVA is not 1
#endif
#if defined(TIVA)
  __LINE__ mTIVA is defined
#else
  __LINE__ mTIVA is not defined
#endif

#undef TIVA
mTIVA=0
#define TIVA 0
#if (TIVA)
  __LINE__ mTIVA is not 0
#else
  __LINE__ mTIVA is 0
#endif
#if defined(TIVA)
  __LINE__ mTIVA is defined
#else
  __LINE__ mTIVA is not defined
#endif
Link to post
Share on other sites

pabigot

 

As the following also fails regardless if I define _TIVAx or not, would you deduce that it is an energia problem.

I thought I knew what was going on, if _TIVAx is defined #include "TM4C_DS18B20.h" is used, and if _TIVAx is not defined then #include "GFDS18B20.h" is used.

 

 

#define _TIVAx

 

#ifdef _TIVAx

#include "TM4C_DS18B20.h"

#endif

#ifndef _TIVAx

#include "GFDS18B20.h"

#endif

Link to post
Share on other sites

pabigot

 

As the following also fails regardless if I define _TIVAx or not, would you deduce that it is an energia problem.

If this fails:

#define _TIVAx
#ifdef _TIVAx
#include "TM4C_DS18B20.h"
#endif
#ifndef _TIVAx
#include "GFDS18B20.h"
#endif
and this works:

#define _TIVAx
#ifdef _TIVAx
#include "TM4C_DS18B20.h"
#endif
then Energia is doing something very strange, because the two should be equivalent, unless the C preprocessor is not what controls what Energia operates on.

 

I thought I knew what was going on, if _TIVAx is defined #include "TM4C_DS18B20.h" is used, and if _TIVAx is not defined then #include "GFDS18B20.h" is used.

That's what I would expect.
Link to post
Share on other sites

Energia will attempt to build and link all *.cpp and *.ino (alias for cpp) and I think all *.c files in your project folder, the folders of any libraries referenced by #include files in the master .ino file (discovered by searching all libraries dirs for that .h file) and any .cpp/.c files in the utility/ subdirectory within any if those library dirs.

 

Sent from my Galaxy Note II with Tapatalk 4

Link to post
Share on other sites

I haven't confirmed this with Energia (and Arduino/Wiring)'s java code yet, but I suspect the IDE finds all the #include's with what could be imagined as a simple grep, not honoring the C preprocessor directives since it's a simple analysis against the .ino file.

 

Sent from my Galaxy Note II with Tapatalk 4

Link to post
Share on other sites

Spirilis Yup seems all #includes are digested by Energia. But as I have fully ported over to Tiva, do not use the 5529 includes anymore.

 

 

Regarding Serial1, at the moment have put in routing links to select the other pins Tiva drives.

 

.

 

Will have a play with Tiva Ware API's and see if I can get the pins in tune with the normal booster pack settings.

 

Link to post
Share on other sites
  • 11 months later...

This is an Energia/Arduino pre-processor "bug"/"feature" depending how you look at it. The Energia/Arduino IDE parses the Sketch looking for #include's of libraries to collect and add them to the list of files to compile. If you #include libraries that have the same function's, defines, macro's, etc you end up with the linker error you see.

 

There is currently no way around this other then creating one single library that supports all chips you which to support and use the defines given to you by Energia to make decisions for chip specific functions.

 

Hope this helps.

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
Reply to this topic...

×   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.

×
×
  • Create New...