Search code examples
cmakefileautoconfautomake

How do I compile and install an individual object file with Automake?


I'm looking to build and install an object file (crt1.o, a C startup file) into the library directory (/usr/lib) with Automake and Autoconf.

So, my initial though about doing this was to create a crt_DATA variable inside the Makefile.am file, and define special targets on how to build the file. However, this idea has an issue: the file would be installed in a data directory instead of a library directory.

I then proceeded to try adding crt1.o to the lib_LIBRARIES section of my Makefile.am and creating crt1_o_SOURCES. However, this gave an error:

error: 'crt1.o' is not a standard library name

At this point, I could not think of any more possible ways to do this.

How do I compile and install an individual object file using Automake?


Very specific requirements:

  • crt1.o cannot be built into its own shared library or archive. It has to be just an object file. It's mandated by the compiler to be this way, so I have my hands tied.

  • It would be lovely if this file could be tracked and installed to the correct place if DESTDIR is changed.


Solution

  • Generally an object file is not useful by itself. I can't be run, and it can't be used except to link to other object files to make a program.

    You probably want a "shared object" file, or a .so file, if you want to build a library. Or, if you are keen to have the library statically linked, you might want a "library file", or a .la file.

    Automake uses Libtool to build both kinds of library files, but it can get complicated. That's because these library files are a bit different across multiple platforms, and automake/libtool attempts to handle the platform differences for you.

    Assuming that the above information isn't what you need, and you really want to install the .o file, then you should add the following to your Makefile.am

    somethingdir = /path/to/where/you/want/the/file
    something_DATA = the_file.o
    

    This treats the object file as a data file, and installs the data file at the chosen path.

    Again, I'm nearly certain that this is not what you really need, but at least you do know how to install an object file.

    What you probably need is one of:

    1. Build the object file into an executable, and install that executable
    2. Build the object file into a shared object library, and install that library
    3. Build the object file into a library archive (that's an .la file), and install that library archive.

    as plain object files, .o files, cannot easily be used without the required header files used to build them, and often the Makefiles and build system used to build them too.