I'd like to create a batch file with certain rules - batch-file

Hi I would like to create a bat file that executes the following commands:
avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o battery.o battery.c
avr-gcc -mmcu=atmega328p battery.o -o battery
avr-objcopy -O ihex -R .eeprom battery battery.hex
avrdude -C "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -v -p ATMEGA328P -c arduino -P COM4 -b 57600 -U flash:w:battery.hex:i
I've ran this as a bat but the commands aren't recognized. Should I move to the directories that has the executables first?
The second command always throw an error in a msgbox that doesn't really matter, can it 'ok' the msgbox by itself and carry on to the next command?
Thank you very much.

Why would you expect that to work. It will work if the batch file is in same directory as the files.
ALWAYS SPECIFY FULL PATHS
%windir%\system32\setx
is one way to do it, above is same as
C:\Windows\system32\setx

Related

Error trying to compile C file: mkfifo: cannot create fifo 'stderr': Operation not supported

We are trying to compile this by following instructions in the readme. I must say that we are not specialists with C at all, we are students of a web development bootcamp and trying to do our last project.
It's a command line tool to calculate ephemerides of multiple celestial bodies, and as you can read in the setup in the readme file, it need to download certain data from the internet, and then compile.
All is done through the setup.sh script.
So, we have tried:
In Windows 10 ubuntu WSL terminal
If we type $./setup or $./prettymake, after download the data, gives the error:
$mkfifo: cannot create fifo 'stderr': Operation not supported
$mkdir -p obj obj/argparse obj/coreUtils obj/ephemCalc obj/listTools obj/mathsTools obj/settings
cc -Wall -Wno-format-truncation -Wno-unknown-pragmas -g -c -I /mnt/d/reboot/ephemeris-compute-de430/src -O3 -D DEBUG=0 -D MEMDEBUG1=0 -D MEMDEBUG2=0 -fopenmp -D DCFVERSION=\"2.0\" -D DATE=\"09/06/2019\" -D PATHLINK=\"/\" -D SRCDIR=\"/mnt/d/reboot/ephemeris-compute-de430/src/\" src/ephemCalc/constellations.c -o obj/ephemCalc/constellations.o
If we do it with $sudo ./setup, the error printed is:
$mkfifo: cannot create fifo 'stderr': Operation not supported
$cat: stderr: No such file or directory
$mkdir -p obj obj/argparse obj/coreUtils obj/ephemCalc obj/listTools obj/mathsTools obj/settings
cc -Wall -Wno-format-truncation -Wno-unknown-pragmas -g -c -I /mnt/d/reboot/ephemeris-compute-de430/src -O3 -D DEBUG=0 -D MEMDEBUG1=0 -D MEMDEBUG2=0 -fopenmp -D DCFVERSION=\"2.0\" -D DATE=\"09/06/2019\" -D PATHLINK=\"/\" -D SRCDIR=\"/mnt/d/reboot/ephemeris-compute-de430/src/\" src/ephemCalc/constellations.c -o obj/ephemCalc/constellations.o
In macOS terminal
If we type $./prettymake, gives the error:
$mkdir -p obj obj/argparse obj/coreUtils obj/ephemCalc obj/listTools obj/mathsTools obj/settings
cc -Wall -Wno-format-truncation -Wno-unknown-pragmas -g -c -I /Users/rominaelorrietalopez/Documents/Descargas2/ephemeris-compute-de430-master/src -O3 -D DEBUG=0 -D MEMDEBUG1=0 -D MEMDEBUG2=0 -fopenmp -D DCFVERSION=\"2.0\" -D DATE=\"09/06/2019\" -D PATHLINK=\"/\" -D SRCDIR=\"/Users/rominaelorrietalopez/Documents/Descargas2/ephemeris-compute-de430-master/src/\" src/argparse/argparse.c -o obj/argparse/argparse.o
$clang: error: unsupported option '-fopenmp'
$make: *** [obj/argparse/argparse.o] Error 1
We have tried certain things to no avail, like granting permissions and what not, but have no idea what to do next.
It seems that it have something to do with the prettymake file:
mkfifo stderr
cat stderr | sed 's/\(.*\)/\1/' &
make $# 2>stderr | sed 's/\(.*\)/\1/'
rm stderr
It's like its trying to create a pipe to save the errors of the compilation but somehow it fails.
Also possibly worth of mention, it have a Makefile associated.
Since the github project does not have Issues, we've contacted the creator via email, but well, we thought maybe someone could help us here too.
Any kind of help would be honestly appreciated, thanks.
A comment from the OP invites me to answer; here it is.
The prettymake script creates a named fifo in order to receive the messages produced by make on its standard error.
A background process (cat) consumes the data from this fifo and sends them to a sed command (see right after) in order to transform these data before writing to standard output.
(note that cat is useless here since sed could have directly read from the named fifo thanks to <)
However, the two sed commands as shown in the question don't do anything since they just capture each line of text (\(.*\)) and repeat them unchanged (\1), thus they could have been omitted.
In this case, the script could just contain make $# 2>&1, it would have produced the same effect.
On a system where creating the named fifo is problematic (old version of WSL apparently), this change in the script should produce the same effect as expected.
Looking at the link provided in the question, we can see that the original prettymake script actually contains transformations in the sed commands in order to display standard output and standard error of the make command with different colours.

