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

Force openssl in CMake targets #348

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

Force openssl in CMake targets #348

wants to merge 3 commits into from

Conversation

afjoseph
Copy link

@afjoseph afjoseph commented Mar 21, 2024

Fixes #343

Hey guys. I'm having the same issue as #343. Here's the repro steps. My machine is MacOS M1 Monterey 12.6.6 and I'm on the latest commit as of writing:

git clone https://github.com/rizinorg/rz-ghidra
cd rz-ghidra
git submodule update --init
# OpenSSL installed with homebrew
pkg-config --cflags --libs openssl
-I/opt/homebrew/Cellar/openssl@3/3.2.1/include -L/opt/homebrew/Cellar/openssl@3/3.2.1/lib -lssl -lcrypto
cmake -DCMAKE_PREFIX_PATH=/Users/afjoseph/dev/misc/rizin/build -B build && cmake --build build --verbose

The build fails with the following error:

        [ 36%] Building CXX object CMakeFiles/core_ghidra.dir/src/core_ghidra.cpp.o
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DRZ_GHIDRA_SLEIGHHOME_DEFAULT=\"/usr/local/lib/rizin/plugins/rz_ghidra_sleigh\" -Dcore_ghidra_EXPORTS -I/Users/afjoseph/dev/misc/rz-ghidra/ghidra/ghidra/Ghidra/Features/Decompiler/src/decompile/cpp -I/Users/afjoseph/dev/misc/rz-ghidra/third-party/pugixml/src -isystem /opt/homebrew/include/librz -isystem /opt/homebrew/include/librz/sdb -std=gnu++11 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.6 -fPIC -MD -MT CMakeFiles/core_ghidra.dir/src/core_ghidra.cpp.o -MF CMakeFiles/core_ghidra.dir/src/core_ghidra.cpp.o.d -o CMakeFiles/core_ghidra.dir/src/core_ghidra.cpp.o -c /Users/afjoseph/dev/misc/rz-ghidra/src/core_ghidra.cpp
        In file included from /Users/afjoseph/dev/misc/rz-ghidra/src/core_ghidra.cpp:9:
        In file included from /Users/afjoseph/dev/misc/rz-ghidra/src/ArchMap.h:10:
        In file included from /opt/homebrew/include/librz/rz_core.h:7:
        In file included from /opt/homebrew/include/librz/rz_main.h:9:
        In file included from /opt/homebrew/include/librz/rz_getopt.h:4:
        /opt/homebrew/include/librz/rz_util.h:21:10: fatal error: 'openssl/bn.h' file not found
        #include <openssl/bn.h>
                 ^~~~~~~~~~~~~~
        1 error generated.
        make[2]: *** [CMakeFiles/core_ghidra.dir/src/core_ghidra.cpp.o] Error 1
        make[1]: *** [CMakeFiles/core_ghidra.dir/all] Error 2
        make: *** [all] Error 2

This PR fixes tells CMake to require OpenSSL in the CMake targets, which would add the necessary compile flags (e.g., pkg-config --cflags openssl).

@ret2libc
Copy link
Member

I think this error should be solved in Rizin itself.

It can be reproduced with this small test:
CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(MyRizinProject)

# Find the Rizin package (make sure it is installed and CMake can find it)
find_package(Rizin COMPONENTS Core REQUIRED)

# Add the executable that we want to compile
add_executable(test_rizin test_rizin.c)

# Link the Rizin libraries to our executable
target_link_libraries(test_rizin PUBLIC Rizin::Core)

test_rizin.c

#include <stdio.h>
#include <rz_util.h>

int main(int argc, char **argv) {
	char *s = rz_str_newf("core %p\n", argv);
	printf("s = %s\n", s);
	free(s);
	return 0;
}
cmake --build build
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/rizin_pkg/build
[ 50%] Building C object CMakeFiles/test_rizin.dir/test_rizin.c.o
In file included from /tmp/rizin_pkg/test_rizin.c:2:
/opt/homebrew/include/librz/rz_util.h:21:10: fatal error: 'openssl/bn.h' file not found
#include <openssl/bn.h>
         ^~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/test_rizin.dir/test_rizin.c.o] Error 1
make[1]: *** [CMakeFiles/test_rizin.dir/all] Error 2
make: *** [all] Error 2

I'm not a Cmake guru unfortunately so I was never able to fix it myself, but it should likely be fixed somewhere in https://github.com/rizinorg/rizin/blob/dev/librz/RzModulesConfig.cmake.in .

@afjoseph
Copy link
Author

@ret2libc Thanks for looking into it. I agree this should be fixed in core Rizin. I'll look into it and modify the PR (or just close this one). Expect it sometime in the next 1-2 days.

Many thanks for taking a look at it ❤️

@ret2libc
Copy link
Member

Sure thing. I actually have some pending changes to fix this thing in Rizin itself. I was able to get some help to fix it once and for all. Still need to adjust a few things and push the PR though.

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.

Failed to build with rizin 0.6.3 on MacOS
2 participants