[RESOLVE] Sketch with multiple files

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
Chiquitoloco
Posts: 17
Joined: 11 Sep 2016 11:26

[RESOLVE] Sketch with multiple files

Post by Chiquitoloco » 13 Jan 2017 20:39

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'
Last edited by Chiquitoloco on 03 Feb 2017 17:27, edited 1 time in total.

jucs
Posts: 35
Joined: 28 Dec 2016 17:56

Re: Sketch with multiple files

Post by jucs » 14 Jan 2017 02:47

I does work with my library hack using the Makefile... I didn't find any other way.

User avatar
PoltoS
Posts: 5101
Joined: 26 Jan 2011 19:36

Re: Sketch with multiple files

Post by PoltoS » 14 Jan 2017 16:23

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.

Chiquitoloco
Posts: 17
Joined: 11 Sep 2016 11:26

Re: Sketch with multiple files

Post by Chiquitoloco » 16 Jan 2017 18:08

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
...

michap
Posts: 343
Joined: 26 Mar 2013 10:35
Contact:

Re: Sketch with multiple files

Post by michap » 16 Jan 2017 21:20

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

jucs
Posts: 35
Joined: 28 Dec 2016 17:56

Re: Sketch with multiple files

Post by jucs » 17 Jan 2017 15:27

Ah, that may have been my problem as well :-) I'll try it too!

Chiquitoloco
Posts: 17
Joined: 11 Sep 2016 11:26

Re: Sketch with multiple files

Post by Chiquitoloco » 17 Jan 2017 19:46

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?

User avatar
PoltoS
Posts: 5101
Joined: 26 Jan 2011 19:36

Re: Sketch with multiple files

Post by PoltoS » 18 Jan 2017 04:05

What function exactly do you want?

Chiquitoloco
Posts: 17
Joined: 11 Sep 2016 11:26

Re: Sketch with multiple files

Post by Chiquitoloco » 18 Jan 2017 10:54

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

User avatar
PoltoS
Posts: 5101
Joined: 26 Jan 2011 19:36

Re: Sketch with multiple files

Post by PoltoS » 19 Jan 2017 01:17

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.

Post Reply