How to link openssl lib with Bazel on Windows?

138 views
Skip to first unread message

Danylo Ulianych

unread,
Jan 18, 2023, 3:57:47 PM1/18/23
to bazel-discuss
Hello Bazel community,
I have trouble building a source code that uses openssl with Bazel on Windows.
The code relevant part:

int main() {
        auto cipher = EVP_aes_256_gcm();
        auto ctx = EVP_CIPHER_CTX_new();

        return 0;
}

and the Bazel BUILD file:

cc_library(
    name = "check_license",
    srcs = ["cpprest/check_license_offline.cc"],
    hdrs = ["cpprest/my_header.h"],
    deps = [
        "//mediapipe/framework/port:cpprest",
    ],
    linkopts = select({
        "//mediapipe:windows": [
            "-DEFAULTLIB:cpprest_2_10.lib",
        ],
        "//conditions:default": [
            "-lcpprest",
            "-lboost_system",
            "-lssl",
            "-lcrypto",
        ],
    }),
)

and I'm getting a whole bunch of errors on Windows at the linking stage:

check_license.lib(check_license_offline.obj) : error LNK2019: unresolved external symbol EVP_aes_256_gcm referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > (message clipped)"

I have no issues on Linux with the same BUILD script.

How to fix this on Windows?

Thanks.

Dimiter “malkia” Stanev

unread,
Feb 10, 2023, 4:02:13 PM2/10/23
to bazel-discuss
On windows you are linking (only) to cpprest_2_10.lib but it's not clear what this entails. On linux you are linking to ssl/crypto where this symbol is defined (not sure if in ssl or crypto - but in one of these).

It's possible that cpprest_2_10.lib has also /DEFAULTLIB:<ssl|crypto.lib> of sorts, but I'm not sure. But maybe not.

You can use some custom command-line options for Windows to track this down:
Add to your linkopts also this  /VERBOSE:lib or look for more messages here - https://learn.microsoft.com/en-us/cpp/build/reference/verbose-print-progress-messages?view=msvc-170 - this would tell what .libs were looked at, ignored, etc.

Danylo Ulianych

unread,
Feb 11, 2023, 4:03:25 AM2/11/23
to bazel-discuss
The problem was with missing libeay32.lib in the app built on Windows. Adding this lib to a particular place fixed the issue. Thanks.
Reply all
Reply to author
Forward
0 new messages