Hi Jeffrey, On 11/2/17, Jeffrey Walton <noloa...@gmail.com> wrote: > I'm working on adding Autotools to a C++ library and test program. My > Automake.am has: > > lib_LTLIBRARIES = \ > libcryptopp.la > > libcryptopp_la_SOURCES = \ > cryptolib.cpp \ > cpu.cpp \ > integer.cpp \ > <remaining files in alphabetical order> > ... > > cpu.cpp needs additional flags to enable ISAs on IA-32, Aarch64 and > Power7/Power8. According to > https://www.gnu.org/software/automake/manual/html_node/Per_002dObject-Flags.html, > I need to add an additional library: > > CPU_FLAG = -msse2 -msse3 -mssse3 > libcpu_a_SOURCES = cpu.cpp > libcpu_a_CXXFLAGS = $(CXXFLAGS) $(CPU_FLAG)
Note that you should not include $(CXXFLAGS) here. CXXFLAGS is always included (so with this it will duplicated on the command line, which might be undesired by the user). > Now that the objects are built we need to add libcpu.a back into > libcryptopp.la in the exact position it would have been in if I could > have specified per-object flags. The Automake manual gives an example > of linking a program with disjoint libraries, but not adding the > extraneous library back to the main (primary?) library at a particular > position. > > The "in the exact position" is important. Not too familiar with C++ stuff but I would be a bit concerned that it might not be possible at all to force a particular link order for the objects in the static version of the library. Nevertheless for the shared library case you can probably achieve this using several dummy libraries. Something like this should work OK (totally untested): lib_LTLIBRARIES = libfoo.la EXTRA_LTLIBRARIES = libdummy1.la libdummy2.la libdummy3.la libdummy1_la_SOURCES = a.cpp b.cpp libdummy2_la_SOURCES = c.cpp d.cpp libdummy2_la_CXXFLAGS = -mstuff libdummy3_la_SOURCES = e.cpp f.cpp libfoo_la_SOURCES = libfoo_la_LIBADD = $(libdummy1_la_OBJECTS) \ $(libdummy2_la_OBJECTS) \ $(libdummy3_la_OBJECTS) and then the linking order should be a, b, c, d, e, f -- with c and d compiled using your special flags. Cheers, Nick