Sign in to follow this  
AdamGL

Building source via Makefile

Recommended Posts

AdamGL    130
Hello everyone! I am pretty new to the whole Open Source scene, and I decided that I would give some of the SDKs on sourceforge.net a try. Instead of going for the binary downloads, I decided to try and compile the source code for the project (this one being jpeg-6b). And here my troubles began. I perused the source several times and found out that Makefiles were what gave the compiler the necessary information to compile the project. Several Google searches gave me Linux only tutorials on makefiles which didn't really help me, since I'm using MSVC++ 2008 Express on Windows XP. So, I tried some simple "nmake /f makefile.vc libjpeg.lib" as was recommended in one of the docs, but alas, I get the error that win32.mak could not be found. So my question is, how do I compile existing code? I'm guessing there is a graphical way of doing it too, so I would like to know both methods: GUI in the MSVC++ IDE and command line. Thank you for taking the time to read this. I never really thought about what happens to my C++ code when I compile it. Now I see it's no trivial matter...

Share this post


Link to post
Share on other sites
jpetrie    13154
Quote:

I'm guessing there is a graphical way of doing it too, so I would like to know both methods: GUI in the MSVC++ IDE and command line.

Nope, there isn't. At least, not always. But generally, unless the code comes with a .vcproj, you won't be building it in Visual Studio unless you make your own .vcproj for it -- this isn't particularly complex, usually, but how you do it depends entirely on the code. Sometimes you can get away with making a blank .vcproj, adding all the source code from the project, hitting build, and getting results.

Other times, more work is involved. VS can also support .vcproj's that are directed to build a command-line makefile, but this basically involves putting the make invocation in a little field in the .vcproj properties, so you need to know how to execute the command-line build first.

Share this post


Link to post
Share on other sites
frob    44972
>> I perused the source several times and found out that Makefiles were what gave the compiler the necessary information to compile the project.

Sort of. Make files are a bunch of rules that (basically) look at time stamps. If the target is older than the sources, it feeds filenames and parameters at a program. In most cases the file names are the .c and .cpp files, and the program is a compiler and/or linker. They generally don't do a whole lot.


>> I tried some simple "nmake /f makefile.vc libjpeg.lib" as was recommended in one of the docs, but alas, I get the error that win32.mak could not be found.

Since it is on SourceForge, use their forums (that is an active project) and ask them about it. Mention that you've already read several faqs, include the link to the instructions you tried, and give the exact error messages you encountered.

>> So my question is, how do I compile existing code? I'm guessing there is a graphical way of doing it too, so I would like to know both methods: GUI in the MSVC++ IDE and command line.

Command line by itself isn't much. Starting out with a single source file it is easy enough: cl test.cpp
That will attempt to compile, link with default libraries, and spew forth an executable.

make, nmake, nant, vcproj, and countless other tools aren't there for the simple command lines, they're mostly for when you have a group of many files and assorted options you need to take care of. Those are much more complex than just command line compilation.

For a mature code base like libjpeg, you are best allowing the experts who maintain the project answer your questions and point you to a tutorial or FAQ.

>> I never really thought about what happens to my C++ code when I compile it. Now I see it's no trivial matter...

It is a good thing to learn. Once you learn it, you'll immediately want to find ways to automate it.

One task of our build tools involves auto-generating the vcproj files, which are fairly simple xml documents. Since we use nant, that means that visual studio can call the build tools. When a file is added, the vcproj is updated during the build to include the new file, so nothing is ever out of date. We have an automated build system that continuously builds and tests the games from nant scripts, so they don't need the gui. It's a beautiful system. /me offers a hug to the tools team.

Share this post


Link to post
Share on other sites
werekarg    193
i think win32.mak was used on older vc versions. anyway...

first, it is advised to run Common7\Tools\vsvars32.bat

then, makefile.vc must be modified a little bit, i think, again, it hasnt been updated for newer vc version. do this:

- comment !include <win32.mak>
- add after the newly commented line these lines:

cc=cl.exe
link=link.exe
cflags=-c


then nmake -f makefile.vc libjpeg.lib

and watch the marvel unfolding [wink]

Share this post


Link to post
Share on other sites
daviangel    604
You must be a glutton for punishment!
I'm serious the only time I compile is when there is no binaries available!
In the early day of Linux I'm talking redhat 5, suse 6 ,etc before they had decent package managers and binaries,etc the process ususally went like this:
extract source somewhere and from terminal run the following commands:

./configure
make
make install

wait and hope there were no errors and tada you have your binary!
I have no idea what you are trying to do on windows but I imagine it'd be more work since most open source makefiles I believe would be aimed at gcc and it's make tools and not cl and windows make tools(hence the error message about win32.mak missing since there isn't one!).
If there are windows specific make files available it should've been noted in your download and if not all I can say is good luck trying to make them.

Share this post


Link to post
Share on other sites
AdamGL    130
I researched some more and downloaded Cygwin and got that running nicely. So I went to the directory of the project and typed:

./configure

and already it complained I'm missing things. I know they're dependancies and I made a point of including them but nothing works. Does anybody know of a resource that will explain to me how these automated building scripts work? Even one that will teach me so I can learn from scratch.

Share this post


Link to post
Share on other sites
joe_bubamara    100
You first stop is ALWAYS files: README and INSTALL for any project from sf.

Mannnnnyyyyy projects these days are cross-platfrom and are ment from the very start to work on at least linux + win32 platforms. What projects do you plan to compile? If there is nothing mentioned about windows platform, then that project does not have a windows port! In that case you have to make it yourself, for example Wallgrind is one wonderfull project which unfortunately does not work on windows (maybe through some interix or cygwin magic, but I am not sure). There are reasons, so good luck if you can port it :-).

configure files are mostly NOT used for windows native compiles (unless you go through cygwin or interix). Usually there are visual studio projects, either by original authors or by community or it is make or nmake files. Use google, ask for project name + vs build. In early versions, like legendary 6.0 version, VS used makefiles as well. However windows make utility was "a bit" - modfied from the gnu version, so makefiles are not compatible. There is still nmake utility which is m$ version of makefiles. You can also compile with gnu make if you just give it right paths and flags, but you can not just download the code and then type make as if you are doign linux build. Again - read docs, there is usually info needed to get various platform builds ... somewhere in some file.

well ... linux tutorials for autoconf, make, configure & co are still valid. These are same apps, no matter platform. So same knowledge applies.

As you discovered in your research there is cygwin, which is posix/*nix emulation layer for windows. You might also try SFU (or interix) as a better integrated, but buggier posix environment on win32 platform. Also check gnuwin32 project which is windows native port of many unix tools. Another indispensible tool to have on your machine is msys and mingw port of gcc. By the way msys is the only one that ports rxvt to native win32 which gives you best command window yet (win powershell is just a joke compared to rxvt+bash).

www.mingw.org - for msys
http://gnuwin32.sourceforge.net/ - for natively compiled gnu apps

By the what projects from sf did you try to compile?

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