- 1. Linux C/C++ 编译集锦
- 1.1. 常规编译
- 1.1.1. 修改安装目录
- 1.2. GCC 问题
- 1.3. 问题
- 1.3.1. Target requires the language dialect "CXX17" (with compiler extensions), but CMake does not know the compile flags to use to enable it
- 1.3.2. 解决 "错误: 只允许在 C99 模式下使用‘for’循环初始化声明" 问题
- 1.3.3. Linux error while loading shared libraries: cannot open shared object file: No such file or directory
./configure make sudo make install1.1.1. 修改安装目录
- 修改 configure 文件中 prefix 的值:
用 vi/vim 打开 configure 文件, 然后找到 prefix 值, 修改未 prefix=你的安装目录, 然后保存退出, 再执行 ./configure & make & sudo make install 就可以, 不过该方法比较麻烦, 会容易改动到 configure 文件的其他的参数, 不建议使用。
- 执行 configure 文件时指定安装目录:
./configure --prefix=/home/user/zws/build
- 在 make install 指定 DESTDIR 参数:
./configure make make install DESTDIR=/home/user/zws/build1.2. GCC 问题
Follow the instructions at https://gcc.gnu.org/wiki/InstallingGCC
Specifically, don’t install ISL manually in some non-standard path, because GCC needs to find its shared libraries at run-time.
The simplest solution is to use the download_prerequisites script to add the GMP, MPFR, MPC and ISL source code to the GCC source tree, which will cause GCC to build them for you automatically, and link to them statically.
If it provides sufficiently recent versions, use your OS package management system to install the support libraries in standard system locations. For Debian-based systems, including Ubuntu, you should install the packages libgmp-dev, libmpfr-dev and libmpc-dev. For RPM-based systems, including Fedora and SUSE, you should install gmp-devel, mpfr-devel and libmpc-devel (or mpc-devel on SUSE) packages. The packages will install the libraries and headers in standard system directories so they can be found automatically when building GCC.
Alternatively, after extracting the GCC source archive, simply run the ./contrib/download_prerequisites script in the GCC source directory. That will download the support libraries and create symlinks, causing them to be built automatically as part of the GCC build process. Set GRAPHITE_LOOP_OPT=no in the script if you want to build GCC without ISL, which is only needed for the optional Graphite loop optimizations.
tar xzf gcc-4.6.2.tar.gz cd gcc-4.6.2 ./contrib/download_prerequisites cd .. mkdir objdir cd objdir $PWD/../gcc-4.6.2/configure --prefix=$HOME/GCC-4.6.2 --enable-languages=c,c++,fortran,go make make install # option export PATH=$HOME/GCC-4.6.2/bin:$PATH1.3. 问题 1.3.1. Target requires the language dialect “CXX17” (with compiler extensions), but CMake does not know the compile flags to use to enable it
需要:
- CMAKE > 3.8
- GCC/C++17 > 5.1.0
Still the same "dialect “CXX17” error ?In my case, something else was needed to make it works:
sudo ln -s /usr/local/bin/gcc /usr/local/bin/cc
i’ve setted -DCMAKE_C_COMPILER=/usr/local/bin/gcc and -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ to cmake command options and had worked fine.
1.3.2. 解决 “错误: 只允许在 C99 模式下使用‘for’循环初始化声明” 问题$ make CFLAGS=-std=c99 # 或者 $ export CFLAGS=-std=c991.3.3. Linux error while loading shared libraries: cannot open shared object file: No such file or directory
sudo find / -name the_name_of_the_file.so echo $LD_LIBRARY_PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/ export LD_LIBRARY_PATH ./my_app sudo ldconfig sudo ldconfig /opt/intel/oneapi/mkl/2021.2.0/lib/intel64 ln -s /lib/libpthread_rt.so /lib/libpthread_rt.so.1
installed the -dev version of that package.
sudo apt install libgconf2-dev



