On Fri, May 22, 2009 at 8:04 AM, James Coleman <jam...@dspsrv.com> wrote:
...
> 4.
> I notice that adding a static library doesn't get picked up by a default
> rule. I'm not going to dig further into this. My syntax for libs might be
> wrong, makefile.lib:
> executable: othercfile.o staticlibrary.a
>
> staticlibrary.a: yetanothercfile.o
>
>
> $ make -f makefile.lib
> g++    -c -o othercfile.o othercfile.cpp
> g++    -c -o yetanothercfile.o yetanothercfile.cpp
> g++     executable.cpp othercfile.o staticlibrary.a   -o executable
> g++: staticlibrary.a: No such file or directory
> make: *** [executable] Error 1

Almost.  To trigger the built-in library archiving rules you need this:

executable: othercfile.o staticlibrary.a
staticlibrary.a: staticlibrary.a(yetanothercfile.o)

$ make
g++    -c -o othercfile.o othercfile.cpp
g++    -c -o yetanothercfile.o yetanothercfile.cpp
ar rv staticlibrary.a yetanothercfile.o
ar: creating staticlibrary.a
a - yetanothercfile.o
g++     executable.cpp othercfile.o staticlibrary.a   -o executable
rm yetanothercfile.o
$


However:
1) the syntax is annoyingly redundant, using the .a name twice
2) it unnecessarily rebuilds the archive's symbol table after each addition
3) it breaks if you have multiple files in the archive and use parallel make

(If your system's ar doesn't rebuild the symbol-table by default, the
(2) doesn't apply, but your archives don't have symbol-tables!)

Much better is to write a command that handles all the changed archive
members in one go:

staticlibrary.a: yetanothercfile.o yacf.o
        $(AR) $(ARFLAGS) $@ $?


Philip Guenther


_______________________________________________
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make

Reply via email to