Alexis Clarembeau Alexis Clarembeau - 1 year ago 79
C Question

Add source to an existing automake program

I would like to edit an existing software to add a new source file (Source.cpp).
But, I can't manage the compilation process (it seems to be automake and it looks very complicated).

The software (iperf 2: is compiled using a classical

make install

If I just add the file to the corresponding source and include directory, I got this error message:

Settings.cpp:(.text+0x969) : undefined reference to ...

It looks like the makefile isn't able to produce the output file associated with my new source file (Source.cpp). So, I probably need to indicate it manually somewhere.

I searched a bit in the project files and it seemed that the file to edit was: "".
I added my source to the variable
in that file but it didn't workded.

Could you help me to find the file where I need to indicate my new source file (it seems a pretty standard compilation scheme but I never used automake softwares and this one seems very complicated).

Thank you in advance

Answer Source

This project is built with the autotools, as you already figured out.

The makefiles are built by automake. It takes its input in files that usually have a am file name extension.

The iperf program is built by the makefile generated from src/ This is indicated by:

bin_PROGRAMS = iperf

All (actually this is a simplification, but which holds in this case) source files of a to be built binary are in the corresponding name_SOURCES variable, thus in this case iperf_SOURCES. Just add your source file to the end of that list, like so (keeping their formatting):

iperf_SOURCES = \
                Client.cpp \
# lines omitted
                tcp_window_size.c \

Now, to reflect this change in any future generated src/Makefile you need to run automake. This will modify src/, which is a template that is used by config.sub at the end of configure to generate the actual makefile.

Running automake can happen in various ways:

  • If you already have makefiles that were generated after an configure these should take care of rebuilding themselves. This seems to fail sometimes though!

  • You could run automake (in the top level directory) by hand. I've never done this, as there is the better solution to...

  • Run autoreconf --install (possibly add --force to the arguments) in the top level directory. This will regenerate the entire build system, calling all needed programs such as autoheader, autoconf and of course automake. This is my favorite solution.

The later two options require calling configure again, IMO ideally doing an out of source built:

# in top level dir 
mkdir build
cd build
../configure # arguments 
make # should now also compile and link your new source file
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download