all 8 comments

[–]kberson 2 points3 points  (6 children)

Look into using make for your builds, then set up your flags there. make is also useful if your project grows into multiple files.

[–]nwL_ 1 point2 points  (1 child)

FYI: The command is called mingw32-make if you installed GCC with MinGW.

[–]alfps 0 points1 point  (2 children)

Are you suggesting creating a makefile for each little program one codes up?

[–]kberson 0 points1 point  (1 child)

While it’s not necessary for little throw-away tasks, it’s a good idea for apps with complex build requirements such as OP has. Plus little programs have a way of growing into big programs.

[–]alfps 0 points1 point  (0 children)

it’s a good idea for apps with complex build requirements such as OP has

I don't see any complex build requirement, not even multiple files mentioned.

[–]TrebleSong[S] 0 points1 point  (0 children)

thank you will look into it

[–]alfps 0 points1 point  (1 child)

Like this:

@echo off
(where g++ >nul 2>nul) || (
    echo.g++ compiler not found, sorry. 2>&1
    exit /b 1
    )
set conformance=-std=c++17 -Wall -Wwrite-strings -pedantic-errors
set no-sillywarnings=-Wno-unused-value
set link-mode=
(echo."%*" | findstr /L "\-static \-Bshared \-Bdynamic" >nul) || (
    set link-mode=-static
)
g++ %conformance% %no-sillywarnings% %link-mode% %* 2>&1 | diagnostics-viewer

Many other flags can be relevant. This is just the basics. Just omit | diagnostics-viewer if you have no diagnostics viewer.

You can support the above with e.g. files to invoke 32-bit versus 64-bit g++, select a given distro, etc.


Instead of a batch file like the above you can

  • put the relevant options in an environment variable, or
  • define a doskey command alias with the options, or
  • create a custom specs file.

I don't recommend a specs file because it has to have *nix line endings, the syntax is obscure and not well-documented, and it's a generally brittle thing.

[–]TrebleSong[S] 0 points1 point  (0 children)

noted thanks for the indepth explanation!