gpt4 book ai didi

c++ - 为什么 QDir::exists() 在 docker 容器中不起作用?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:04:41 25 4
gpt4 key购买 nike

在我的主机 KDE Neon 机器(最新升级到 18.04)中执行的以下程序输出 Hello World! 1 输出 Hello World! 0 当从使用下面的 Dockerfile 构建并使用 sudo docker run -it qdir 运行的 Docker 容器执行时。

QDir 是否需要运行 dbus 或其他服务?

C++程序:

#include <QDir>
#include <iostream>


int main(int argc [[maybe_unused]], char** argv [[maybe_unused]])
{
QDir d("/");
std::cout << "Hello World! " << d.exists() << std::endl;
return 0;
}

docker 文件:

FROM kdeneon/plasma:user-lts

USER root

RUN apt-get install -y qt5-default

WORKDIR /
COPY qdir /
CMD /bin/bash

编辑 CMakeLists.txt 来构建程序:

project(qdir)

cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(QT_MIN_VERSION "5.3.0")

find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core)

include_directories(${Qt5Core_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})

set(qdir_SRCS main.cpp)

add_executable(qdir ${qdir_SRCS})
target_link_libraries(qdir ${Qt5Core_LIBRARIES})

install(TARGETS qdir RUNTIME DESTINATION bin)

编辑2:我创建了一个 github 项目,重新组合了以上所有内容。要重现该问题,如果您有 Qt SDK、cmake、ninja 和 docker,只需执行以下操作:

git clone https://github.com/kleag/qdirtest
cd qdirtest
./test.sh

这是我得到的输出:

$ ./test.sh
[…]
Successfully built f710cbb7a3c9
Successfully tagged qdir:latest
Hello World! 1
Hello World! 0

最佳答案

我从 apachelogger on KDE forums 得到了答案:

Since 5.10 Qt is using somewhat new syscalls. One of them is statx and last I checked the syscall was not whitelisted in docker, nor was it whitelistable because the libseccomp used for the upstream docker build was too old and didn't know what statx is. Chances are the problem you see is that. If so, seccomp=unconfined would make it work.

关于c++ - 为什么 QDir::exists() 在 docker 容器中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52705124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com