Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to append MachineCodeComputer_SystemdDBusInodes_SHA256.cpp to list of source files #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nathan-hess
Copy link

@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.

…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
Author

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

Excellent, thanks for looking it over!

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