Message ID | 1353828369-14493-1-git-send-email-computersforpeace@gmail.com |
---|---|
State | Accepted |
Commit | 3835899b3b29904eede98e0c22973a430c9cb1f9 |
Headers | show |
On Sat, 2012-11-24 at 23:26 -0800, Brian Norris wrote: > Technically, '-l' linker options should be included only after the > objects which must link to the library. So when we include '-lpthread' > in the LDFLAGS variable, it gets placed too early (i.e., before the > io_paral.o object), and so the pthread linkage never occurs. The > following error probably only shows up with linkers that don't link > pthreads by default. Pushed to mtd-utils, thanks!
diff --git a/tests/ubi-tests/Makefile b/tests/ubi-tests/Makefile index ace0120..c434a6f 100644 --- a/tests/ubi-tests/Makefile +++ b/tests/ubi-tests/Makefile @@ -8,7 +8,8 @@ LIBS = libubi TARGETS=io_update volrefcnt integ io_paral io_read io_basic \ mkvol_basic mkvol_bad mkvol_paral rsvol -CFLAGS += -I$(LIBUBI_HEADER_PATH) -I $(KERNELHDR) -lpthread +CFLAGS += -I$(LIBUBI_HEADER_PATH) -I $(KERNELHDR) +LDLIBS += -lpthread include ../../common.mk
Technically, '-l' linker options should be included only after the objects which must link to the library. So when we include '-lpthread' in the LDFLAGS variable, it gets placed too early (i.e., before the io_paral.o object), and so the pthread linkage never occurs. The following error probably only shows up with linkers that don't link pthreads by default. $ make tests V=1 ... gcc -I../../ubi-utils//include -I ../../include -lpthread -Wall -Wextra -Wwrite-strings -Wno-sign-compare -ffunction-sections -fdata-sections -Wl,--gc-sections -g -o /home/norris/git/mtd-utils/tests/ubi-tests/io_paral /home/norris/git/mtd-utils/tests/ubi-tests/io_paral.o /home/norris/git/mtd-utils/tests/ubi-tests/helpers.o libubi.a /home/norris/git/mtd-utils/tests/ubi-tests/io_paral.o: In function `main': /home/norris/git/mtd-utils/tests/ubi-tests/io_paral.c:287: undefined reference to `pthread_create' /home/norris/git/mtd-utils/tests/ubi-tests/io_paral.c:295: undefined reference to `pthread_create' /home/norris/git/mtd-utils/tests/ubi-tests/io_paral.c:303: undefined reference to `pthread_join' collect2: ld returned 1 exit status make[2]: *** [/home/norris/git/mtd-utils/tests/ubi-tests/io_paral] Error 1 ... $ ld --version GNU ld (GNU Binutils for Ubuntu) 2.22 ... $ gcc --version gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 ... Signed-off-by: Brian Norris <computersforpeace@gmail.com> --- tests/ubi-tests/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)