Go Down

Topic: Optional library files grows up binary size (Read 1 time) previous topic - next topic

Hello,

I'm writing a library that has many optional files to be included or not. My problem is when the files are present in library folder, even if not included in sketch, they grow up binary size. It seams they got linked while nothing is used in.
If I remove those files, binary get smaller, with no error and work well.
I'm using IDE 1.0.1.

Thanks for your help.

Mathieu
Mgth : ArduixPL http://www.mgth.fr

Jantje

Mathieu
A library in Arduino speak is not a library in C/C++ speak.
Only the Arduino core is treated like a real C/C++ library in the Arduino IDE and as such does not have the drawback of increasing your binary output with unused code.
There are some options you could take to fix your problem.
Change your code so the linker/compiler can do a better job. (requires good C/C++ knowledge)
Use a environment that allows you to use C/C++ libraries (requires knowledge of a C/C++ IDE )
Use defines to remove code. (requires more documentation and understanding of the library)
Split your library in several smaller libraries and only include the libraries needed in your sketch.

If you have many optional files the last is probably the most obvious choice

Best regards
Jantje

Note that even if you use C/C++ libraries you still have to seriously think about memory management.
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

ok,
thanks for the reply,
I thought that unused code should not get linked in final binary.
And actually it used to look like if it does, I mean, when I removed #include from ino, the bin got down in size. And I must have done something wrong, cause now it does not.

Mathieu
Mgth : ArduixPL http://www.mgth.fr

Jantje

Mathieu
There is some optimization. It is better when you use real C/C++ libraries then standard libraries. The problem is around "what are unused variables and what is unused code"
If it used to be better you probably indirectly include the headers.
To identify if and where a header is included: Try renaming a header and compile.
Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

I found what the problem was :
I tried to use the trick like in ethernet library to create a single "extern" object declared in .h and a global variable actually declared in .cpp
I did that for each of my optional module.
What I got is as the variable is globally declared in cpp, this one got linked...

Before to find that, I tried compiling as a c++ .a library in eclipse. as you said the binary is even smaller, and then even if I keep my global thing it does not get linked.

Anyway the first solution is better to get the lib distributed

It would be nice in future arduino versions that we could choose to have the libs compiled as .a

thanks for your help.
Mgth : ArduixPL http://www.mgth.fr

eried

I am not sure if this will work to you but it will help me to know:
http://arduino.cc/forum/index.php/topic,118440.0.html

I replaced the ancient compiler/winavr-avrdude with the last version. I get always slighty smaller files with the new one, can you test what you get?
My website: http://ried.cl

Go Up