环境:ubuntu18.04
qt version:qt5.12
-
问题:编译出的程序无法使用鼠标双击运行,但可以在终端下执行,与运行库是否缺失无关
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