Cannot Build 32 Bit Hello World Using CMake
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