Windows command line build

@aerodyno: Thanks, I'll try to fix the Skydrive link.

Not sure why the .BAT files aren't working. The errors about not being able to find the .h files sounds like it could be a problem with the PATH or one of the environment variables.

Try running abuild.bat with the -v option (verbose) and see if the output messages offer any further clues. You can also try posting the verbose output here.

Thanks,
David

Hi David,

Thanks for your response and your offer to help!

I was just writing a long post to you, but using -v and building a simple "BlinkWithoutDelay.pde" helped me find my error. I had an extra SPACE after one of the paths I edited in agetpref, and that was ruining everything.

I'm now going to try with full sketch and original files, I'll come back here if it doesn't work. :slight_smile:

Thanks again,
aerodyno

Use this with an AVR ISP MKII?

How hard would it be to command-line program the arduino AND use the AVR ISP MKII programmer? I have already configured the IDE to use the AVR ISP MKII, so I don't need to burn the Arduino bootloader:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1275160256

How would I go about making this change // is it possible?

Thanks,
Aero

EDIT: 7/28/2010
By Adding "build.verbose=true" and "upload.verbose=true" to the preferences file, I was able to see what the IDE was doing... So I then made the necessary modifications to the abuild and aupload scripts. So yes, I'm using the build scripts and uploading via my avr isp mkII programmer. Nice!!!!

So I'm trying to build the built-in Arduino-0018 DateTime example.

After adding function headers for the functions in this file, I run abuild.bat -c DateTime.pde (in the same dir as that file, along with the 4 batch files) and I get repeated "undefined reference to DateTime". Any help or advice would be appreciated. I'm so close. It looks like I just need to get libraries working, and then the avrispmkII stuff, and I'm all set for what I need.

Thanks!
Aero

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\wv>cd Desktop

C:\Documents and Settings\wv\Desktop>cd wv-cmd

C:\Documents and Settings\wv\Desktop\wv-cmd>asetpref
ARDUINO_BURNRATE=19200
ARDUINO_COMPORT=COM7
ARDUINO_FCPU=16000000
ARDUINO_MCU=atmega328p
ARDUINO_PATH=C:\Documents and Settings\wv\Desktop\arduino-0018
ARDUINO_PROGRAMMER=stk500
C:\Documents and Settings\wv\Desktop\wv-cmd>abuild -c DateTime.pde
.\obj\DateTime.pde.cpp.o: In function `digitalClockDisplay()':
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:62: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:63: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:64: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:66: undefined reference to `DateTimeStrings'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:66: undefined reference to `DateTimeStrings'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:66: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:66: undefined reference to `DateTimeStringsClass::dayStr(unsigned char)'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:68: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:68: undefined reference to `DateTimeStringsClass::monthStr(unsigned char)'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:70: undefined reference to `DateTime'
.\obj\DateTime.pde.cpp.o: In function `getPCtime()':
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:53: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:53: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:53: undefined reference to `DateTimeClass::sync(unsigned long)'
.\obj\DateTime.pde.cpp.o: In function `loop':
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:24: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:24: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:24: undefined reference to `DateTimeClass::now()'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:26: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:26: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:26: undefined reference to `DateTimeClass::available()'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:28: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:28: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:28: undefined reference to `DateTimeClass::now()'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:29: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:29: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:29: undefined reference to `DateTimeClass::now()'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:31: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:31: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:31: undefined reference to `DateTimeClass::available()'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:36: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:36: undefined reference to `DateTime'
C:\Documents and Settings\wv\Desktop\wv-cmd/obj/DateTime.pde.cpp:36: undefined reference to `DateTimeClass::now()'
.\obj\arduino_runtime_atmega328p_withlibs.a(Print.cpp.o):(.data+0x6): undefined reference to `__cxa_pure_virtual'

C:\Documents and Settings\wv\Desktop\wv-cmd>

So here's a change I found, that gets me a step closer:

If you are using arduino 0018,
Line 251 of abuild.bat should be

      for /D %%d in ("!arduino_path!\libraries\*.*") do (

instead of

      for /D %%d in ("!arduino_path!\hardware\libraries\*.*") do (

I was also getting this error:

abuild -c DateTime.pde
.\obj\arduino_runtime_atmega328p_withlibs.a(Print.cpp.o):(.data+0x6): undefined reference to `__cxa_pure_virtual'

I searched google for it, dropped this line into DateTime.pde and now it works:
extern "C" void __cxa_pure_virtual() { while (1); }
reference: c++ - What is the purpose of __cxa_pure_virtual? - Stack Overflow

So now I am successfully able to build DateTime.pde (a sample) using abuild.bat.

Yup, I played around with this quite a bit last night. I also hit the __cxa_pure_virtual problem, but decided to get some sleep (sometimes this hobby is too much like my day job ;)).

Thanks for posting the solution - I'll check out the reference to understand what's causing it. I wonder if tweaking the avr-gcc / avr-g++ command line options might fix that?

-David

