0

I have a small project that requires a few standard libraries, say libpng and boost. For now I hope that project can build easily on any of my collaborators machines (OSX/Unix/Linux), but am not concerned packaging or installing it right now. My question is, is there an easy way to write "home-brewed" Makefile or configure file that can automatically find and use those libraries on a particular *nix system?

I know Autoconf and CMake are tools designed for such tasks, but I and my collaborators do not want to go into the fuss for such a small project, at least not right now.

Another possibility I have in mind is pkg-config. Is that a recommended approach? I currently have two problems with that: (1) it cannot find all libraries, (say boost, discussed here, here and here), and (2) not all system seems to have installed pkg-config.

The solution I hope to have ishave in mind is to write a Makefile that looks like below.

INCpng = $(shell command retrieves "-I/path/to/png.h")
LIBpng = $(shell command retrieves "-L/path/to/libpng.so -lpng")

INCboost = $(shell command retrieves "-I/path/to/boost")
LIBpng = $(shell command retrieves "-L/path/to/libboost.so -lboost")

SomeFile: SomeFile.cc
    $(CXX) $(CXXFLAGS) $(INCpng) $(INCboost) $(LIBpng) $(LIBboost) -o $@ $<

I'm also open to write a not-to-complicated configure file.

Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
Ying Xiong
  • 4,578
  • 8
  • 33
  • 69

1 Answers1

1

pkg-config was designed for more-or-less exactly this purpose. It was designed to replace the X-config scripts/etc. that many projects had been writing on their own before that.

I don't know about CMake but I believe the autotools are just using pkg-config internally.

For things that pkg-config cannot find (and that do not have their own X-config) the only thing you can do is use reasonable defaults and allow people to over-ride them (you could test some common alternatives as fallback defaults as well but you still need to allow user over-riding.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148