build: explicitly link unit tests with static libraries

Unit tests define mock functions in the unit test code
itself.  This links fine with static libraries, but
doesn't work if trying to link with shared libraries.

So change the unit tests to always explicitly link
with the static libraries.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I3a8a60162fcab6c73a216c4bb364175767fdc62c

Reviewed-on: https://review.gerrithub.io/422441
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2018-08-15 09:32:03 -07:00
parent afca551212
commit 5e181ba84f
2 changed files with 10 additions and 1 deletions

View File

@ -63,4 +63,13 @@ SPDK_LIB_LINKER_ARGS = \
-Wl,--no-whole-archive \
$(SPDK_REMAINING_LIB_LIST:%=-lspdk_%)
# This is primarily used for unit tests to ensure they link when shared library
# build is enabled. Shared libraries can't get their mock implementation from
# the unit test file.
SPDK_STATIC_LIB_LINKER_ARGS = \
-Wl,--whole-archive \
$(SPDK_WHOLE_ARCHIVE_LIB_LIST:%=$(SPDK_ROOT_DIR)/build/lib/libspdk_%.a) \
-Wl,--no-whole-archive \
$(SPDK_REMAINING_LIB_LIST:%=$(SPDK_ROOT_DIR)/build/lib/libspdk_%.a)
install: all

View File

@ -42,7 +42,7 @@ CFLAGS += -I$(SPDK_ROOT_DIR)/test
SPDK_LIB_LIST += thread util log spdk_mock sock
LIBS += -lcunit $(SPDK_LIB_LINKER_ARGS)
LIBS += -lcunit $(SPDK_STATIC_LIB_LINKER_ARGS)
APP = $(TEST_FILE:.c=)