Go Down

Topic: Any way to include contributed libraries in core code? (Read 585 times) previous topic - next topic

liuzengqiang

I originally wanted to add an I2CIO library within the NewLiquidCrystal library to easily control PCF8574 within the core code (such as main.cpp etc.) but found a better way to do it in setup() instead. This makes me think whether there is a way to actually use contributed libraries in core code at all. I can include a few libraries within avr folder in the IDE just fine, like:

Code: [Select]
#include <..\..\libraries\EEPROM\EEPROM.h>
In main.cpp
I have no idea whether I CAN include contributed libraries in main.cpp
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Juraj

and what do you do? compiler/linker have a parameter for libraries. never use full paths in source code

Robin2

I have no idea whether I CAN include contributed libraries in main.cpp
When you use the word "CAN" are you asking whether you have permission to do something or are you asking whether it is possible to do something?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

liuzengqiang

Referring to Juraj's comments, I want relative path so all IDE versions on any computer I use will compile correctly. CAN arduino IDE facilitate that? I compiled my code that has the contributed library included in the .ino file:

C:\Arduino\arduino-1.6.5-r5\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8037 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Micro" -IC:\Arduino\arduino-1.6.5-r5\hardware\arduino\avr\cores\arduino -IC:\Arduino\arduino-1.6.5-r5\hardware\arduino\avr\variants\micro -IC:\Arduino\arduino-1.6.5-r5\hardware\arduino\avr\libraries\EEPROM -IC:\Arduino\arduino-1.6.5-r5\hardware\arduino\avr\libraries\Wire -IC:\Users\user\OneDrive\OneDrive Documents\Arduino sketchbooks\libraries\NewliquidCrystal

If I understand this right, being the first message printed before all other compile messages, the contributed library NewliquidCrystal was compiled among other libraries, if I include it in .ino. I'll try this trick to see if it works. Include contributed library in .ino and use #include <xxx.h> in core .cpp files.

A later message regarding all core file compilation:

C:\Arduino\arduino-1.6.5-r5\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8037 -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Micro" -IC:\Arduino\arduino-1.6.5-r5\hardware\arduino\avr\cores\arduino -IC:\Arduino\arduino-1.6.5-r5\hardware\arduino\avr\variants\micro
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Juraj

install in Boards Manager some version of AVR boards package, for example 1.6.21 and repeat the experiment

liuzengqiang

install in Boards Manager some version of AVR boards package, for example 1.6.21 and repeat the experiment
I tried with 1.8.4 and the order of compilation is still the same, contributed libs before core files. Did you want me to see something else? BTW, I am only using 1.6.5-r5 because that's the last(ish) version without the pluggableUSB complication in USB implementation and I could make sense of what they do with USB. With pluggableUSB, there are too many things to make sense.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Juraj

I tried with 1.8.4 and the order of compilation is still the same, contributed libs before core files. Did you want me to see something else? BTW, I am only using 1.6.5-r5 because that's the last(ish) version without the pluggableUSB complication in USB implementation and I could make sense of what they do with USB. With pluggableUSB, there are too many things to make sense.
there is no Arduino AVR core 1.8.4. do you know what Boards Manager is and what are boards packages?

liuzengqiang

I meant IDE version 1.8.4. I know what board managers do but not sure how. I'm compiling arduino micro.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Juraj

I meant IDE version 1.8.4. I know what board managers do but not sure how. I'm compiling arduino micro.
the only core in IDE installation folder is the version of AVR core bundled with IDE.
every other core or other version of the AVR core is installed with the boards package in Arduino15 folder in users home folder and it doesn't change with IDE installation.

and you asked about GitHub. all board packages have a GtHub repo
here are the cores by Arduino
https://github.com/arduino?utf8=%E2%9C%93&q=arduinocore&type=&language=

liuzengqiang

Good to know they still use magic numbers. Bookmarked. How do I include contributed libraries in core code again? I still have no idea.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Juraj

Good to know they still use magic numbers. Bookmarked. How do I include contributed libraries in core code again? I still have no idea.
I still don't understand what do you mean by "include contributed libraries in core code"?
"core" is the folder with Arduino.h and co.

liuzengqiang

Say Juraj, I want to add some code to main.cpp, implement some new USB device classes in USBCore.cpp etc. that is what I mean by core code. And in these programs, I want to include libraries such as an adafruit 3-axis accelerometer library that is under my arduino sketchbook/libraries/adafruit-stuff folder, how do you go about including it in main.cpp or USBCore.cpp? Thanks.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Juraj

Say Juraj, I want to add some code to main.cpp, implement some new USB device classes in USBCore.cpp etc. that is what I mean by core code. And in these programs, I want to include libraries such as an adafruit 3-axis accelerometer library that is under my arduino sketchbook/libraries/adafruit-stuff folder, how do you go about including it in main.cpp or USBCore.cpp? Thanks.
you don't need to change the core files to use other device classes.
why do you want to change the main.cpp. what s what you can't do in setup() and loop()?

liuzengqiang

I need a way to include those libraries and you keep saying that I shouldn't. I'm not sure how far I have to lead you down my rabbit hole to convince you that I should. I will give it a try. The code that attaches USB is in main.cpp. I need some prep work before USB attach so my code goes in main.cpp
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Juraj

I need a way to include those libraries and you keep saying that I shouldn't. I'm not sure how far I have to lead you down my rabbit hole to convince you that I should. I will give it a try. The code that attaches USB is in main.cpp. I need some prep work before USB attach so my code goes in main.cpp
and for what board or MCU?
there is initVariant() for this

Go Up