0

I inherited a C++ code with a dependency to OpenMPI that I want to delegate to Conan and CMake, and the automated build has a strange (to me at least) behavior related to sysctl that I want to understand.

How I tried to do it

I declared the required dependencies in my root CMakeLists.txt:

Note: I added the full list of requirements because I also suspect that some of them may be in conflict? That happened before with boost, that forced me to set explicitly zlib (if i remember correctly).

# stuff ...

conan_cmake_configure(
                      REQUIRES
                        zlib/1.2.12
                        mp-units/0.7.0
                        boost/1.79.0
                        openmpi/4.1.0
                        gsl/2.7
                        cspice/0067
                      GENERATORS
                        cmake
                        # that is required for cspice
                        CMakeDeps
                        CMakeToolchain
                      )
  # more stuff ...

and then in the application CmakeLists.txt I find, include and link the executable to the required libraries:

add_executable(spock main.cpp)

find_package(cspice REQUIRED)
find_package(openmpi REQUIRED)

target_include_directories(
  spock PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
                $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
               openmpi_INCLUDE_DIRS
               cspice_INCLUDE_DIRS
             )

target_link_libraries(spock
                      CONAN_PKG::boost
                      CONAN_PKG::mp-units
                      openmpi::openmpi
                      cspice::cspice
                    )

# We need C++ 20 activated with the concepts library
target_compile_features(spock PUBLIC cxx_std_20)

Problem: undefined reference to sysctl ... on my local system only.

Building on my local machine with CMake 3.23.2 results in the following error message:

Consolidate compiler generated dependencies of target spock
[ 25%] Building CXX object src/CMakeFiles/spock.dir/main.cpp.o
^[[A^[[A[ 50%] Linking CXX executable ../bin/spock
/usr/bin/ld: /home/becheler/.conan/data/openmpi/4.1.0/_/_/package/8f7048d1bf6fc2a7985eb087c34e69a5e64f6c86/lib/libopen-pal.a(evutil_rand.o): in function `arc4_stir.isra.0':
evutil_rand.c:(.text+0x3d2): undefined reference to `sysctl'
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/CMakeFiles/spock.dir/build.make:146: bin/spock] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:135: src/CMakeFiles/spock.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

However, the same build on Github workflows on Ubuntu 20.04 works. What is weird. The only difference before apart the distribution version is that github wokflows use higher privileges than me on local (I believe?).

What I tried so far

I've been trying to read about what this sysctlreference is. And I found conflicting information:

The sysctl() function retrieves system information and allows processes with appropriate privileges to set system information.

Linux does not support this function (other OS like MacOS or FreeBSD support it)

  • A comment from the same post concludes that in Linux,

these details can be obtained by reading the kernel-provided pseudofiles /proc/cpuinfo and /proc/meminfo

So here is my question: why does it compile at all on the remote server if this command is not supposed to exist on the OS used?

WaterFox
  • 850
  • 6
  • 18
  • 1
    The Linux [man page](https://www.man7.org/linux/man-pages/man2/sysctl.2.html) says "This system call no longer exists on current kernels!" I didn't see where you mentioned what distribution you're getting the error on, but maybe it's a newer one and the GitHub OS is an older one that still has it? – Shawn Jul 16 '22 at 07:31
  • 1
    What happens if you build it with higher privileges locally? Does it build? You pointed out as the main difference, but it is not clear if you tried it locally and what happened. – drodri Jul 20 '22 at 11:44
  • I hesitated running a sudo cmake, but as I don't know what it will do to my system I prefered not to risk it :/ – WaterFox Jul 21 '22 at 01:36

0 Answers0