Compiling with a Makefile

I'm a Windows user. I'm using Code::Blocks, and my c++ program utilizes and outside library (gmp). That means that I can't simply compile my program within Code::Blocks itself.

Rather, I have to use a Cygwin shell and compile it using this command:

g++ -o main main.cpp -lgmpxx -lgmp

I'd like to create a Makefile, so that I can pass this along to allow others to compile it easily, but I have very little experience with this. I tried to adapt a Makefile that was given to me for another project (done in Linux), but it's not working.

First, here is the Makefile as I have adapted it for my program:

1
2
3
4
5
6
7
8
9
10
11
12
CC = g++
CFLAGS = -O -lgmpxx -lgmp

OBJS = main.cpp

main: $(OBJS)
	$(CC) $(CFLAGS) -o main $(OBJS)

main.o: main.cpp

clean:
	rm -f *~ *.o main


I tried to execute this by calling:

make main

but I get an error from Cygwin
-bash: make command not found


Can anyone offer any advice, either to modify the Makefile or in how I execute it? Thanks!
The error message is not because of the makefile. It says that it can't find the make command, so I guess you have not installed make.
Uh, you can compile it within Code::Blocks.

Go to Settings > Compiler > Linker Settings.
Then either add the libgmpxx.a and libgmp.a files to the "Link Libraries" list, or type "-lgmpxx -lgmp" (without the quotes) under "Other Linker Options".

It won't affect any programs that don't use GMP, so you don't have to worry about that.
Long,
That's good to know. I didn't realize that I could do this. Another question: I have gmp compiled in my Cygwin directory. I assume that I can just browse over there to point to the two .a files. However, when I navigate over there, the closest things that I see are "libgmpxx.dll.a" and "libgmp.dll.a". Are these the same files? Can I use my Cygwin folder to access these or do I have to compile gmp again for code::blocks?

Peter,
You're right. I haven't installed make. I've only used it in Linux, and I don't ever even remember installing it over there. I'll have to install it and try again.

Both,
Does my makefile look OK or will I need to modify it?

Thanks a lot!
You don't necessary need Cygwin to use GNU Make because you already have one with MinGW inside Code::Blocks installation, just check that binaries are in system PATH. However, I'm not sure that you can build GMP library without either Cygwin or MSYS because of dependence on autotools build system. I presume that if you try hard enough eventually you can come up with a Code::Blocks project for the GMP library. This way you will be able to manage builds entirely from Code::Blocks IDE using a workspace.

Also, if you need a makefile for a Code::Blocks project you can use 'cbp2make' tool for that:

http://sourceforge.net/projects/cbp2make/
http://forums.codeblocks.org/index.php/topic,13675.0.html
Topic archived. No new replies allowed.