0

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?

closed as primarily opinion-based by amon, Doc Brown, Nicol Bolas, Bart van Ingen Schenau, Blrfl Mar 3 at 12:12

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I don't think there's a "correct" answer. It seems to be working for you, so yes. You might consider trying a simple make file next instead of the shell script, just for learning purposes. – GrandmasterB Mar 2 at 8:02
  • You may want to setup VSC in a way you can start the build process by a shortcut, and in case of compiling errors, it shows you directly the place of errors. See this SO post. – Doc Brown Mar 3 at 7:18
  • @DocBrown I did not know that, thank you for the tip! – Vlastimil Mar 3 at 7:22
1

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!

  • Make file looks good! – GrandmasterB Mar 3 at 4:54
  • 1
    @GrandmasterB Thank you! I've done maybe too many edits already. I hope it's fine now. – Vlastimil Mar 3 at 6:29
  • You're welcome! Looks like you got it. – GrandmasterB Mar 3 at 6:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.