About Makefile to make a library not an executable file


This Makefile is a makefile that creates executable files.
Can you tell me how to change this with a makefile that creates a library (*.a)?

Thank you.

Something like,
gcc -c hello.c world.c /* compile hello.o and world.o /
ar rcs libmylib.a hello.o world.o /
packe them to limylib.a */


1 Like

If you use a modern build system like CMake or Meson it may be easier than writing your Makefiles by hand.

CMake example
Meson example


  • Meson is great with GStreamer and GLib but not so great with CUDA. It’s used to build a lot of open source projects and this is reflected in it’s design. If you like Python, you’ll probably like it.
  • Likewise, CMake is more popular and great with CUDA but can be harder than Meson when working with the GLib ecosystem(Gnome, Gtk, GStreamer, Vala, etc.).
  • Meson can use CMake subprojects but not the other way around (easily).

There is some level of investment to learing a build system, but It’s usally easier than writing your Makefiles by hand. The above choices are hardly exhaustive, but are the two I use on a regular basis for this purpose. You get a lot for free, like dependency management, generating config files, installing stuff, etc.

1 Like

@mdegans Thank you 👍😊

Come to Korea after the corona
I’ll buy you a drink.

1 Like

May take you up on that offer someday. Would love to visit Korea!

1 Like