Libraries always included?

I am trying to figure out why a small sketch is already 29kb.
Pretty much assume it is because a lot of libraries seem to get included on compile (they are not in my code however).

#include #include #include #include #include #include #include

A small sketch takes 29kb with this setup. is this normal and can i optimize this?

Why are you including header files if you don't need them?

i need the ones i included, but there seem to be a whole lot more getting included, besides the ones i need to edit out myself (like ethernetserver.. i only need client).
... i am making datalogger that logs to sd card and periodicly sends updates to internet. should work with or without internet.
the eeprom lib is included for storing settings of the sketch itself to overcome power loss.
time is needed to be in sync with receiving server.

will those iibs eat all my memory then?

edit: just checked and creating empty sketch with those libs only uses 1186 bytes

i need the ones i included

they are not in my code however

Only one of these statements can be true.

will those iibs eat all my memory then?

Use, yes. When you load a different sketch, you won't find crumbs where the previous sketch made a meal of your memory.

edit: just checked and creating empty sketch with those libs only uses 1186 bytes

How big is an "empty" sketch without them being included? I think that you'll find that it is not much smaller.

rondlite:
a lot of libraries seem to get included on compile (they are not in my code however).

can be true if you dont cut the line in half. It SEEMS they get included because I see libraries scroll by on compile that i did not include in my sketch (like wire etc).
they most likely get included from other libraries. so i thought i might need to tweak them.
when i create a new sketch from the old (so there will be new compile from scratch) it still compiles to 28kb (380 lines of script)

Compile shows:

Gathering compilation infomation...
Compiling sketch...
Cleaning...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/archilog11.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/CDC.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/HardwareSerial.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/HID.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/IPAddress.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/main.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/new.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/Print.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/Stream.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/Tone.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/USBCore.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/WInterrupts.c.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/wiring.c.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/wiring_analog.c.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/wiring_digital.c.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/wiring_pulse.c.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/wiring_shift.c.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/WMath.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/WString.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/malloc.c.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/realloc.c.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/EEPROM.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/Dhcp.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/Dns.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/Ethernet.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/EthernetClient.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/EthernetServer.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/EthernetUdp.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/socket.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/w5100.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/File.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/SD.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/Sd2Card.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/SdFile.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/SdVolume.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/SPI.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/DateStrings.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/Time.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/TimeAlarms.cpp.o...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/core.a...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/archilog11.elf...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/archilog11.eep...
Creating C:/Users/Ron/Documents/Arduino_Build/archilog11/archilog11.hex...
Binary sketch size: 28,864 bytes (of a 32,256 byte maximum, 89.48%).
Estimated memory use: 1,953 bytes (of a 1,024 byte maximum, 190.72%).
[Stino - Done compiling.]

the empty sketch you asked me without any libs, was indeed only 1000 bytes less.

guess have to take out the libraries one by one from all the sketch to find which one uses the memory

.

Even if you #include files, but don't use the functions/classes declared in them (directly or indirectly) linker should optimize out the code/data.

linker should optimize out the code/data.

Actually, the linker only includes in the hex file those things that are needed. It's a matter of what it puts in, not what it removes from, the hex file that gets uploaded.

I just editted out all time and udp stuff to change with ajax call to server for current time.

however it only gives me 2kb (same result on clean new sketch, my compiler says does cleanup before every compile so guess thats all good).
taking out entire serial library (Serial prints) will give me another 1kb.

the libraries i got left are:

#include #include #include #include

guess ethernet is using it all then

seems ethernet is using at least the 14kb for the w5100.. so maybe using enc28j60 will save me lot of memory, since the library is so much smaller...

since the library is so much smaller

On the other hand, it is much more difficult to use. If you need to buy additional hardware, buy a Mega, instead (or a Due).

Actually, the linker only includes in the hex file those things that are needed. It's a matter of what it puts in, not what it removes from, the hex file that gets uploaded.

In simple case yes, but linker optimizes unreferenced code and data as well to minimize exe size.

rondlite:
I am trying to figure out why a small sketch is already 29kb.
Pretty much assume it is because a lot of libraries seem to get included on compile (they are not in my code however).

#include #include #include #include #include #include #include

A small sketch takes 29kb with this setup. is this normal and can i optimize this?

What small sketch? What board? What IDE version?

How to use this forum

Code tags please, not tags.

Read this before posting a programming question

PaulS:

since the library is so much smaller

On the other hand, it is much more difficult to use. If you need to buy additional hardware, buy a Mega, instead (or a Due).

Yes, well the Due produces larger code.

See: Creating Instances with NEW - Programming Questions - Arduino Forum

Adding a "new" operator added 51Kb to the program size. :slight_smile: