diff mbox series

[blktests] src/Makefile: fix static linking of miniublk

Message ID 20230803212052.1173449-1-tytso@mit.edu (mailing list archive)
State New, archived
Headers show
Series [blktests] src/Makefile: fix static linking of miniublk | expand

Commit Message

Theodore Ts'o Aug. 3, 2023, 9:20 p.m. UTC
When using static linking, the libraries need to be placed after the
.o or .c files so they are searched.  Otherwise, the build will fail:

cc -O2 -Wall -Wshadow  -DHAVE_LINUX_BLKZONED_H  -D_GNU_SOURCE -lpthread -luring -o miniublk miniublk.c
/bin/ld: /tmp/ccfjiUvb.o: in function `ublk_ctrl_init':
miniublk.c:(.text+0xaeb): undefined reference to `io_uring_queue_init_params'
/bin/ld: /tmp/ccfjiUvb.o: in function `ublk_queue_deinit':
miniublk.c:(.text+0xb73): undefined reference to `io_uring_unregister_ring_fd'
/bin/ld: miniublk.c:(.text+0xb85): undefined reference to `io_uring_unregister_files'
/bin/ld: /tmp/ccfjiUvb.o: in function `ublk_io_handler_fn':
miniublk.c:(.text+0xd62): undefined reference to `io_uring_queue_init_params'
/bin/ld: miniublk.c:(.text+0xd77): undefined reference to `io_uring_register_ring_fd'
/bin/ld: miniublk.c:(.text+0xd8c): undefined reference to `io_uring_register_files'
/bin/ld: miniublk.c:(.text+0xe94): undefined reference to `io_uring_submit_and_wait_timeout'
/bin/ld: /tmp/ccfjiUvb.o: in function `__ublk_ctrl_cmd':
miniublk.c:(.text+0x14a6): undefined reference to `io_uring_submit'
/bin/ld: miniublk.c:(.text+0x1533): undefined reference to `__io_uring_get_cqe'
collect2: error: ld returned 1 exit status
make: *** [Makefile:61: miniublk] Error 1

Fixes: d42fe976 ("src: add mini ublk source code")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 src/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Shinichiro Kawasaki Aug. 7, 2023, 6:25 a.m. UTC | #1
On Aug 03, 2023 / 17:20, Theodore Ts'o wrote:
> When using static linking, the libraries need to be placed after the
> .o or .c files so they are searched.  Otherwise, the build will fail:
> 
> cc -O2 -Wall -Wshadow  -DHAVE_LINUX_BLKZONED_H  -D_GNU_SOURCE -lpthread -luring -o miniublk miniublk.c
> /bin/ld: /tmp/ccfjiUvb.o: in function `ublk_ctrl_init':
> miniublk.c:(.text+0xaeb): undefined reference to `io_uring_queue_init_params'
> /bin/ld: /tmp/ccfjiUvb.o: in function `ublk_queue_deinit':
> miniublk.c:(.text+0xb73): undefined reference to `io_uring_unregister_ring_fd'
> /bin/ld: miniublk.c:(.text+0xb85): undefined reference to `io_uring_unregister_files'
> /bin/ld: /tmp/ccfjiUvb.o: in function `ublk_io_handler_fn':
> miniublk.c:(.text+0xd62): undefined reference to `io_uring_queue_init_params'
> /bin/ld: miniublk.c:(.text+0xd77): undefined reference to `io_uring_register_ring_fd'
> /bin/ld: miniublk.c:(.text+0xd8c): undefined reference to `io_uring_register_files'
> /bin/ld: miniublk.c:(.text+0xe94): undefined reference to `io_uring_submit_and_wait_timeout'
> /bin/ld: /tmp/ccfjiUvb.o: in function `__ublk_ctrl_cmd':
> miniublk.c:(.text+0x14a6): undefined reference to `io_uring_submit'
> /bin/ld: miniublk.c:(.text+0x1533): undefined reference to `__io_uring_get_cqe'
> collect2: error: ld returned 1 exit status
> make: *** [Makefile:61: miniublk] Error 1
> 
> Fixes: d42fe976 ("src: add mini ublk source code")
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Thanks, applied!
diff mbox series

Patch

diff --git a/src/Makefile b/src/Makefile
index 1365480..c902649 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -39,7 +39,8 @@  CONFIG_DEFS := $(call HAVE_C_HEADER,linux/blkzoned.h,-DHAVE_LINUX_BLKZONED_H)
 override CFLAGS   := -O2 -Wall -Wshadow $(CFLAGS) $(CONFIG_DEFS)
 override CXXFLAGS := -O2 -std=c++11 -Wall -Wextra -Wshadow -Wno-sign-compare \
 		     -Werror $(CXXFLAGS) $(CONFIG_DEFS)
-MINIUBLK_FLAGS :=  -D_GNU_SOURCE -lpthread -luring
+MINIUBLK_FLAGS :=  -D_GNU_SOURCE
+MINIUBLK_LIBS := -lpthread -luring
 LDFLAGS ?=
 
 all: $(TARGETS)
@@ -58,6 +59,7 @@  $(CXX_TARGETS): %: %.cpp
 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $^
 
 $(C_MINIUBLK): %: miniublk.c
-	$(CC) $(CFLAGS) $(LDFLAGS) $(MINIUBLK_FLAGS) -o $@ miniublk.c
+	$(CC) $(CFLAGS) $(LDFLAGS) $(MINIUBLK_FLAGS) -o $@ miniublk.c \
+		$(MINIUBLK_LIBS)
 
 .PHONY: all clean install