Cmd cannot run my executable without providing ".exe"

So I have compiled & linked a program called "embed.exe" using mingw gcc compiler but it I am required by cmd to use "embed.exe" instead of "embed" to run it.
D:\c\embed\bin\release>embed
'embed' is not recognized as an internal or external command,
operable program or batch file.
D:\c\embed\bin\release>embed.exe
Usage: embed [-h] <input>
I want to be able to run it by typing "embed" only. This only happens to my program. Yes, the pathext does contain .exe.
So this has made me think there's something wrong with mingw output, as if cmd doesn't recognize that it's an exe if I don't specify .exe.
Here are all my compiler flags:
-std=gnu11 -march=x86-64 -msse3
-Werror -Wall -Wextra -Wno-unused-parameter -Wno-missing-braces
-Wno-missing-field-initializers -Wpedantic -Wno-format
-flto
-g -D_DEBUG -DDEBUG -Og
-Wl,-subsystem,console
Turns out the problem is not with mingw but with how I create the bin directory.
The problem occurs when I use bash on windows to mkdir the directory, but if I use windows' mkdir, it works. Who would've thought...
How to reproduce the error:
Directory:
embed
|-->main.c
Cd to embed directory.
> gcc -c main.c -o main.o
> bash -c "mkdir bin"
> gcc -o bin/embed.exe main.o -Wl,-subsystem,console
> cd bin
> embed
'embed' is not recognized as an internal or external command,
operable program or batch file.
Cd back and delete bin
> mkdir bin
> gcc -o bin/embed.exe main.o -Wl,-subsystem,console
> cd bin
> embed
Usage: embed [-h] <input>
Read up on PATHEXT . . . it is an optional CMD environment variable that will help you here.
In fact, given a *.EXE file isn't working, I'm guessing you might already have that variable and it doesn't include EXE in the list.
Frank

C++ Test Automation using Batch: Specifically how to use Makefile to build .exe for project?

I'm new to using Makefiles and struggling to build an executable file with file extension of .exe.
Currently, this is what I have which fails to build an executable file:
output: main.o user.o item.o transaction.o bid.o
g++ main.o user.o item.o transaction.o bid.o -o output.exe
main.o: main.cpp
g++ -c main.cpp
user.o: user.cpp user.h
g++ -c -std=c++11 user.cpp
item.o: item.cpp item.h
g++ -c -std=c++11 item.cpp
transaction.o: transaction.cpp transaction.h
g++ -c -std=c++11 transaction.cpp
bid.o: bid.cpp bid.h
g++ -c -std=c++11 bid.cpp
clean:
rm *.o output
I want to make a .exe file because I am creating a batch script to do automated testing of my program. When I create a batch script I try the following in my runTest.bat file:
cd ../../
make
./output current_User_Accounts_File.uaf available_Items_File.ai daily_Transaction_File.tra < Test_Cases/login/login1.in
pause
Problem is I would regularly use bash to execute my program by typing ./ followed by the executable. Using batch file it does not recognize ./ which is why I want to try building .exe file instead. Any help or suggestions is appreciated.
Is there a better strategy to approach this? I have to automate multiple test cases where I take in inputs. When taking the approach of creating .sh scripts instead I run into other conflicts. What are some recommended ways to do automated test scripts for c++?
Here:
g++ main.o user.o item.o transaction.o bid.o -o
the -o option expects the name of the output file, in this case the executable. So:
g++ main.o user.o item.o transaction.o bid.o -o something
or:
g++ main.o user.o item.o transaction.o bid.o -o something.exe
And this is pure GCC/makefile/bash syntax, and nothing particularly to do with the C++ language, so I'm removing that tag.
Windows cmd.exe and most windows programs do not automatigically convert the forward-slash to back-slash. Change ./output ... to output.exe and it should work fine. The .\ would just be redundant anyway.