Cool. I managed to get what I want working, but the scripts are pretty custom to what I'm doing now. If the main scripts posted on the website will get updated, I'll help out with that.

I finally got the command line to work from windows!!!!

Here are all the steps to make it work.

  1. My avrdude.exe was crashing because I had an old winavr path in my windows environment “PATH” variable which had an old version of avrdude.exe; so I just removed that from my path. I guess my winavr will not work but I can set that up again some other day.

  2. I downloaded the new Arduino 19

  3. I followed the install steps at arduino playground WindowsCommandLine:

a) I put the three new downloaded text files in this path on my box:

C:\Documents and Settings\Admin\My Documents\Electronics\Arduino\Arduino command line

b) I edited these two files before renaming them to as *.bat files:
IN agetpref.txt
Change:
set arduino_runtime=!arduino_path!\hardware\cores\arduino
to:
set arduino_runtime=!arduino_path!\hardware\arduino\cores\arduino

IN abuild.txt
change:
set abuild_include_paths_root=!arduino_path!\hardware\libraries
to:
set abuild_include_paths_root=!arduino_path!\libraries

change:
for /D %%d in ("!arduino_path!\hardware\libraries*.") do (
to:
for /D %%d in ("!arduino_path!\libraries*.
") do (

  1. My COM port for my Arduino was seen as COM7 and I went into the windows device manager and changed the baud rate to 56700 (I'm not sure you have to do this but I wanted everything set to 56700 baud so I did).

  2. I used these values for my new windows environment variables.

FIRST NOTE: I have the Arduino Duemilanove. If your board is different you will have to alter the ARDUINO_MCU environment variable.

SECOND NOTE: The ARDUINO_PROGRAMMER = stk500v1 is very important!

a) I added this to the front of my windows “PATH” environment variable:

C:\Documents and Settings\Admin\My Documents\Electronics\Arduino\Arduino command line;

b) Other environment variables added per the wiki instruction:

ARDUINO_PATH=C:\Documents and Settings\Admin\My Documents\Electronics\Arduino\Arduino IDE-0019

ARDUINO_MCU=atmega328p

ARDUINO_PROGRAMMER=stk500v1

ARDUINO_FCPU=16000000

ARDUINO_COMPORT=COM7

ARDUINO_BURNRATE=57600

  1. I opened a command line window and changed to the folder that has my blink sketch example.

cd C:\Documents and Settings\Admin\My Documents\Electronics\Arduino\My Projects\Duemilanove_ATmega328\Blink

  1. Type this to compile and upload the sketch to the Arduino board:

abuild Blink.pde

a) It first compiles the sketch in the obj sub-folder then asked if you want to upload
b) I type 'u' for upload and I DID NOT push the rest button on the Arduino; it seemed to send the reset command over the USB cable via the COM driver.

That's it, it worked for me.

Below is what I seen in the command window after the upload was complete.

abuild.bat: Successfully built .\obj\Blink.pde.rom
abuild.bat: Successfully built .\obj\Blink.pde.hex
text data bss dec hex filename
0 1298 0 1298 512 .\obj\Blink.pde.hex

[Remember to reset your board right before uploading.]
Enter the first character of your choice...
Upload, Quit? u

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file ".\obj\Blink.pde.hex"
avrdude: input file .\obj\Blink.pde.hex auto detected as Intel Hex
avrdude: writing flash (1298 bytes):

Writing | ################################################## | 100% 0.67s

avrdude: 1298 bytes of flash written
avrdude: verifying flash memory against .\obj\Blink.pde.hex:
avrdude: load data flash data from input file .\obj\Blink.pde.hex:
avrdude: input file .\obj\Blink.pde.hex auto detected as Intel Hex
avrdude: input file .\obj\Blink.pde.hex contains 1298 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.59s

avrdude: verifying ...
avrdude: 1298 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.

aupload.bat: exiting with return code 0

David (dab),

Could you please post another link for the batch files if they differ to those on the playground page? I'm not able to compile my code though it builds and uploads fine in the IDE.

The files are the same. Just follow the instruction on the playgound page then follow my instructions to change the bat files with a text editor like notepad. Should work if you follow all the instruction and make my changes to the bat files. I didn't change anything else.

OK, I worked it out.

I had to add declarations for all my functions in to the .pde file, much like the script adds the include for Wprogram.h

I then also had to add an additional function:

extern "C" void __cxa_pure_virtual() { while (1); }

which is needed by some of the other libraries. Perhaps the batch file should also include this as it's not going to use up a huge amount of codespace. If I include this function and compile with the IDE it returns an error.

The problem I now have is that this is building EVERY library (ethernet, onewire, lcd, servo, etc) and my compiled .hex file is 47K!

It seems like there's a lot more going on "behind the scenes" within the IDE prior to the compilation, and it's only building libraries that are mentioned in the code. I'm not sure if it's possible for the batch file to check for "includes" and then only compile with those libraries.

Is there a final set of files available that work with 19 or 20?