码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Linux C/C++ 编译集锦


    这里填写标题

    • 1. Linux C/C++ 编译集锦
      • 1.1. 常规编译
        • 1.1.1. 修改安装目录
      • 1.2. gcc
        • 1.2.1. gcc 编译器的 std=c99 选项
        • 1.2.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

    1. Linux C/C++ 编译集锦

    1.1. 常规编译

    ./configure
    make
    sudo make install
    
    • 1
    • 2
    • 3

    1.1.1. 修改安装目录

    1. 修改 configure 文件中 prefix 的值:

    用 vi/vim 打开 configure 文件, 然后找到 prefix 值, 修改未 prefix=你的安装目录, 然后保存退出, 再执行 ./configure & make & sudo make install 就可以, 不过该方法比较麻烦, 会容易改动到 configure 文件的其他的参数, 不建议使用。

    1. 执行 configure 文件时指定安装目录:
    ./configure --prefix=/home/user/zws/build
    
    • 1
    1. 在 make install 指定 DESTDIR 参数:
    ./configure
    make 
    make install DESTDIR=/home/user/zws/build
    
    • 1
    • 2
    • 3

    1.2. gcc

    1.2.1. gcc 编译器的 std=c99 选项

    gcc 默认使用的是 C89 的标准,而 C89 的标准不支持在 for 中定义循环变量,而在 for 循环中需要定义循环变量的话,需要在 C99 标准中才支持,因此需要增加 -std=c99 或 -std=gun99 参数才能编译通过。

    1.2.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:$PATH
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    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

    需要:

    • 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
    
    • 1

    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=c99
    
    • 1
    • 2
    • 3

    1.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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    installed the -dev version of that package.

    sudo apt install libgconf2-dev
    
    • 1
  • 相关阅读:
    今年​计算机考研形势如何,408还是大趋势么?
    Probability Calibration概率校准大比拼:性能、应用场景和可视化对比总结
    WordPress 上传图片时自动重命名的方法
    【DevOps】Logstash详解:高效日志管理与分析工具
    理解系统内核linux phy驱动
    tinymce富文本编辑器【tip】
    设计模式 煎饼果子和装饰者模式
    FastDFS数据迁移
    Docker命令
    高德地图API-获取位置信息的经纬度
  • 原文地址:https://blog.csdn.net/wan212000/article/details/126001480
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号