cscope: -c or -T mismatch between command line and old symbol database

I'm trying to create tags for *.c, *.x and *.h files.
These are the following commands which I executed.
find <absolute_path_of_code> -name *.c -o -name *.x -o -name *.h > cscope.files
cscope -bkqc cscope.files
Till here everything is ok.
But after this when I execute the command,
cscope -Rb
I get the following message at console.
cscope: -c or -T option mismatch between command line and old symbol database
How do I resolve this?
If you generate a database using the -c or -T options (you use -c in your original command) you are required to pass those options to every subsequent invocation of cscope. Just add -c to your second command (making it cscope -Rbc) and it should work.
cscope -Rb generates only cscope.out file but cscope -bkqc -I cscope.files generates cscope.in.out, cscope.po.out and cscope.out. So there is no need to execute cscope -Rb.

GDB doesn't find sources

I start gdb using this (working dir is /home/leon/Develop/tests/atomic/):
gdb ./bin/lin64/httpress
Then I add directories with source files, and it understands me:
Source directories searched: /home/leon/Develop/tests/atomic/third/http_parser:/home/leon/Develop/tests/atomic/src/tools:$cdir:$cwd
When I run my binary, gdb doesn't recognize the line in my source code, where segfault happened.
How to set source files for gdb?
The program is compiled by gcc:
gcc -D_AMD64_ -D_LIN_ -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -m64 -march=core2 -O2 -Wall -I. -I src/include -I src/lib/zlib/ -I src/lib/otg -I third/openssl/include/ -I src/lib/otg/Tools/HostTime/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Cross -I src/lib/otg/Tools/OpenToolsGate/Common/Interfaces/ -o bin/lin64/httpress -std=c99 -lpthread -lev -lgnutls -O2 -s -DWITH_SSL -Wno-strict-aliasing \
-I /usr/include/libev src/tools/httpress.c -I third/http_parser/ third/http_parser/http_parser.c
Ok, I've made some changes:
gcc -g -ggdb -D_AMD64_ -D_LIN_ -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -m64 -march=core2 -Wall -I. -I src/include -I src/lib/zlib/ -I src/lib/otg -I third/openssl/include/ -I src/lib/otg/Tools/HostTime/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Cross -I src/lib/otg/Tools/OpenToolsGate/Common/Interfaces/ -o bin/lin64/httpress -std=c99 -lpthread -lev -lgnutls -s -DWITH_SSL -Wno-strict-aliasing \
-I /usr/include/libev src/tools/httpress.c -I third/http_parser/ third/http_parser/http_parser.c
In this case it still can't find symbols in the binary.
But if I remove -s option from gcc call. It writes:
Reading symbols from /home/leon/Develop/tests/atomic/bin/lin64/httpress...done.
But the debugger still says this:
(gdb) info source
No current source file.
...after I point him directories with sources.
You miss the -g in your gcc call to include debugging information.
On the other hand, I suggest to decrease optimization level from -O2 to -O0 and use it only once (included gcc call has 2 -O2).
Apart of this, you can add directories to gdb's source path with dir command: Source_Path. But this would only work if you've proper debug information available in httpress
But the debugger still says this:
(gdb) info source
No current source file.
...after I point him directories with sources.
This is expected. There is no current source because you haven't started executing your binary yet.
You want to start or run your binary and get it to some place in execution (e.g. main, or the crash point).
Remove optimize flag :
-O2
And add that flags:
-g -ggdb

Resources