You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

GCC 4.5.1编译旧Qt4软件的环境配置问题求助

GCC 4.5.1编译旧Qt4软件的环境配置问题求助

Hey Osman, let's tackle this old software build headache together—those 2007-era projects can be stubborn, but we’ve got a few solid paths forward! Here are three practical solutions to try:

方案1:在Ubuntu 20.04上手动编译GCC 4.5.1和Qt4

The issue with installing pre-built GCC 4.5 on 20.04 is that the official repos no longer host those outdated packages, so we’ll build them from source:

  • First, install the dependencies needed to compile GCC:
    sudo apt-get install build-essential libgmp-dev libmpfr-dev libmpc-dev flex bison
    
  • Download the GCC 4.5.1 source code, extract it, create a separate build directory (to keep the source clean), then configure and compile:
    mkdir gcc-build && cd gcc-build
    ../configure --prefix=/usr/local/gcc45 --enable-languages=c,c++ --disable-multilib
    make -j$(nproc)  # Use all your CPU cores to speed up the build
    sudo make install
    
    Note: Compiling GCC takes a while—be patient, it could take 30+ minutes depending on your hardware.
  • Next, build Qt4 (we’ll use Qt 4.8.7, which is compatible with GCC 4.5):
    1. Install Qt4’s build dependencies:
      sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libfontconfig1-dev libfreetype6-dev
      
    2. Download Qt 4.8.7 source, extract it, configure it (skip examples/demos to save time), then compile:
      ./configure -prefix /usr/local/qt4 -opensource -nomake examples -nomake demos
      make -j$(nproc)
      sudo make install
      
    3. Set up environment variables to use this Qt4 version:
      export PATH=/usr/local/qt4/bin:$PATH
      export LD_LIBRARY_PATH=/usr/local/qt4/lib:$LD_LIBRARY_PATH
      
      You can add these lines to your ~/.bashrc to make them permanent.

方案2:修复Ubuntu 10.10虚拟机的Qt4安装问题

Ubuntu 10.10’s default repos are no longer active, which is why you can’t install Qt4. Fix this by switching to the old releases archive:

  • Open the sources list file with sudo nano /etc/apt/sources.list
  • Replace every instance of http://archive.ubuntu.com/ubuntu/ with http://old-releases.ubuntu.com/ubuntu/
  • Save the file, then update the package lists and install Qt4:
    sudo apt-get update
    sudo apt-get install qt4-dev-tools libqt4-dev
    

This should pull in the Qt4 packages successfully since the old releases repo still hosts them.

方案3:使用Docker容器(最省心的方法)

Instead of dealing with a VM, use a Docker container to create a clean Ubuntu 10.10 environment with GCC 4.5 already available:

  • Pull the Ubuntu 10.10 image:
    docker pull ubuntu:10.10
    
  • Run an interactive container:
    docker run -it --name old-software-build ubuntu:10.10
    
  • Inside the container, follow the same steps as the VM solution to switch to old repos and install Qt4. Then use docker cp to copy your software source code into the container, and build it there.

Any of these methods should get you up and running with the right build environment. Let me know if you hit snags with any step—I’ll help you work through them!

备注:内容来源于stack exchange,提问作者Osman Kamil

火山引擎 最新活动