I'm working on a test for GCC init_priority
and MSC init_seg
. I want to craft a test to compile and link two source files in a specific order.
I'm having trouble finding information on compiling and linking two source files using AC_COMPILE_IFELSE
or AC_LINK_IFELSE
. The Autoconf docs don't appear to discuss the use case. Searching for terms like "Autoconf test with two source files" are returning irrelevant results. I think I might be missing good search terms.
Is it possible to use two source files during an Autoconf test? If so, then how do I do it?
AC_COMPILE_IFELSE
andAC_LINK_IFELSE
do not serve the purpose you describe, and they are not intended to do. Each takes one source, performs its test, and cleans up after itself. I didn't even find a macro for what you want at the Autoconf archive, which provides a number of sometimes-useful macros that don't ship with Autoconf itself. What you're proposing to do is far out of the ordinary, so if you want to proceed then I think you'll need to roll your own. Possibly it would help to consult the implementations ofAC_COMPILE_IFELSE
andAC_LINK_IFELSE
.But do sit back and have a think first, because I don't think such a test would be meaningful anyway. C++ relative initialization order across translation units is completely unspecified without use of an extension such as
init_priority
orinit_seg
. The language provides no justification for an assumption that it has anything to do with the order in which objects appear on a linker command line, nor even for an assumption that initializations arising from different TUs won't be intermixed. Thus, even if a test of cross-TU initialization happens to pass, that does not convey any actionable information, because there's no basis for certainty that whatever characteristic you are trying to test is responsible for the success.I considered suggesting just a test for in-TU initialization reordering via
init_priority
, which you could perform withAC_RUN_IFELSE
. That's not useful to you either, however, because you apparently need to support MSVC++, which does not provide a mechanism to modulate initialization order at that granularity.Ultimately, then, I think the best you can do is to test whether
init_priority
orinit_seg
is accepted at all by the compiler (which you can do withAC_COMPILE_IFELSE
), and suppose that if so, it in fact does the job it is supposed to do.