This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/EK-TM4C1294XL: Adding a header-only library to an Energia project

Part Number: EK-TM4C1294XL
Other Parts Discussed in Thread: ENERGIA

Tool/software: Code Composer Studio

Hello everyone,

I'm building a C++ MIDI library that should work on a broad range of embedded and PC environments. It's basically a header-only library with an interface class and a huge block of #ifded statements that chooses which platform specific implementation is used. I also want to target Arduino-like environments like the Energia-based TI Launchpads. In fact, I did a lot of development and debugging for the Arduino-specific implementation on a launchpad with an Energia sketch created by the Code Composer Studio, as I prefer the more powerful options the Code Composer gives me.

Until now, my approach was very successful, it already works with the classic Arduino IDE, it works with MSP430 Targets in a CCS-based Energia sketch, but now I'm running into problems while testing my configuration with a Tiva-C Launchpad: I get the following linker error

/Users/MYUSERNAME/Library/Energia15/packages/energia/tools/arm-none-eabi-gcc/4.8.4-20140725/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: cannot find -lEK-TM4C1294XL_simpleMIDI

If I get it right, it searches for a compiled version of a cpp source file for my library to link, which obviously doesn't exist as it's header only.

What should I do? First of all I want to get it working for me, so a hint where this behaviour comes from would be helpful, but it would also be perfect if it worked out of the box for anyone who would only include the header and then should be happy with a working library without the need to do some sophisticated settings.

Any ideas?

  • Update: When including the header through 

    #include "/Absolute/Path/To/simpleMIDI.h"

    it builds without problems, however when doing it like

    #include <simpleMIDI.h>

    where simpleMIDI.h is located inside Energia/libraries the linker error posted above occurs. Really seems to be a behaviour specific to files located in the Energia/library search path.

  • Janos,

    I'm not sure if I clearly understand your work flow but I'll add a few thoughts here which will hopefully steer you in the right direction.

    I looked at some of the Energia example sketches after they were imported into CCS. Typically the libraries (like SPI, WiFi etc) are set up as their own projects that create a static library, then the main project adds the library project as a dependency. Also the static library is included in the main project's --library linker option. In those examples the static library project does contain both C++ source files and header files. I assume your environment is similar except your MIDI library does not have a source file, only a header file. Is that correct?

    A couple of options comes to mind - you could try creating an empty source file that simply includes your simpleMIDI.h header file, build a library out of that source file and then link that library into your main project (similar to what the Energia examples do). Or if you do not plan to generate a library at all, but simply include the header file into your main source file(s), then try removing the reference to the MIDI library in the --library linker option and see if that helps.

    If I have misunderstood the question and/or your development environment, please provide clarification. Or even better would be a sample test case that demonstrates the issue.

  • Yes you got me right. And now I also understood what's really happening there, I didn't get that all those additional projects popping up in the workspace are building static libraries that then will get linked into the main-project.

    Can this be assumed as default CCS behaviour for all headers located in the users Energia/libraries folder that are included through a #include<foo.h> for Energia sketches?

    In this case just including my header in the .cpp file obiously solves my problem. However as my main intent is to deliver a header-only library that doesn't really need this, I will wrap the include statement in the .cpp file in an #ifdef statement that only becomes true if it's a TM4C-based Energia CCS project and otherwise just produces an empty sourcefile. Any suggestion for a good set of macros to check to correctly identify this setup?
  • Janos Buttgereit said:
    Any suggestion for a good set of macros to check to correctly identify this setup?

    Per this related post that I found on the Energia forums, try the macros defined in Energia.h (TARGET_IS_BLIZZARD_RB1, TARGET_IS_SNOWFLAKE_RA0, etc). 

  • I know about the target-specific macros to check, but I just want to identify a CCS-based Energia-Project for the Tiva Launchpad so that a project generated by the Energia IDE won't be identified. Are there any macros telling me that CCS is used?

  • Janos Buttgereit said:
    Are there any macros telling me that CCS is used?

    Sorry but I haven't yet found a macro that you could use here. If I find anything I will post an update.