Skip to contentSkip to conversation

libtracefs: Link unit test to use static local library

PATCH Superseded Tzvetomir Stoyanov (VMware) 2 participants 2 messages Jan 7, 2021 – Jan 12, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracefs: Link unit test to use static local library

Unit test must test the library located in the sorce tree, instead the one installed in the system.

---
 utest/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utest/Makefile +1 -1
index 403540a..6e9c760 100644
@@ -12,7 +12,7 @@ OBJS += tracefs-utest.o
 
 LIBS += -lcunit				\
 	-ldl				\
-	-L$(obj)/lib/tracefs -ltracefs
+	-L$(obj)/lib/tracefs -l:libtracefs.a
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)
Signature · 1 line
2.29.2
#1 lore raw
Quoted 2 lines · On Thu, 7 Jan 2021 10:32:08 +0200 "Tzvetomir Stoyanov (VMware)"…

Unit test must test the library located in the sorce tree, instead the one installed in the system.

I don't think this does what you want it to do.

Quoted 11 lines
---
 utest/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utest/Makefile +0 -0
index 403540a..6e9c760 100644

utest/Makefile OBJS += tracefs-utest.o · line 18

Quoted 8 lines
utest/Makefile +1 -1
@@ -12,7 +12,7 @@ OBJS += tracefs-utest.o
 
 LIBS += -lcunit				\
 	-ldl				\
-	-L$(obj)/lib/tracefs -ltracefs
+	-L$(obj)/lib/tracefs -l:libtracefs.a
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)

OK, I added to src/tracefs_events.c:

void tracefs_hello(void)

{
	printf("hello world!\n");
}

And then to utest/trace-utest.c in main():

	void tracefs_hello(void);
	tracefs_hello();

And try building. It caused this:

/usr/bin/ld: /work/git/libtracefs.git/utest/trace-utest.o: in function `main':
/work/git/libtracefs.git/utest/trace-utest.c:38: undefined reference to `tracefs_hello'
collect2: error: ld returned 1 exit status

That's because I have libtracefs.a installed as well as libtracefs.so, and it is using the system libtracefs.a and not the local one.

But by making the following change:

utest/Makefile +1 -1
index 6e9c760..4899365 100644
@@ -12,7 +12,7 @@ OBJS += tracefs-utest.o
 
 LIBS += -lcunit				\
 	-ldl				\
-	-L$(obj)/lib/tracefs -l:libtracefs.a
+	$(obj)/lib/tracefs/libtracefs.a
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)

It builds.

I just use the full path to the library, instead of using the linker option.

-- Steve