Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-opus-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

How do I add openssl in my CMake file?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash’s answer.
  1. User

    How do I add openssl in my CMake file?

  2. Claude Assistant

    To add OpenSSL to your CMake file, you can use CMake's FindOpenSSL module. Here's how to do it:

    # Find OpenSSL
    find_package(OpenSSL REQUIRED)
    
    # Add your executable or library
    add_executable(myapp main.cpp)
    
    # Link OpenSSL libraries
    target_link_libraries(myapp 
        OpenSSL::SSL 
        OpenSSL::Crypto
    )
    

    If you need more control or are having issues finding OpenSSL, you can also:

    1. Specify OpenSSL root directory if it's installed in a non-standard location:
    set(OPENSSL_ROOT_DIR /path/to/openssl)
    find_package(OpenSSL REQUIRED)
    
    1. Check if OpenSSL was found and handle it gracefully:
    find_package(OpenSSL)
    if(OpenSSL_FOUND)
        target_link_libraries(myapp 
            OpenSSL::SSL 
            OpenSSL::Crypto
        )
        target_include_directories(myapp PRIVATE ${OPENSSL_INCLUDE_DIR})
    else()
        message(FATAL_ERROR "OpenSSL not found!")
    endif()
    
    1. For older CMake versions (before 3.4), you might need to use the variables directly:
    find_package(OpenSSL REQUIRED)
    target_link_libraries(myapp 
        ${OPENSSL_LIBRARIES}
    )
    target_include_directories(myapp PRIVATE ${OPENSSL_INCLUDE_DIR})
    

    The modern CMake approach with OpenSSL::SSL and OpenSSL::Crypto targets is preferred as it automatically handles include directories and is more portable.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.