Skip to content

Conversation

nathan-hess
Copy link
Contributor

@nathan-hess nathan-hess commented May 19, 2023

This change solves an issue I ran into when attempting to use the Cryptolens C++ API with the MachineCodeComputer_SystemdDBusInodes_SHA256 machine code computer (on Linux).

Issue Description

The issue can be recreated as follows:

  1. Create a GitHub Codespace instance in the Cryptolens/cryptolens-cpp repository
  2. Replace examples/unix/example_activate.cpp with example_activate.zip
  3. Run the following commands:
sudo apt update
sudo apt install ninja-build
mkdir examples/unix/cmake/build
cd examples/unix/cmake/build
cmake .. -G Ninja
ninja

A linker error similar to the following should be displayed:

/usr/bin/ld: CMakeFiles/example_activate.dir/workspaces/cryptolens-cpp/examples/unix/example_activate.cpp.o: in function `cryptolens_io::v20190401::basic_Cryptolens<cryptolens_io::v20190401::Configuration_Unix<cryptolens_io::v20190401::MachineCodeComputer_SystemdDBusInodes_SHA256> >::activate(cryptolens_io::v20190401::basic_Error&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)':
example_activate.cpp:([...]): undefined reference to `cryptolens_io::v20190401::MachineCodeComputer_SystemdDBusInodes_SHA256::get_machine_code[abi:cxx11](cryptolens_io::v20190401::basic_Error&)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Proposed Solution

This change mirrors the same option already present to enable compiling with access to MachineCodeComputer_COM:

set (CRYPTOLENS_BUILD_MACHINE_CODE_COM OFF CACHE BOOL "build with MachineCodeComputer_COM?")
if (CRYPTOLENS_BUILD_MACHINE_CODE_COM)
list (APPEND SRC "src/MachineCodeComputer_COM.cpp" "third_party/curl/isunreserved.cpp")
list (APPEND LIBS "Iphlpapi")
endif()

With this change, the cache variable CRYPTOLENS_BUILD_MACHINE_CODE_SYSTEMDDBUSINODES can be set (for instance, in examples/unix/cmake/CMakeLists.txt) if using the MachineCodeComputer_SystemdDBusInodes_SHA256 machine code computer.

I'm not super familiar with compilers, but I suspect this works because if MachineCodeComputer_SystemdDBusInodes_SHA256.cpp is not explicitly specified, GCC still finds and compiles it but without the desired flags that CMake otherwise adds for options such as C++ standard.

svedi and others added 6 commits January 5, 2023 14:56
This commits mark the start of commits which are not part of the main
development branch. Instead, the following commits are used to
to improve the presentation on github and make it easier to get
started with the library.
…onal

Since the only reason we used C++17 was to get std::optional, we downgrade
to C++11 in CMakeLists.

This commit imports version 3.5.0 of optional-lite.
…HA256.cpp` to list of source files to compile

Without appending this file, linker errors are generated when compiling with the `MachineCodeComputer_SystemdDBusInodes_SHA256` machine code computer
@svedi
Copy link
Collaborator

svedi commented Jun 7, 2023

The commit looks good! I will look into merging it in the coming days, thanks!

@nathan-hess
Copy link
Contributor Author

The commit looks good! I will look into merging it in the coming days, thanks!

Excellent, thanks for looking it over!

@svedi svedi force-pushed the master branch 2 times, most recently from 2f481e3 to 8291a39 Compare September 4, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants