make: g++: Command not found - c++

I've checked similar posts and anyone solve my problem. I's very simple but I'm new with eclipse. I'm trying to make a simple example and I'm having this problem.
the make file is just this
all: hello.exe
clean:
rm Hello.o Hello.exe
hello.exe: hello.o
g++ -g -o hello.exe hello.o
hello.o:
g++ -c -g main.cpp
And I get this error "make: g++: Command not found"
Thanks for helping.

You need to install the development tools from GNU. I assume you're on windows, in which case you have two options: cygwin and mingw. The former includes g++ out of the box. I'm less familiar with mingw, but the C++ Standard library appears to, also, be available.
See these installation instructions, I'd recommend starting from step 1, if at all possible.

"sudo apt install g++" did the trick for on on Ubuntu 20 LTS.

Adding for RHEL users, installing development tools resolved the issue on rhel.
Command:
yum groupinstall 'Development Tools'

Related

How to compile custom cpp files on Google Colab

I'm trying to replicate the result of this github repo using Google Colab since I don't want to install all the requirements on my local machine and to take advantage of the GPU on Google Colab
However, one of the things I need to do (as indicated in the repo's README) is to first compile a cpp makefile. The instruction of the makefile is included below. Obvious I can't follow this instruction since I don't know Google Colab's directories of ncvv, cudalib and tensorflow library
cd latent_3d_points/external
with your editor modify the first three lines of the makefile to point to
your nvcc, cudalib and tensorflow library.
make
Is there a way for me to compile the files included in the makefile (because those functions are needed to run the model) either using the makefile directly or compile each cpp file individually? I included the content of the makefile below to avoid having you to click around in the repo looking for it
nvcc = /usr/local/cuda-8.0/bin/nvcc
cudalib = /usr/local/cuda-8.0/lib64
tensorflow = /orions4-zfs/projects/optas/Virt_Env/tf_1.3/lib/python2.7/site-packages/tensorflow/include
all: tf_approxmatch_so.so tf_approxmatch_g.cu.o tf_nndistance_so.so tf_nndistance_g.cu.o
tf_approxmatch_so.so: tf_approxmatch_g.cu.o tf_approxmatch.cpp
g++ -std=c++11 tf_approxmatch.cpp tf_approxmatch_g.cu.o -o tf_approxmatch_so.so -shared -fPIC -I $(tensorflow) -lcudart -L $(cudalib) -O2 -D_GLIBCXX_USE_CXX11_ABI=0
tf_approxmatch_g.cu.o: tf_approxmatch_g.cu
$(nvcc) -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -c -o tf_approxmatch_g.cu.o tf_approxmatch_g.cu -I $(tensorflow) -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2
tf_nndistance_so.so: tf_nndistance_g.cu.o tf_nndistance.cpp
g++ -std=c++11 tf_nndistance.cpp tf_nndistance_g.cu.o -o tf_nndistance_so.so -shared -fPIC -I $(tensorflow) -lcudart -L $(cudalib) -O2 -D_GLIBCXX_USE_CXX11_ABI=0
tf_nndistance_g.cu.o: tf_nndistance_g.cu
$(nvcc) -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -c -o tf_nndistance_g.cu.o tf_nndistance_g.cu -I $(tensorflow) -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2
clean:
rm tf_approxmatch_so.so
rm tf_nndistance_so.so
rm *.cu.o
You can use the bash like on your pc by adding %%bash in the colab's cells.
Example:
Cell one: write cpp file
%%writefile welcome.cpp
#include <iostream>
int main()
{
std::cout << "Welcome To AI with Ashok's Blog\n";
return 0;
}
Cell two: compile and run
%%bash
g++ welcome.cpp -o welcome
./welcome
You can also open the cpp file in colab's build-in text editor in order to enjoy correct highlights. It opens when you open a text file from the "Files" tab on the left and can be save with "ctr+s" shortcut.
You can install the required version of Cuda in google colab. For eg.
For Cuda 9.2 you can try
!apt-get --purge remove cuda nvidia* libnvidia-*
!dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 dpkg --purge
!apt-get remove cuda-*
!apt autoremove
!apt-get update
!wget https://developer.nvidia.com/compute/cuda/9.2/Prod/local_installers/cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64 -O cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb
!dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb
!apt-key add /var/cuda-repo-9-2-local/7fa2af80.pub
!apt-get update
!apt-get install cuda-9.2
Similarly, you can find a way to install Cuda 8.2.
For gcc
!apt-get install -qq gcc-5 g++-5 -y
!ln -s /usr/bin/gcc-5
!ln -s /usr/bin/g++-5
!sudo apt-get update
!sudo apt-get upgrade
Then you can compile it or make it by running make, if your installation has a custom make file.
!make

While installing on OSX Sierra via gcc-6, keep having "FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!" error

Environment info
Operating System:
macOS 10.12.2 (16C68)
Compiler:
gcc-6
Steps to reproduce
I've installed gcc-6 and modified config.mk as required into
export CC = gcc-6
export CXX = g++-6
But keep having this error:
g++-6 -c -std=c++0x -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -O3 -funroll-loops -msse2 -fPIC -fopenmp src/learner.cc -o build/learner.o
FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
What have you tried?
Reinstall XCode
Reinstall gcc
Run make clean_all && make -4j
But still went wrong. Any idea?
I had this issue when using macports-installed gnu assembler. You could try forcing the use of as that comes with Xcode, or simply temporarily removing /opt/local/bin from your path.
I solved by uninstalling MacPorts:
sudo port -f uninstall installed

R package RcppEigen installation failed [duplicate]

I tried to install RcppEigen on amazon EC2 (on a t1.micro to
make sure It works) & ubuntu 13.04. I tried with both R version was 2.15.2 and 3.0, 32bit ubuntu and 64bit ubuntu. Any time I got the following:
root#ip-10-224-4-239:/home/ubuntu# R CMD INSTALL RcppEigen_0.3.1.2.1.tar.gz
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘RcppEigen’ ...
** package ‘RcppEigen’ successfully unpacked and MD5 sums checked
** libs
g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I../inst/include -fpic -O2 -pipe -g -c RcppEigen.cpp -o RcppEigen.o
g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I../inst/include -fpic -O2 -pipe -g -c fastLm.cpp -o fastLm.o
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.7/README.Bugs> for instructions.
make: *** [fastLm.o] Error 4
ERROR: compilation failed for package ‘RcppEigen’
* removing ‘/usr/local/lib/R/site-library/RcppEigen’
Anyone has an idea on how to get RcppEigen to run on EC2?
(Rcpp installs flawlessly....)
That looks like a "simple" out of memory issue.
C++ can be demanding as is, and complex template code (which Eigen surely is) demands even more resources. Simply try allocating more memory -- otherwise it is hard to kill g++.

g++: as fails to determine which assembler to run

Today I wanted to recompile one of my projects. Compiling this project had already worked on my machine, but this time an error occured.
The compiler output goes:
fatal error: as: unknown host architecture (can't determine which assembler to run)`
for the line:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../../.vscode -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I../../.vscode -I. -o Main.o ../../Main.cpp
I tried to compile some other projects, but realized, that I wouldn't be able to compile anything using any c++ compiler, so I looked it up.
The only fitting thread I found was this one but the solution 'reinstalling binutils' didn't work for me (tried sudo apt-get install --reinstall binutils as well as --reinstall gcc, g++ and build-essential)
One possible reason for this problem that comes to my mind is the iOS-toolchain I installed yesterday - I had to install some different clang versions - but I actually didn't change anything on the system's assembler...
If someone's got an idea; any help would be appreciated :)
Additional info:
Ubuntu 16.04 LTS 64bit
AMD FX(tm)-6300 Six-Core Processor × 6
uname -m
returns x86_64
gcc -march=native -v -E - 2>&1 <<<'' | grep "cc1" | egrep -o -e $'-m(arch|tune)=[^ "\']+'
returns -march=bdver2 and -mtune=bdver2
already tried gcc [...] -march with bdver2 and other architectures
g++ -v -c HelloWorld.cpp gives me: http://pastebin.com/Ks2be0hL
type -a as says:
as is /usr/local/bin/as
as is /usr/bin/as
as --version sadly just show's me the error again, but info as tells me it's binutils-2.26.1-system from 2016-08-07
dpkg -S /usr/bin/as prints: binutils: /usr/bin/as
type -a as says as is /usr/local/bin/as. This is what gcc is running, not /usr/bin/as, because /usr/local/bin/as is found first in your $PATH search order. This is why re-installing packages and so on is having no effect: something else you installed (probably manually) installed a non-standard as.
Have a look at /usr/local/bin/as and figure out where it came from, and what to do with it. For now you can just rename it to as.unknown or something, and then everything will use the normal system assembler (/usr/bin/as).
Remove binutils and reinstall it using the following steps:
Create an installation directory /opt/cross, and make sure you have write permission to .
sudo mkdir -p /opt/cross
sudo chown user /opt/cross
export PATH=/opt/cross/bin:$PATH
Download and install
wget http://mirrors.muzzy.it/gnu/binutils/binutils-2.9.tar.gz
tar xvf binutils-2.9.tar.gz
cd binutils-2.9
linux32 ./configure --prefix=/opt/cross --target=aarch64-linux --disable-multilib
If dosn't work remove --target=aarch64-linux, the --disable-multilib option means that we only want our Binutils installation to work with programs and libraries using the aarch64 instruction set, and not any related instruction sets such as aarch32, run:
linux32 ./configure --prefix=/opt/cross --disable-multilib
linux32 make
linux32 make install

Couldn't build google mock

I tried to build google mock on Windows 7 by using MinGW. But I couldn't.
I downloaded google test and google mock from the web site below by clicking 'Download Zip' button.
[https://github.com/google/googletest][1]
I unzipped the file and execute the command on the command line.
> g++ -c -Iinclude -I. src/gmock-all.cc
But the error occurred.
> include/gmock/internal/gmock-port.h:53:45: fatal error: gtest/internal/gtest-linked_ptr.h: No such file or directory
How can I solve it?
You should first build googletest, and then googlemock. It comes bundled
with googlemock in subdirectory named "gtest". This is what you need to do:
g++ -isystem <path_to_gtest>/include -I<path_to_gtest> \
-isystem <path_to_gmock>/include -I<path_to_gmock> \
-pthread -c <path_to_gtest>/src/gtest-all.cc
g++ -isystem <path_to_gtest>/include -I<path_to_gtest> \
-isystem <path_to_gmock>/include -I<path_to_gmock> \
-pthread -c <path_to_gmock>/src/gmock-all.cc
This will definately work on Linux, but I cant be 100% sure for MinGW on
Win7. If it does not help, I suggest using Visual Studio Community Edition.
You already have a VS solution setup in <path_to_gmock>/msvc/2010. It
is a solution for VS2010 but opening it with a newer version will prompt you
to upgrade the toolset. Simply accept and build the "gmock" project in that
solution.o_gmock>/src/gmock-all.cc