0

I'm writing a simple Bazel BUILD file but I have to include MKL library. My main.c include this library:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "omp.h"
#include "mkl.h"
#include "mkl_types.h"
#include "mkl_dfti.h"

The last 3 libs that are located in $MKLROOT set by a module environment. My bazel build file is:

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")


cc_library(

    name = "mkl_headers",
    srcs = glob(["include/*(.cc|.cpp|.cxx|.c++|.C|.c|.h|.hh|.hpp|.ipp|.hxx|.inc|.S|.s|.asm|.a|.lib|.pic.a|.lo|.lo.lib|.pic.lo|.so|.dylib|.dll|.o|.obj|.pic.o)"]),
    includes = ["include"],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "mkl_libs_linux",
    srcs = [
        "lib/libiomp5.so",
        "lib/libmklml_intel.so",
    ],
    visibility = ["//visibility:public"],
)

cc_binary(
    name = "mklfft",
    srcs = ["main.c"],
    deps = [
        ":mkl_libs_linux"
    ],
)

I tried to take an example from the BUILD tensorflow mkl file but it's very complicated.

The bazel build command return:

INFO: Analyzed target //mklfft:mklfft (2 packages loaded, 8 targets configured).
INFO: Found 1 target...
ERROR: missing input file 'mklfft/mkl.h', owner: '//mklfft:mkl.h'
ERROR: missing input file 'mklfft/mkl_dfti.h', owner: '//mklfft:mkl_dfti.h'
ERROR: missing input file 'mklfft/mkl_types.h', owner: '//mklfft:mkl_types.h'
ERROR: /C/mklfft/BUILD:6:1: //mklfft:mkl: missing input file '//mklfft:mkl.h'
ERROR: /C/mklfft/BUILD:6:1: //mklfft:mkl: missing input file '//mklfft:mkl_dfti.h'
ERROR: /C/mklfft/BUILD:6:1: //mklfft:mkl: missing input file '//mklfft:mkl_types.h'
ERROR: missing input file 'mklfft/readFile.c', owner: '//mklfft:readFile.c'
Target //mklfft:mklfft failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /C/mklfft/BUILD:6:1 3 input file(s) do not exist
INFO: Elapsed time: 0.342s, Critical Path: 0.03s
INFO: 0 processes.

Can you clarify the method to link external shared libraries with bazel?

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
epascolo
  • 135
  • 2
  • 9

1 Answers1

1

linking with "lib/libiomp5.so", "lib/libmklml_intel.so", it's not enough. You need to add libmkl_intel_thread.so and -libmkl_core.so also. Please check mkl linker adviser to see what mkl suggests to use:
https://software.intel.com/content/www/us/en/develop/articles/intel-mkl-link-line-advisor.html

Gennady.F
  • 571
  • 2
  • 7