Page 1 of 1

[RESOLVE] Sketch with multiple files

Posted: 13 Jan 2017 20:39
by Chiquitoloco
Hi,

i was wondering if we can compil a sktech with multiple files as

main.ino
functions.h
myFunctions.cpp

main.ino :

Code: Select all

#include "functions.h"
void loop {
test();
}
functions.h :

Code: Select all

void test();
myFunctions.cpp :

Code: Select all

void test(){
}
because when i try to compil there is the debug :

Code: Select all

Preprocessing file: Print.cpp with SDCPP... 
Compiling Print_sdcpp_.cpp ...
Preprocessing file: Stream.cpp with SDCPP... 
Compiling Stream_sdcpp_.cpp ...
Preprocessing file: HardwareSerial.cpp with SDCPP... 
Compiling HardwareSerial_sdcpp_.cpp ...
Preprocessing file: HLCore.cpp with SDCPP... 
Compiling HLCore_sdcpp_.cpp ...
Preprocessing file: _main.cpp with SDCPP... 
Compiling _main_sdcpp_.cpp ...
Preprocessing file: Print.cpp with SDCPP... 
Compiling Print_sdcpp_.cpp ...
Preprocessing file: Stream.cpp with SDCPP... 
Compiling Stream_sdcpp_.cpp ...
Preprocessing file: HardwareSerial.cpp with SDCPP... 
Compiling HardwareSerial_sdcpp_.cpp ...
Preprocessing file: HLCore.cpp with SDCPP... 
Compiling HLCore_sdcpp_.cpp ...
Preprocessing file: _main.cpp with SDCPP... 
Compiling _main_sdcpp_.cpp ...Compiling file "LLCore_arduino.c" by means of SDCC...
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_MODEL_LARGE -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=3_5_0 -DSDCC=350 -D__SDCC_REVISION=9253 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include\mcs51" -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include"  "LLCore_arduino.c" 
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdas8051.exe -plosgffw "LLCore_arduino.rel" "LLCore_arduino".asm
LLCore_arduino.c:25: warning 85: in function NOPS unreferenced function argument : 'i'
LLCore_arduino.c:218: warning 85: in function delayLoops unreferenced function argument : 'v'
Compiling file "Print_ucxx.c" by means of SDCC...
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_MODEL_LARGE -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=3_5_0 -DSDCC=350 -D__SDCC_REVISION=9253 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include\mcs51" -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include"  "Print_ucxx.c" 
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdas8051.exe -plosgffw "Print_ucxx.rel" "Print_ucxx".asm
Compiling file "Stream_ucxx.c" by means of SDCC...
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_MODEL_LARGE -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=3_5_0 -DSDCC=350 -D__SDCC_REVISION=9253 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include\mcs51" -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include"  "Stream_ucxx.c" 
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdas8051.exe -plosgffw "Stream_ucxx.rel" "Stream_ucxx".asm
Compiling file "HardwareSerial_ucxx.c" by means of SDCC...
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_MODEL_LARGE -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=3_5_0 -DSDCC=350 -D__SDCC_REVISION=9253 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include\mcs51" -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include"  "HardwareSerial_ucxx.c" 
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdas8051.exe -plosgffw "HardwareSerial_ucxx.rel" "HardwareSerial_ucxx".asm
Compiling file "HLCore_ucxx.c" by means of SDCC...
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_MODEL_LARGE -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=3_5_0 -DSDCC=350 -D__SDCC_REVISION=9253 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include\mcs51" -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include"  "HLCore_ucxx.c" 
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdas8051.exe -plosgffw "HLCore_ucxx.rel" "HLCore_ucxx".asm
Compiling file "_main_ucxx.c" by means of SDCC...
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_MODEL_LARGE -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=3_5_0 -DSDCC=350 -D__SDCC_REVISION=9253 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include\mcs51" -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include"  "_main_ucxx.c" 
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdas8051.exe -plosgffw "_main_ucxx.rel" "_main_ucxx".asm

?ASlink-Warning-Undefined Global '_test' referenced by module '_main_ucxx'
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_MODEL_LARGE -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=3_5_0 -DSDCC=350 -D__SDCC_REVISION=9253 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include\mcs51" -isystem "C:\Users\chiquito\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.20\zuno_toolchain/sdcc/\bin\..\include"  "C:\Users\chiquito\AppData\Local\Temp\build8529676853814033870.tmp/main.c" 
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdas8051.exe -plosgffw "main.rel" "main".asm
sdcc: Calling linker...
sdcc: sdld.exe -nf "main.lk"
Error. SDCC returned: 1

Erreur lors de la compilation.
and mostly this line

Code: Select all

?ASlink-Warning-Undefined Global '_test' referenced by module '_main_ucxx'

Re: Sketch with multiple files

Posted: 14 Jan 2017 02:47
by jucs
I does work with my library hack using the Makefile... I didn't find any other way.

Re: Sketch with multiple files

Posted: 14 Jan 2017 16:23
by PoltoS
It works out of the box. Place in your folder any other .c file and with SAME name .h file. Include this .h file in the .ino and Arduino IDE will undertsand that it should also compile the .c file having same name as .h file.

Re: Sketch with multiple files

Posted: 16 Jan 2017 18:08
by Chiquitoloco
the Poltos's technic work well.

But how to do if i want use more than 1 *.cpp files?

In my sketch (before for arduino Uno) i have a *.cpp per sensor. This way i can separate my code and it's more readable. After i join all *.cpp in the file functions.h

My sketch is like that

main.ino
functions.h
dht.cpp
lux.cpp
pir.cpp
...

Re: Sketch with multiple files

Posted: 16 Jan 2017 21:20
by michap
you need for each file a *.c and *.h file, then it will be taken.

functions.h + functions.c
dht.h + dht.cpp
lux.h + lux.cpp
pir.h + pir.cpp

Michael

Re: Sketch with multiple files

Posted: 17 Jan 2017 15:27
by jucs
Ah, that may have been my problem as well :-) I'll try it too!

Re: Sketch with multiple files

Posted: 17 Jan 2017 19:46
by Chiquitoloco
I'm ok with you, but with this way, it'll be messy in the code after.

Will be good to compil as a arduino programmer.

Poltos, do you think to plan this functionnality in futur release?

Re: Sketch with multiple files

Posted: 18 Jan 2017 04:05
by PoltoS
What function exactly do you want?

Re: Sketch with multiple files

Posted: 18 Jan 2017 10:54
by Chiquitoloco
the possibility to compile 1 .h file with multiples *.cpp file

Like that
main.ino
functions.h
dht.cpp
lux.cpp
pir.cpp
rather than
functions.h + functions.c
dht.h + dht.cpp
lux.h + lux.cpp
pir.h + pir.cpp

Re: Sketch with multiple files

Posted: 19 Jan 2017 01:17
by PoltoS
We need to instruct IDE which .cpp file to take. This is the Arduino style. But on the underlying layers Z-Uno can compile using the classical style too. May be in future we will add it to IDE too.