diff mbox series

libtracefs: Link unit test to use static local library

Message ID 20210107083208.15967-1-tz.stoyanov@gmail.com (mailing list archive)
State Superseded
Headers show
Series libtracefs: Link unit test to use static local library | expand

Commit Message

Tzvetomir Stoyanov (VMware) Jan. 7, 2021, 8:32 a.m. UTC
Unit test must test the library located in the sorce tree, instead the
one installed in the system.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 utest/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Steven Rostedt Jan. 12, 2021, 9:32 p.m. UTC | #1
On Thu,  7 Jan 2021 10:32:08 +0200
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> 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.

> 
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> ---
>  utest/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/utest/Makefile b/utest/Makefile
> index 403540a..6e9c760 100644
> --- a/utest/Makefile
> +++ b/utest/Makefile
> @@ -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:

diff --git a/utest/Makefile b/utest/Makefile
index 6e9c760..4899365 100644
--- a/utest/Makefile
+++ b/utest/Makefile
@@ -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
diff mbox series

Patch

diff --git a/utest/Makefile b/utest/Makefile
index 403540a..6e9c760 100644
--- a/utest/Makefile
+++ b/utest/Makefile
@@ -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)