Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force test program to be linked to static library built by libtool

I have a library managed by autotools. I have the following line in the Makefile.am, as well as other necessary configurations

lib_LTLIBRARIES = libstuff.la

My project also builds a program to run some test suites. This program is configured as follows:

noinst_PROGRAMS = runtests
runtests_SOURCES = test/stuff.c stuff.h
runtests_LDADD = libstuff.la

However, the program is always linked to the dynamic version of libstuff.la, which complicates some situations (for example, debugging with gdb). How could I force the program to be linked against libstuff.a instead of libstuff.so or equivalent dynamic library?

like image 322
brandizzi Avatar asked Jan 18 '23 00:01

brandizzi


1 Answers

The right way to do this is to add the -static flag to an LDFLAGS variable. For all targets: AM_LDFLAGS = -static

Or specifically for the test program: runtests_LDFLAGS = -static

like image 186
Brett Hale Avatar answered Mar 05 '23 14:03

Brett Hale