oneapi-src / oneapi-src/oneAPI-samples

Cannot Build 32 Bit Hello World Using CMake

未关闭
#2,312 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
C++
星标
1.2k
派生
745
PR 合并指标
30 天内没有已合并 PR

描述

Summary

In short when i try to build a application using CMake right after running source /opt/intel/oneapi/setvars.sh ia32 it does not work. I created a dockerfile to summarize my findings. It simply installs the oneAPI toolchain on a empty ubuntu base image and tries to compile a sample application. If this is a incorrect pattern for building let me know. I was following the documentation

Enable CMake with setvars.sh, oneapi-vars.sh, or vars.sh
If you are already using setvars.sh, oneapi-vars.sh, or vars.sh to initialize the build environment, then all the necessary environment variables are being set and you should be able to use CMake. For more information on these scripts, see Use the setvars and oneapi-vars Scripts with Linux*.

# Use nomral ubuntu base
FROM public.ecr.aws/ubuntu/ubuntu:22.04

# enable using "source" in docker
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# install dev tools
RUN apt-get update && \
    apt-get install -y cmake golang-go wget git

# install intel compiler
RUN wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/fdc7a2bc-b7a8-47eb-8876-de6201297144/l_BaseKit_p_2024.1.0.596.sh && \
    chmod +x ./l_BaseKit_p_2024.1.0.596.sh && \
    ./l_BaseKit_p_2024.1.0.596.sh -a --silent --eula accept &&\
    chmod +x /opt/intel/oneapi/setvars.sh

# create helloworld
RUN mkdir hello-world && \
    cd hello-world && \
    touch CMakeLists.txt && \
    echo "cmake_minimum_required(VERSION 3.22)" >> CMakeLists.txt && \
    echo "project(hello_world)" >> CMakeLists.txt && \
    echo "set(CMAKE_CXX_STANDARD 20)" >> CMakeLists.txt && \
    echo "add_executable(hello_world main.cpp)" >> CMakeLists.txt && \
    touch main.cpp && \
    echo "#include<iostream>" >> main.cpp &&\
    echo "" >> main.cpp &&\
    echo "auto main() -> int {" >> main.cpp &&\
    echo -e "    std::cout << \"Hello World\";" >> main.cpp &&\
    echo "    return 0;" >> main.cpp &&\
    echo "}" >> main.cpp

# build basic application
RUN source /opt/intel/oneapi/setvars.sh ia32 &&\
    cd hello-world && \
    mkdir build && \
    cd build && \
    cmake  -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx .. && \
    cmake --build .

this will result in the error

CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/opt/intel/oneapi/compiler/2024.1/bin/icx"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /hello-world/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_84458/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_84458.dir/build.make CMakeFiles/cmTC_84458.dir/build
    gmake[1]: Entering directory '/hello-world/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_84458.dir/testCCompiler.c.o
    /opt/intel/oneapi/compiler/2024.1/bin/icx    -MD -MT CMakeFiles/cmTC_84458.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_84458.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_84458.dir/testCCompiler.c.o -c /hello-world/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_84458
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_84458.dir/link.txt --verbose=1
    /opt/intel/oneapi/compiler/2024.1/bin/icx CMakeFiles/cmTC_84458.dir/testCCompiler.c.o -o cmTC_84458
    /usr/bin/ld: cannot find Scrt1.o: No such file or directory
    /usr/bin/ld: cannot find crti.o: No such file or directory
    /usr/bin/ld: cannot find crtbeginS.o: No such file or directory
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.so when searching for -lm
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.a when searching for -lm
    /usr/bin/ld: cannot find -lm: No such file or directory
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.so when searching for -lm
    /usr/bin/ld: cannot find -lgcc: No such file or directory
    /usr/bin/ld: cannot find -lgcc_s: No such file or directory
    /usr/bin/ld: cannot find -lgcc: No such file or directory
    /usr/bin/ld: cannot find -lgcc_s: No such file or directory
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.a when searching for -lc
    /usr/bin/ld: cannot find -lc: No such file or directory
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc
    /usr/bin/ld: cannot find -lgcc: No such file or directory
    /usr/bin/ld: cannot find -lgcc_s: No such file or directory
    /usr/bin/ld: cannot find crtendS.o: No such file or directory
    /usr/bin/ld: cannot find crtn.o: No such file or directory
    icx: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[1]: *** [CMakeFiles/cmTC_84458.dir/build.make:100: cmTC_84458] Error 1
    gmake[1]: Leaving directory '/hello-world/build/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:127: cmTC_84458/fast] Error 2

however if i replace source /opt/intel/oneapi/setvars.sh ia32 with source /opt/intel/oneapi/setvars.sh it will compile as expected and use the correct compiler.

Version

2024.1.0.596

Environment

Ubuntu 22.04

also full environment can be detailed in the dockerfile.

Steps to reproduce

given the dockerfile is present in your dir you can simply run docker build . to attempt to build it.

Observed behavior

Saw the error

CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/opt/intel/oneapi/compiler/2024.1/bin/icx"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /hello-world/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_84458/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_84458.dir/build.make CMakeFiles/cmTC_84458.dir/build
    gmake[1]: Entering directory '/hello-world/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_84458.dir/testCCompiler.c.o
    /opt/intel/oneapi/compiler/2024.1/bin/icx    -MD -MT CMakeFiles/cmTC_84458.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_84458.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_84458.dir/testCCompiler.c.o -c /hello-world/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_84458
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_84458.dir/link.txt --verbose=1
    /opt/intel/oneapi/compiler/2024.1/bin/icx CMakeFiles/cmTC_84458.dir/testCCompiler.c.o -o cmTC_84458
    /usr/bin/ld: cannot find Scrt1.o: No such file or directory
    /usr/bin/ld: cannot find crti.o: No such file or directory
    /usr/bin/ld: cannot find crtbeginS.o: No such file or directory
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.so when searching for -lm
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.a when searching for -lm
    /usr/bin/ld: cannot find -lm: No such file or directory
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.so when searching for -lm
    /usr/bin/ld: cannot find -lgcc: No such file or directory
    /usr/bin/ld: cannot find -lgcc_s: No such file or directory
    /usr/bin/ld: cannot find -lgcc: No such file or directory
    /usr/bin/ld: cannot find -lgcc_s: No such file or directory
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.a when searching for -lc
    /usr/bin/ld: cannot find -lc: No such file or directory
    /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc
    /usr/bin/ld: cannot find -lgcc: No such file or directory
    /usr/bin/ld: cannot find -lgcc_s: No such file or directory
    /usr/bin/ld: cannot find crtendS.o: No such file or directory
    /usr/bin/ld: cannot find crtn.o: No such file or directory
    icx: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[1]: *** [CMakeFiles/cmTC_84458.dir/build.make:100: cmTC_84458] Error 1
    gmake[1]: Leaving directory '/hello-world/build/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:127: cmTC_84458/fast] Error 2

I do believe this is related to setvars.sh not using the correct linker/glibc when ia32 is set.

Expected behavior

Dockerfile builds using ia32 as a arugment to setvars.sh

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用报告中的 Dockerfile 运行 docker build .,并在 source /opt/intel/oneapi/setvars.sh ia32 后检查生成的 CMakeLists.txt、main.cpp 和 compiler-test 输出。将该构建路径与使用不带 ia32 的 setvars.sh 成功构建的路径进行比较;完成的标准是 Dockerfile 使用 ia32 参数成功构建示例。

由索引模型根据 Issue 内容生成。

评估

技术栈
cmake, cpp, docker, ubuntu
领域
build-system, compilers, devops, operating-systems
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。