ubuntu 下用qt5.12编译出的程序无法使用鼠标双击运行

环境:ubuntu18.04
qt version:qt5.12

  1. 问题:编译出的程序无法使用鼠标双击运行,但可以在终端下执行,与运行库是否缺失无关
    mimetype 程序见结果为’application/x-sharedlib’,查看了下正常能用鼠标执行的为‘application/x-executable’(直接右键单击程序属性可查看类型)

    搜索回答如下:

    gcc doesn’t set the mime type. mimetype guesses the appropriate mime type based on the contents of the file. For ELF files (most compiled binaries and shared libraries), the header contains a field e_type which identifies its type. If it is ET_DYN, then mimetype will treat it as a shared library.

    By default, gcc/ld will produce binaries which set e_type to ET_EXEC, which get detected as application/x-executable. When the command-line option -pie is used, a position-independent executable is created, which may, like shared libraries, be loaded at different addresses and still work. Because this works so much like a shared library, to avoid too many changes to the loader, such binaries get marked as ET_DYN, even though they can be executed directly.

    Some Linux distributions, yours included, have set -pie as the default. It’s still possible to override this with -no-pie, but the fact that the mime type is misdetected should not be seen as a bug, and unless you know what you’re doing, you shouldn’t override it. -pie allows for some extra security protections that are fundamentally incompatible with -no-pie.

    所以解决方法在pro中加入下面的编译连接选项重新构建即可

    QMAKE_LFLAGS += -no-pie
    
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
Qt是一种广泛使用的跨平台应用程序框架。本文将介绍如何在Ubuntu 18.04上交叉编译Qt 5.12.7的详细教程。 第一步是安装必要的依赖项。打开终端并输入以下命令: sudo apt-get update sudo apt-get install build-essential perl python git p7zip-full 接下来,你需要安装交叉编译工具链。在此示例中,我们将以ARM Cortex-A7为目标平台。 sudo apt-get install g++-arm-linux-gnueabihf libc6-armhf-cross-armel-cross binutils-arm-linux-gnueabihf 然后,创建一个新的目录并切换到该目录中,然后从Qt官方网站上下载最新的Qt源代码: mkdir qt-cross-compile && cd qt-cross-compile wget https://download.qt.io/archive/qt/5.12/5.12.7/single/qt-everywhere-src-5.12.7.tar.xz tar xvf qt-everywhere-src-5.12.7.tar.xz 接下来,创建一个称为“qt5-armhf.conf”的新文件,需要根据目标平台进行相应的更改: cd qt-everywhere-src-5.12.7/qtbase/mkspecs cp -r linux-arm-gnueabi-g++/ qt5-armhf cd qt5-armhf vi qmake.conf 确保以下行已正确配置: 将“QMAKE_CFLAGS”和“QMAKE_CXXFLAGS”修改为: QMAKE_CFLAGS = -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard --sysroot=/usr/arm-linux-gnueabihf/ QMAKE_CXXFLAGS = $$QMAKE_CFLAGS 对于“QMAKE_LINK”和“QMAKE_LINK_SHLIB”,添加以下行: QMAKE_LINK = arm-linux-gnueabihf-g++ QMAKE_LINK_SHLIB = $$QMAKE_LINK 接下来,进入Qt源代码目录并构建一个交叉编译版本: cd ../../.. ./configure -prefix /opt/qt5-armhf -static -opensource -confirm-license -release -skip webengine -skip wayland -skip qtgamepad make -j4 接下来,安装Qt到目标目录: sudo make install 完成后,你可以在目标文件夹/opt/qt5-armhf找到已安装的Qt库。现在你可以使用Qt Creator或手动创建项目并在Ubuntu 18.04中进行交叉编译

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值