linux下解决make: g++: Command not found

在编译执行make命令的时候,提示make: g++: Command not found,原因是缺少组件导致的。

[smart@node-build cpp_jni]$ make
g++ -c -pipe -g -std=gnu++0x -Wall -W -fPIC  -I. -I/usr/java/jdk1.8.0_131/include -I/usr/java/jdk1.8.0_131/include/linux -I../../../../Qt5.6.1/5.6/gcc_64/mkspecs/linux-g++ -o com_example_demo_jni_TestJni.o com_example_demo_jni_TestJni.cpp
make: g++: Command not found
make: *** [com_example_demo_jni_TestJni.o] Error 127

执行yum search "gcc-c++"查询缺少组件的版本,不同的操作系统版本可能会不一样。

[smart@node-build cpp_jni]$ yum search "gcc-c++"
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.aliyun.com
==================================================================================================== N/S matched: gcc-c++ =====================================================================================================
gcc-c++.x86_64 : C++ support for GCC

  Name and summary matches only, use "search all" for everything.

切换到root用户,执行yum install "gcc-c++.x86_64" -y安装对应版本的组件

[root@node-build cpp_jni]# yum install "gcc-c++.x86_64" -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.163.com
 * updates: ftp.sjtu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-39.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-39.el7 for package: gcc-c++-4.8.5-39.el7.x86_64
--> Processing Dependency: libstdc++ = 4.8.5-39.el7 for package: gcc-c++-4.8.5-39.el7.x86_64
--> Processing Dependency: gcc = 4.8.5-39.el7 for package: gcc-c++-4.8.5-39.el7.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-c++-4.8.5-39.el7.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-c++-4.8.5-39.el7.x86_64
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-39.el7 will be installed
--> Processing Dependency: libgomp = 4.8.5-39.el7 for package: gcc-4.8.5-39.el7.x86_64
--> Processing Dependency: cpp = 4.8.5-39.el7 for package: gcc-4.8.5-39.el7.x86_64
--> Processing Dependency: libgcc >= 4.8.5-39.el7 for package: gcc-4.8.5-39.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-39.el7.x86_64
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package libstdc++.x86_64 0:4.8.5-36.el7_6.2 will be updated
---> Package libstdc++.x86_64 0:4.8.5-39.el7 will be an update
---> Package libstdc++-devel.x86_64 0:4.8.5-39.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
.......................................
  Cleanup    : glibc-2.17-260.el7_6.6.x86_64                                                                                                                                                                             17/19 
  Cleanup    : glibc-common-2.17-260.el7_6.6.x86_64                                                                                                                                                                      18/19 
  Cleanup    : libgcc-4.8.5-36.el7_6.2.x86_64                                                                                                                                                                            19/19 
  Verifying  : kernel-headers-3.10.0-1127.8.2.el7.x86_64                                                                                                                                                                  1/19 
  Verifying  : glibc-common-2.17-307.el7.1.x86_64                                                                                                                                                                         2/19 
  Verifying  : glibc-headers-2.17-307.el7.1.x86_64                                                                                                                                                                        3/19 
  Verifying  : glibc-devel-2.17-307.el7.1.x86_64                                                                                                                                                                          4/19 
  Verifying  : gcc-c++-4.8.5-39.el7.x86_64                                                                                                                                                                                5/19 
  Verifying  : mpfr-3.1.1-4.el7.x86_64                                                                                                                                                                                    6/19 
  Verifying  : cpp-4.8.5-39.el7.x86_64                                                                                                                                                                                    7/19 
  Verifying  : libmpc-1.0.1-3.el7.x86_64                                                                                                                                                                                  8/19 
  Verifying  : libgomp-4.8.5-39.el7.x86_64                                                                                                                                                                                9/19 
  Verifying  : glibc-2.17-307.el7.1.x86_64                                                                                                                                                                               10/19 
  Verifying  : gcc-4.8.5-39.el7.x86_64                                                                                                                                                                                   11/19 
  Verifying  : libstdc++-devel-4.8.5-39.el7.x86_64                                                                                                                                                                       12/19 
  Verifying  : libgcc-4.8.5-39.el7.x86_64                                                                                                                                                                                13/19 
  Verifying  : libstdc++-4.8.5-39.el7.x86_64                                                                                                                                                                             14/19 
  Verifying  : glibc-2.17-260.el7_6.6.x86_64                                                                                                                                                                             15/19 
  Verifying  : libgcc-4.8.5-36.el7_6.2.x86_64                                                                                                                                                                            16/19 
  Verifying  : libgomp-4.8.5-36.el7_6.2.x86_64                                                                                                                                                                           17/19 
  Verifying  : libstdc++-4.8.5-36.el7_6.2.x86_64                                                                                                                                                                         18/19 
  Verifying  : glibc-common-2.17-260.el7_6.6.x86_64                                                                                                                                                                      19/19 

Installed:
  gcc-c++.x86_64 0:4.8.5-39.el7                                                                                                                                                                                                

Dependency Installed:
  cpp.x86_64 0:4.8.5-39.el7               gcc.x86_64 0:4.8.5-39.el7   glibc-devel.x86_64 0:2.17-307.el7.1   glibc-headers.x86_64 0:2.17-307.el7.1   kernel-headers.x86_64 0:3.10.0-1127.8.2.el7   libmpc.x86_64 0:1.0.1-3.el7  
  libstdc++-devel.x86_64 0:4.8.5-39.el7   mpfr.x86_64 0:3.1.1-4.el7  

Dependency Updated:
  glibc.x86_64 0:2.17-307.el7.1             glibc-common.x86_64 0:2.17-307.el7.1             libgcc.x86_64 0:4.8.5-39.el7             libgomp.x86_64 0:4.8.5-39.el7             libstdc++.x86_64 0:4.8.5-39.el7            

Complete!

提示安装完成,再次执行make后不再报错。

[smart@node-build cpp_jni]$ make
g++ -c -pipe -g -std=gnu++0x -Wall -W -fPIC  -I. -I/usr/java/jdk1.8.0_131/include -I/usr/java/jdk1.8.0_131/include/linux -I../../../../Qt5.6.1/5.6/gcc_64/mkspecs/linux-g++ -o com_example_demo_jni_TestJni.o com_example_demo_jni_TestJni.cpp
rm -f libnative.so.1.0.0 libnative.so libnative.so.1 libnative.so.1.0
g++ -shared -Wl,-soname,libnative.so.1 -o libnative.so.1.0.0 com_example_demo_jni_TestJni.o    
ln -s libnative.so.1.0.0 libnative.so
ln -s libnative.so.1.0.0 libnative.so.1
ln -s libnative.so.1.0.0 libnative.so.1.0
rm -f ../target/cpp/libnative.so.1.0.0
mv -f libnative.so.1.0.0  ../target/cpp/ 
rm -f ../target/cpp/libnative.so
rm -f ../target/cpp/libnative.so.1
rm -f ../target/cpp/libnative.so.1.0
mv -f libnative.so ../target/cpp/ 
mv -f libnative.so.1 ../target/cpp/ 
mv -f libnative.so.1.0 ../target/cpp/ 

猜你喜欢

转载自blog.csdn.net/BUG_88/article/details/106235196
今日推荐