9 years, 11 months ago.

Conditional Library compilation

I have two libraries : SPI_TFT and SPI_TFT_ILI9341. I need to use one *or* the other depending on the type of display controller a user has. I tried adding #ifdef #else around the #include statements so I only reference one in the code, but the compiler still compiles both libraries and gives me multiple definition errors (L6200E). How can I tell the compiler not to compile a library included in a project?

Presently I have to maintain two forks (one for each type of LCD display controller):

http://mbed.org/users/TickTock/code/CANary

http://mbed.org/users/TickTock/code/CANary_9341

Here is a test area showing the problem when I try to create one project with both libraries:

http://mbed.org/users/TickTock/code/CANary_9341_test/

I don't even reference the SPI_TFT library at all in my code but it still tries to compile causing the linker error. I am looking for a way to tell the compiler to ignore one or the other.

Please don't spam questions area :-) What if you share your code, that would be for us a good starting point what you got a the moment.

posted by Martin Kojtal 12 May 2014

I added links to the projects I am facing this problem with. Not following the spam comment. Is there another, smaller distribution area, I should be using to ask questions?

posted by Tick Tock 12 May 2014

1 Answer

9 years, 11 months ago.

Lazy Solution

My lazy solution would be this: /media/uploads/yoonghm/canary.zip

These are the changes:

  • Combine SPI_TFTx2 and SPI_TFTx2_ILI9341 folders into one. Resolve the differences.
  • Update files in TOUCH_TFTx2 folder to derive TOUCH_TFTx2 class from SPI_TFTx2 or SPI_TFTx2_IFI9341. This can be controlled during pre-compilation stage using precompile.h in the TOUCH_TFTx2 folder. The file is also needed in main.cpp. The constructors for TOUCH_TFTx2 for SPI_TFTx2 and SPI_TFTx2_IFI9341 are a bit difference. So the code is quite messy.

Better Solution

Define TOUCH_TFTx2 as virtual class. Implement the details in the concrete derived class such as SPI_TFTx2 and SPI_TFTx2_IFI9341

Accepted Answer

CAn you add that example as a library/program so people can export it ? Will be easier to click "Import". Thanks!

posted by Martin Kojtal 13 May 2014

Thanks HM Yoong!

posted by Tick Tock 17 May 2014