Skip to content

Build fails #3

@robertvazan

Description

@robertvazan

Since I couldn't use the supplied Dockerfile due to #2, I created my own. After adding all the necessary dependencies, I am now running into build errors:

STEP 4/5: RUN cd /src/spectre-cli &&     cmake -DBUILD_SPECTRE_TESTS=ON . &&     make install &&     spectre-tests &&     cd / &&     rm -rf /src
CMake Warning (dev) at CMakeLists.txt:2 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The C compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
CMake Deprecation Warning at CMakeLists.txt:3 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- Found Git: /usr/bin/git (found version "2.49.1")
-- Current spectre source version 2.6-cli-5-118-g5ff9ec4...
-- Found sodium: /usr/lib/libpthread.a (found version "1.0.20")
-- spectre: USE_SODIUM is enabled.
-- Found Curses: /usr/lib/libcurses.so
-- spectre: USE_COLOR is enabled.
-- spectre: USE_JSON is enabled.
CMake Error at cmake/Findsodium.cmake:247 (add_library):
  add_library cannot create imported target "sodium" because another target
  with the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:44 (find_package)
  CMakeLists.txt:185 (use_spectre_sodium)


-- spectre-tests: USE_SODIUM is enabled.
-- Found LibXml2: /usr/lib/libxml2.so (found version "2.13.9")
-- spectre-tests: USE_XML is enabled.
-- Configuring incomplete, errors occurred!
Error: building at STEP "RUN cd /src/spectre-cli &&     cmake -DBUILD_SPECTRE_TESTS=ON . &&     make install &&     spectre-tests &&     cd / &&     rm -rf /src": while running runtime: exit status 1

Analysis (by Gemini and GPT)

The build failure is caused by two separate bugs in spectre-cli's custom CMake find module cmake/Findsodium.cmake:

  1. Target Name Collision: CMakeLists.txt calls use_spectre_sodium() for each enabled executable (spectre, spectre-bench, spectre-tests). This function calls find_package(sodium). The custom Findsodium.cmake script unconditionally calls add_library(sodium ... IMPORTED) without checking if the target already exists (e.g., using if(NOT TARGET sodium)). When BUILD_SPECTRE_TESTS=ON is set, find_package(sodium) is executed multiple times, which crashes the build on the second execution because the sodium target was already created by the first call.
  2. Incorrect Library Resolution: Findsodium.cmake relies on pkg-config for static libraries. When iterating over the list of pkg-config libraries, it prepends "lib${_libname}.a" using list(INSERT ... 0). Because it prepends at index 0 on each iteration, the list gets reversed. The libsodium package depends on pthread, so pkg-config returns something like sodium;pthread. After the reverse-prepend, the search list becomes libpthread.a;libsodium.a;.... Consequently, CMake finds libpthread.a first and mistakenly assigns it to the sodium library variables, as evidenced by the build output: -- Found sodium: /usr/lib/libpthread.a.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions