我正在尝试从 Nixos 上的 QtCreator 编译 Qt5 应用程序。
我已经按照 https://nixos.wiki/wiki/Qt 中所述创建了 shell.nix 文件。我按如下方式启动 QtCreator:
$ ls -al
...
.rw-r--r-- 236 username 30 Jun 17:31 shell.nix
...
$ nix-shell
[nix-shell:~/myproject]$ qtcreator
QtCreator 启动,我可以打开我的项目文件 (myproject.pro)。
但是,当我“构建项目”[ctrl+b] 时,我收到以下错误消息:
9:38:09: Running steps for project myproject...
19:38:09: Starting: "/nix/store/gkr9j6p60vib8k8bxhc33581fn4pl8d8-qt-full-5.15.2/bin/qmake" /tmp/myproject/myproject.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
19:38:09: The process "/nix/store/gkr9j6p60vib8k8bxhc33581fn4pl8d8-qt-full-5.15.2/bin/qmake" exited normally.
19:38:09: Starting: "/nix/store/lxmh13cqvd2kwc3qbmnjknvynw6lc2si-gnumake-4.3/bin/make" -f /tmp/build-myproject-Desktop-Debug/Makefile qmake_all
make: Nothing to be done for 'qmake_all'.
19:38:09: The process "/nix/store/lxmh13cqvd2kwc3qbmnjknvynw6lc2si-gnumake-4.3/bin/make" exited normally.
19:38:09: Starting: "/nix/store/lxmh13cqvd2kwc3qbmnjknvynw6lc2si-gnumake-4.3/bin/make" -j16
g++ -Wl,-rpath,/nix/store/wn6q10flx0id4yxa96yq1jzpmbvi7d5r-qtwebkit-5.212.0-alpha4/lib -Wl,-rpath,/nix/store/wn6q10flx0id4yxa96yq1jzpmbvi7d5r-qtwebkit-5.212.0-alpha4/lib -Wl,-rpath,/nix/store/gpw8cms1ig5k16d86zr7hkhi77gccl9r-qtwebkit-5.212.0-alpha4/lib -Wl,-rpath,/nix/store/gpw8cms1ig5k16d86zr7hkhi77gccl9r-qtwebkit-5.212.0-alpha4/lib -Wl,-rpath,/nix/store/3sx0lss99gj0krp3xgqz47zipp8fmj18-qtbase-5.14.2/lib -o myproject cobs.o main.o mainwindow.o srm60binarycom.o moc_mainwindow.o -L/nix/store/8jix4ismqsz2pz6gji3zpawdv2k5aqws-libGL-1.3.3/lib /nix/store/3sx0lss99gj0krp3xgqz47zipp8fmj18-qtbase-5.14.2/lib/libQt5Widgets.so /nix/store/3sx0lss99gj0krp3xgqz47zipp8fmj18-qtbase-5.14.2/lib/libQt5Gui.so /nix/store/3sx0lss99gj0krp3xgqz47zipp8fmj18-qtbase-5.14.2/lib/libQt5Core.so -L/nix/store/izvv5r9a8s19l742nfwr72z2w3ijq8bh-libglvnd-1.3.3/lib -lGL -lpthread
/nix/store/qvc6cz5d43jhhm4a3r48xkrc82xh1s95-binutils-2.35.1/bin/ld: cannot find crt1.o: No such file or directory
/nix/store/qvc6cz5d43jhhm4a3r48xkrc82xh1s95-binutils-2.35.1/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:429: myproject] Error 1
19:38:09: The process "/nix/store/lxmh13cqvd2kwc3qbmnjknvynw6lc2si-gnumake-4.3/bin/make" exited with code 2.
Error while building/deploying project myproject (kit: Desktop)
When executing step "Make"
19:38:09: Elapsed time: 00:00.
错误:
.../ld: cannot find crt1.o: No such file or directory
.../ld: cannot find crti.o: No such file or directory
如何解决这个问题?
这可能是由于 Qt Creator 选择了裸 gcc / g++ 编译器而不是包装版本。打包版本添加了一些命令行选项来使事情正常工作。
就我而言,我必须进入 Tools > Options > Kits 并将自动选择的 C 和 C++ 编译器从“gcc”切换到“gcc-wrapper”。
请参阅相关讨论https://discourse.nixos.org/t/nix-shell-cmake-gcc-qt-creator-not-working-together/16703。
我启动了 Qt5 创建者(NixOS 23.05): nix-shell -p qt5Full -p qtcreator --run qtcreator 并使用生成的 QT Widget 应用程序运行与该线程相同的错误(“缺少 crt1.0”)
提供的答案是可以的,只需要一些详细的步骤:
记下 QtCreator 的工具 > 选项 > 套件自动检测的 c 和 c++ 路径 (/nix/store/lcf37pgp3rgww67v9x2990hbfwx96c1w-gcc-wrapper-12.2.0/bin/gcc /nix/store/lcf37pgp3rgww67v9x2990hbfwx96c1w-gcc-wrapper-12.2.0/bin/g++)
从/nix/store(/nix/store/0s8gvg6nh3d3cbby1hjf69jfb2xdvbvp-cmake-3.25.3/bin/cmake)中找到cmake