Running CMake throws linking error - cannot find gcc
prashanthr05 opened this issue · 10 comments
Following the instructions in the README, we create a docker image with ubuntu 22.04 installing basic packages like wget
, git
, and ca-certificates
from apt and the rest of the required packages for C++ development using mambaforge given in environment.yml. We copy the source code files within the project directory in a workspace created in home.
CMake configuration step throws the following error,
-- The CXX compiler identification is GNU 10.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /home/user/conda/envs/myenv/bin/x86_64-conda-linux-gnu-c++
-- Check for working CXX compiler: /home/user/conda/envs/myenv/bin/x86_64-conda-linux-gnu-c++ - broken
CMake Error at /home/user/conda/envs/myenv/share/cmake-3.24/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"/home/user/conda/envs/myenv/bin/x86_64-conda-linux-gnu-c++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/user/my_ws/sample-cpp/build/CMakeFiles/CMakeTmp
Run Build Command(s):/home/user/conda/envs/myenv/bin/make -f Makefile cmTC_9116f/fast && /home/user/conda/envs/myenv/bin/make -f CMakeFiles/cmTC_9116f.dir/build.make CMakeFiles/cmTC_9116f.dir/build
make[1]: Entering directory '/home/user/my_ws/sample-cpp/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_9116f.dir/testCXXCompiler.cxx.o
/home/user/conda/envs/myenv/bin/x86_64-conda-linux-gnu-c++ -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/user/conda/envs/myenv/include -o CMakeFiles/cmTC_9116f.dir/testCXXCompiler.cxx.o -c /home/user/my_ws/sample-cpp/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_9116f
/home/user/conda/envs/myenv/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9116f.dir/link.txt --verbose=1
/home/user/conda/envs/myenv/bin/x86_64-conda-linux-gnu-c++ -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/user/conda/envs/myenv/include -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,--allow-shlib-undefined -Wl,-rpath,/home/user/conda/envs/myenv/lib -Wl,-rpath-link,/home/user/conda/envs/myenv/lib -L/home/user/conda/envs/myenv/lib CMakeFiles/cmTC_9116f.dir/testCXXCompiler.cxx.o -o cmTC_9116f
/home/user/conda/envs/myenv/bin/../lib/gcc/x86_64-conda-linux-gnu/10.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: cannot find -lgcc: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_9116f.dir/build.make:99: cmTC_9116f] Error 1
make[1]: Leaving directory '/home/user/my_ws/sample-cpp/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:127: cmTC_9116f/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
See also "/home/user/my_ws/sample-cpp/build/CMakeFiles/CMakeOutput.log".
See also "/home/user/my_ws/sample-cpp/build/CMakeFiles/CMakeError.log".
@traversaro would you have any hints on what might be causing the problem?
P.S. I face the same problem trying to compile robotology-superbuild in the same way from the source within a Docker+Conda environment.
A quick fix would be is to move the installation of packages related to C++ development using apt package manager instead of Conda in order to use system-wide dependencies. However, that does not seem elegant and could possibly later cause some management issues.
I chime in just to let you know that I use daily a dockerized development environment based on conda that you can find here (I have to push quite a lot of local modifications piled up recently xD). You can use it as a reference if you want to compile the superbuild.
Edit: I took advantage of the occasion and I pushed my local modifications, enjoy :)
@traversaro would you have any hints on what might be causing the problem?
I reinstalled exactly the same packages in a new environment, and everything seems to be working fine there. At a quick glance, it seems that ~1500 files are missing in the environment in the Docker image:
user@3562add587dd:~/conda/envs$ find myenv | wc -l
16566
user@3562add587dd:~/conda/envs$ find myenv2 | wc -l
18130
@diegoferigo Thank you for chiming in and thank you for the devenv and development-iit projects which I am already using as references :D
Taking a look at the file you have linked, the differences from what I am doing here are not much (comparing only the relevant parts).
@traversaro would you have any hints on what might be causing the problem?
I reinstalled exactly the same packages in a new environment, and everything seems to be working fine there. At a quick glance, it seems that ~1500 files are missing in the environment in the Docker image:
user@3562add587dd:~/conda/envs$ find myenv | wc -l 16566 user@3562add587dd:~/conda/envs$ find myenv2 | wc -l 18130
Ah, it looks like cleaning up the packages using mamba clean --force-pkgs-dirs --all --yes
or mamba clean --tarballs --index-cache --packages --yes
might be causing problems. I will take a look into it. Thank you very much for the heads up @traversaro!
For an example of the cleaning commands used by the "official" mambaforge image, check https://github.com/conda-forge/miniforge-images/blob/ac6652a64d584f2dd97365febe3994037db1226c/ubuntu/Dockerfile#L35 .
Indeed, --force-pkgs-dirs
seems that can break packages, see https://docs.conda.io/projects/conda/en/latest/commands/clean.html#Removal%20Targets :
-f, --force-pkgs-dirs
Remove all writable package caches. This option is not included with the --all flag. WARNING: This will break environments with packages installed using symlinks back to the package cache.
For an example of the cleaning commands used by the "official" mambaforge image, check https://github.com/conda-forge/miniforge-images/blob/ac6652a64d584f2dd97365febe3994037db1226c/ubuntu/Dockerfile#L35 .
In fact, I was actually using the instructions from that file for installing mambaforge
inside the container and cleaning up the installation to keep the image lightweight
But what was actually causing the problem was this line,
where I was deleting the static libraries which clearly reflects the linking error cannot find -lgcc
.
Thank you for your suggestions and help @diegoferigo @traversaro !!
where I was deleting the static libraries which clearly reflects the linking error
cannot find -lgcc
.
Indeed, deleting static libraries it is a good idea if you just use the Docker image to run an executable or Python script.