Question

On Linux Mint 19 with C++ compiler version: g++-8 (...) 8.2.0

I am compiling and running my project named: getPixelColor


Using a shell script:

#!/bin/sh
g++-8 -std=c++17 -Wall -Wextra -Werror -Wpedantic -pedantic-errors -o getPixelColor getPixelColor.cpp -lX11 && ./getPixelColor "${@}"

Finally, I defined a personal alias:

alias work-pixel='watch -n 1 /home/vlastimil/Development/getPixelColor/cpp/compileRun 0 0'

And work inside Visual Studio Code like that:

VS Code with Terminal


Question

Did I streamline the development process to 100%, or is there yet some space for improvements?

Was it helpful?

Solution

Thanks to GrandmasterB, I realized that for C++ projects, it is ordinary to add Makefile to make things even easier and streamlined.


Makefile

This is quite new to me. I like the way things get dependent there. Awesome way to go.

COORDS ?= 0 0

CXX := g++-8
CXXFLAGS := -std=c++17 -Wall -Wextra -Werror -Wpedantic -pedantic-errors
LDLIBS := -lX11
RM := rm -f

BIN := getPixelColor
SRC := $(BIN).cpp

$(BIN): $(SRC)
    $(CXX) $(CXXFLAGS) $(SRC) -o $(BIN) $(LDLIBS)

.PHONY: clean
clean:
    $(RM) $(BIN)

.PHONY: run
run: $(BIN)
    ./$(BIN) $(COORDS)

compileRun (POSIX shell script)

This file serves for an infinite loop of constant (compiling and) running the with signal failsafes. Can be given X, Y coordinates optionally.

#!/bin/sh

set -o nounset

trap 'cleanup' HUP INT QUIT ABRT TERM

cleanup()
{
    printf '\n%s\n' 'Cleaning up... Exiting.' 1>&2
    make -s clean
    exit 1
}

while true
do
    clear
    make -s clean

    if [ "${#}" -eq 2 ]
    then
        COORDS="${*}" make run
    else
        make run
    fi

    sleep 5s
done

It looks neater now. Thank you for guidance!

Licensed under: CC-BY-SA with attribution
scroll top