使用CMake构建的Qt应用可以在Windows中编译但无法运行

时间:2019-07-16 18:29:20

标签: windows cmake qt5

我正在将程序移植到Windows,并且可以对其进行编译,但是当我运行它时,它显示“ Qt5Cored.dll:无法打开共享的目标文件”。

我正在设置一个Windows框,将我在Linux上编写的程序移植到Windows。我所有的C ++程序都使用CMake。设置了Git,ssh,CMake和MinGW之后,我编译了一个程序,该程序除了C ++和数学之外不使用任何库,并使其运行。然后,我安装了Qt并克隆了Mirasol(https://github.com/phma/mirasol;用于教幼儿数字),并对其进行了编译,但没有运行。

这是我在Windows上的构建脚本。欢迎提供有关在哪里安装程序的建议。直到我告诉它要去哪里,CMake才找到Qt。

#!/bin/sh
#export CMAKE_PREFIX_PATH=/c/Qt/5.13.0/lib/cmake/Qt5
export Qt5_DIR="C:/Qt/5.13.0/mingw73_64/lib/cmake/Qt5"
mkdir -p ~/build/$1
cd ~/build/$1
mkdir -p dbg
mkdir -p rel
mkdir -p ins
cd dbg
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=~ ~/src/$1
cd ../rel
cmake -GNinja -DCMAKE_INSTALL_PREFIX=~ ~/src/$1
cd ../ins
cmake -GNinja -DCMAKE_INSTALL_PREFIX=/usr/local ~/src/$1

我在Linux上的构建脚本位于http://bezitopo.org/developers.html(此后,我添加了无关的afl和Android构建)。

在Linux上,它运行良好,并且“ ldd mirasol”产生以下输出:

        linux-vdso.so.1 (0x00007ffdfe6d1000)
        libQt5Widgets.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 (0x00007f714c35d000)
        libQt5Gui.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5 (0x00007f714bbf4000)
        libQt5Core.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f714b4a9000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f714b120000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f714ad82000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f714ab6a000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f714a779000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f714a55a000)
        libGL.so.1 => /usr/lib/x86_64-linux-gnu/libGL.so.1 (0x00007f714a2ce000)
        libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f714a09c000)
        libharfbuzz.so.0 => /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f7149dfe000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7149be1000)
        libicui18n.so.60 => /usr/lib/x86_64-linux-gnu/libicui18n.so.60 (0x00007f7149740000)
        libicuuc.so.60 => /usr/lib/x86_64-linux-gnu/libicuuc.so.60 (0x00007f7149389000)
        libdouble-conversion.so.1 => /usr/lib/x86_64-linux-gnu/libdouble-conversion.so.1 (0x00007f7149178000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7148f74000)
        libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f7148c5e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f714cdf9000)
        libGLX.so.0 => /usr/lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f7148a2d000)
        libGLdispatch.so.0 => /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f7148777000)
        libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f71484c3000)
        libgraphite2.so.3 => /usr/lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f7148296000)
        libicudata.so.60 => /usr/lib/x86_64-linux-gnu/libicudata.so.60 (0x00007f71466ed000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f714647b000)
        libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f7146143000)
        libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f7145f1b000)
        libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f7145d17000)
        libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f7145b11000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f71458fc000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f71456f4000)

在Windows上运行它会产生错误

 C:/Users/phma/build/mirasol/dbg/mirasol.exe: error while loading shared libraries: Qt5Widgetsd.dll: cannot open shared object file: No such file or directory

和ldd产生输出

        ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x7ffad3a20000)
        KERNEL32.DLL => /c/Windows/System32/KERNEL32.DLL (0x7ffad3010000)
        KERNELBASE.dll => /c/Windows/System32/KERNELBASE.dll (0x7ffad0e10000)
        msvcrt.dll => /c/Windows/System32/msvcrt.dll (0x7ffad3560000)
        libgcc_s_seh-1.dll => /mingw64/bin/libgcc_s_seh-1.dll (0x61440000)
        libstdc++-6.dll => /mingw64/bin/libstdc++-6.dll (0x6fc40000)
        USER32.dll => /c/Windows/System32/USER32.dll (0x7ffad2bb0000)
        win32u.dll => /c/Windows/System32/win32u.dll (0x7ffad0c30000)
        GDI32.dll => /c/Windows/System32/GDI32.dll (0x7ffad2e00000)
        gdi32full.dll => /c/Windows/System32/gdi32full.dll (0x7ffad1840000)
        msvcp_win.dll => /c/Windows/System32/msvcp_win.dll (0x7ffad0a60000)
        ucrtbase.dll => /c/Windows/System32/ucrtbase.dll (0x7ffad0b30000)

。它没有说“ Qt5Widgetsd.dll =>未找到”,我也不知道多余的“ d”来自哪里。

ETA:我更改了构建脚本,以告诉CMake使用MSYS Makefile而不是Ninja。我仍然会收到错误消息。

ETA:我将这些DLL复制到了该程序的编译目录,并且该目录运行。对我来说,这看起来并不规范,它来自Linux,其库位于/ usr / lib /中,但是在Windows上,Kate二进制文件旁边的bin目录中有许多DLL。

1 个答案:

答案 0 :(得分:0)

请确保将dll的调试版本(查看输出的 d 后缀)放在EXE附近(请记住Windows将cwd添加为“ ./”。)

d 后缀是因为您构建了调试版本。