Sign in to follow this  
pressgreen

Makefile madness

Recommended Posts

Can any one please in layman's terms explain "Makefiles". I would like to build a library that comes with make files but I don't understand them at all. I use visual studio 2010 as a compiler and I barely used gcc. So could any one try to take a stab at explaining it and its components with out getting to pedantic.

 

Thanks

Share this post


Link to post
Share on other sites

Makefiles are basically files that associate rules, dependencies, and actions to effectively build a program (and more - they are often used in compilation but have a wide variety of applications). That's all you need to know if you just want to know how to use one to build a library, but if you want to make a makefile (no pun intended) then you can always find a more detailed explanation on the internet.

 

If you are under Linux, this is easy, the make utility comes with your distribution. Just cd into the library's folder where the Makefile resides, and type "make" (or perhaps the library tells you to use "make setup", it depends on the makefile). Do that, and it should just work. If there's an error that comes up, try googling it, perhaps you need to run the makefile as superuser or you need to download and install some package first, etc..

 

If you are under Windows, let's just say your day is going to suck, at least in my experience. Makefiles just don't work all that well under Windows, if the library also comes with an IDE project file (visual studio, or whatever) prefer that to using makefiles IMHO. Otherwise I think you need to install CMake, and a bunch of other stuff, and then I don't know. Sorry :(

Edited by Bacterius

Share this post


Link to post
Share on other sites

To be honest, if it's visual C++, I'd just create a new static lib project, add all of the source files, hit compile, and hope for the best! :)
If it's a lib that only uses it's own methods/classes, then it's usually not too bad. If it's a lib with a tonne of external dependencies, then this may prove to be a nightmare! (and you may be better off with the makefile). You can set projects up to build a makefile in VC++, but I'm on linux at the moment, otherwise I'd have a quick look to remind myself.

Sometimes you may need to add a new define to the project settings for the lib to get it compiling. Have a hunt around in the headers for any #ifdef MY_LIB_FOO lines, and add that define to your project settings. Alternatively, look for any -DMY_FOO_LIB lines in the makefile. -D just means define, and that usually means you'll be wanting to use the identifier directly after it when building!

If the lib is supposed to compile to a DLL, you may want to create a dynamic library project instead of a static one (and you will definitely need to locate the BUILDING_MY_LIBRARY define, so that the lib gets compiled with declspec(dllexport). Alternatively, just delete the declspec from the headers leaving an empty macro in it's place.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this