On windows 10, how to get gcc to compile from standard input - windows

I've seen this post that tells how to get gcc to compile from standard input (type file.c | gcc -x c -):
Is it possible to get GCC to read from a pipe?
But it does not work on windows 10. I always get "The system cannot find the file specified" in spite of having tried it every way I can imagine.
Anyone know the trick?
And I can't change the version of gcc we're using (I've heard standard input compile with gcc in mingw works on windows).

My own example works just fine. It was my mistake!

Related

How can I compile the Linux Kernel getting the output of the preprocessor too?

I know that with gcc -E you can get the output of the preprocessor, but what I have to do to get that output for every source code file in the Linux Lernel as part of the compilation process?

GCC ver 7.3.0 preprocessor fails if output file doesn't exist

I tried to build the FreeIPMI on a box with GCC 7.3.0 and got stuck - the preprocessor complained that output file was missing:
nekto#ubuntu:~/freeipmi-1.6.1/man$ /usr/bin/cpp -nostdinc -w -C -P -I../man libipmiconsole.3.pre libipmiconsole.3
cpp: error: libipmiconsole.3: No such file or directory
That's output file, its existence shouldn't be checked I think.
BTW, the same command worked flawlessly on another box with GCC 6.
Is it issue with the GCC 7.3.0 preprocessor?
I'm answering my own question.
The invocation format for the GCC 7.3.0 preprocessor has been changed - the output filename has to be prepended by the -o option, and all the free-standing filenames on the command line are considered input files.
Also the preprocessor became more strict about input formats it supports, so it can't be used to generate man-pages for the FreeIPMI anymore.

Why compiling a program produces a file that is not executable?

I am using g95 to compile a fortran code. I use
C:\MinGW\bin>g95.exe -c C:\test\coil.f -o C:\test\coil.exe
It compiles and gives coil.exe which is created as 16 bit application so when ever I try to run this executable it throws an incompatibility error. I am using windows 7 64bit. I think by default it goes to 16 bit. Is there a way to get 64 bit in place of 16bit?
If you want to obtain an executable, compile it as follows:
g95.exe C:\test\coil.f -o C:\test\coil.exe
, i.e. without the -c switch. With -c you are getting an object file (.obj) which is not supposed to be executed.
From the comment by #DmitriChubarov

Is there an easy way to COLOR-CODE the compiler outputs?

gcc (or other compilers) often generate huge text output and it's very difficult to see where the error is or miss warnings. I've done some search but havn't found a clean simple solution to color code the compiler output (so for instance warnings are yellow, errors are red, etc...)
Gcc 4.9 seems to have added this feature via the -fdiagnostics-color flag:
here's an alternative if you are looking for something very simple:
#!/bin/bash -e
make ${#} 2>&1 | perl -wln -M'Term::ANSIColor' -e '
m/Building|gcc|g++|\bCC\b|\bcc\b/ and print "\e[1;32m", "$_", "\e[0m"
or
m/Error/i and print "\e[1;91m", "$_", "\e[0m"
or
m/Warning/i and print "\e[1;93m", "$_", "\e[0m"
or
m/Linking|\.a\b/ and print "\e[1;36m", "$_", "\e[0m"
or
print; '
Just alias your make to this script and make sure it's executable...
Debian and Ubuntu gives the colorgcc package for that purpose.
And I usually run gcc (and make) thru emacs with M-x compile then the messages are colorized.
addenda
GCC 4.9 has a native colorization facility and GCC 6 - released end of April 2016 - (and probably GCC 5 too) is enabling it by default (when stdout is a terminal).
Ok, I'll just leave a notice about my own (python based) tool also :)
It is called Pluggable Output Processor and designed not only to colorize output of one particular program. Here is sample GCC output before:
After:
See colorgcc, a perl script that coulours the gcc output.
How to install and use colorgcc to colorize your gcc compiler output:
At least 3 answers here so far mention colorgcc, but NONE OF THEM EXPLAIN HOW TO INSTALL IT! (And it's not obvious). So, here's how to install the latest version in Ubuntu!
Go here and click "Clone or download" --> "Download Zip". I saved it into "~/Downloads/Install_Files"
Navigate to it in your file browser and right click it and go to "Extract Here." I now have a directory called "~/Downloads/Install_Files/colorgcc-master".
Copy the "colorgcc.pl" script to "/usr/bin/colorgcc" to "install" it (be sure to use the correct directory according to where you extracted it above): sudo cp ~/Downloads/Install_Files/colorgcc-master/colorgcc.pl /usr/bin/colorgcc
Make it executable: sudo chmod +x /usr/bin/colorgcc
Make the "~/bin" directory if it does not yet exist: mkdir ~/bin
*Make symbolic links that point to "/usr/bin/colorgcc" so that whenever you call gcc or g++ it automatically calls colorgcc instead:
ln -s /usr/bin/colorgcc ~/bin/g++
ln -s /usr/bin/colorgcc ~/bin/gcc
(if you ever want to uninstall colorgcc for some reason just delete these symbolic links "~/bin/g++" and "~/bin/gcc", and the Perl script: "/usr/bin/colorgcc" and you're done)
Done!
Here is a sample g++ output now when I call g++ -Wall -std=c++11 time_until_overflow_2.cpp -o time_until_overflow_2:
*Note: making these symbolic links in "~/bin" only works if "~/bin" is in your PATH variable in a location before the folder where the actual gcc and g++ executables are located. To ensure you have "~/bin" in your path you can view the PATH variable contents with: echo $PATH. If you don't see "/home/YOUR_USERNAME/bin" at the beginning of your path, add it with: export PATH=~/bin:$PATH.
References:
See here for more info. and for where I originally learned most of these steps: https://imranfanaswala.wordpress.com/2009/02/02/setting-up-colorgcc/. Thanks Imran Fanaswala!
~GS
you can use GilCC which is a Ruby tool that will convert GCC output to color in real-time. Right now you have two choices: Perl script (colorGCC) or GilCC and if you already work with Ruby you will like GilCC.
Unique to GilCC; GilCC has warning and errors counters and also shows compile time, very handy when you are trying to improve things. Because it is in Ruby it is cross platform. It is flexible and you can add more gems to customize it anyway you want.
The link to the download page is here.
https://github.com/gilmotta/GilCC
Although GCC 4.9 has -fdiagnostics-color option to enable colored outputs to terminals, I have created a tiny tool called 'crror' to get colorized compiler output.
It supports outputs from make as well. I can add colorize patterns for other tools if anyone requires.

Color gcc output on mac 10.6.8?

I've heard of colorgcc for coloring gcc outputs on the command line, but I can't find documentation on how to get this working on a mac (if it even does?). I'm not really willing to switch to an IDE, so If there are any alternatives for gcc coloring output that would be awesome.
Thanks

Resources