common/mlx5: fix build without dlopen option
authorTonghao Zhang <xiangxia.m.yue@gmail.com>
Fri, 6 Mar 2020 14:27:19 +0000 (22:27 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 18 Mar 2020 09:21:41 +0000 (10:21 +0100)
When setting the CONFIG_RTE_BUILD_SHARED_LIB to y,
and build the mlx5 pmd, there is a building error.
To fix it, add RTE_IBVERBS_LINK_DLOPEN to include
relative codes.

    mlx5_common.o: In function `mlx5_glue_init':
    drivers/common/mlx5/mlx5_common.c:324: undefined reference to `dlclose'

Fixes: 7b4f1e6bd367 ("common/mlx5: introduce common library")
Cc: stable@dpdk.org
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Tested-by: Ali Alnubani <alialnu@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
drivers/common/mlx5/mlx5_common.c
drivers/net/mlx4/mlx4.c

index 610fb48..9ea56f2 100644 (file)
@@ -2,10 +2,12 @@
  * Copyright 2019 Mellanox Technologies, Ltd
  */
 
-#include <dlfcn.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
+#ifdef RTE_IBVERBS_LINK_DLOPEN
+#include <dlfcn.h>
+#endif
 
 #include <rte_errno.h>
 
@@ -209,8 +211,6 @@ error:
  */
 RTE_INIT_PRIO(mlx5_glue_init, CLASS)
 {
-       void *handle = NULL;
-
        /* Initialize common log type. */
        mlx5_common_logtype = rte_log_register("pmd.common.mlx5");
        if (mlx5_common_logtype >= 0)
@@ -233,6 +233,8 @@ RTE_INIT_PRIO(mlx5_glue_init, CLASS)
        /* The glue initialization was done earlier by mlx5 common library. */
 #ifdef RTE_IBVERBS_LINK_DLOPEN
        char glue_path[sizeof(RTE_EAL_PMD_PATH) - 1 + sizeof("-glue")];
+       void *handle = NULL;
+
        const char *path[] = {
                /*
                 * A basic security check is necessary before trusting
@@ -320,8 +322,10 @@ RTE_INIT_PRIO(mlx5_glue_init, CLASS)
        mlx5_glue->fork_init();
        return;
 glue_error:
+#ifdef RTE_IBVERBS_LINK_DLOPEN
        if (handle)
                dlclose(handle);
+#endif
        DRV_LOG(WARNING, "Cannot initialize MLX5 common due to missing"
                " run-time dependency on rdma-core libraries (libibverbs,"
                " libmlx5)");
index a1dd658..8e29878 100644 (file)
@@ -8,7 +8,6 @@
  * mlx4 driver initialization.
  */
 
-#include <dlfcn.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <stddef.h>
@@ -18,6 +17,9 @@
 #include <string.h>
 #include <sys/mman.h>
 #include <unistd.h>
+#ifdef RTE_IBVERBS_LINK_DLOPEN
+#include <dlfcn.h>
+#endif
 
 /* Verbs headers do not support -pedantic. */
 #ifdef PEDANTIC