tags:

views:

696

answers:

1

I've got a GUI project (using Fast Light Toolkit) with the following components inside of it.

All of the headers and files listed here (note the Makefile.win)

http://www.stroustrup.com/Programming/Graphics/

and this is the file I'm trying to get to run.

#include "Simple_window.h"  // get access to our window library
#include "Graph.h"          // get access to our graphics library facilties

int main()
{
    using namespace Graph_lib; // our graphics facilities are in Graph_lib

    Point tl(100,100);         // to become top left corner of window

    Simple_window win(tl,600,400,"Canvas"); // make a simple window

    Polygon poly; // make a shape (a polygon)

    poly.add(Point(300,200));     // add point
    poly.add(Point(350,100));     // add another point
    poly.add(Point(400,200));     // add a third point

    poly.set_color(Color::red);   // adjust properties of poly

    win.attach(poly);             // connect poly to window

    win.wait_for_button();        // give control to display engine
}

At first when I tried to compile I got an error saying

File: C:\Dev-Cpp\Makefile.win
Error: [Build Error] [Projectname.exe] Error 1

Then I went into project options and selected "Use custom makefile" selected the custom makefile from the website which is saved in my C++ folder (and is part of the project.)

When I did this I got

File: C:\Users\Alex\Makefile.win (this is a different makefile.win)
Error: [Build Error] No rule to make target 'c12_3.cpp'(the file I'm compiling)
       needed by 'c12_3.o'. Stop.

I am using Dev-C++ as a compiler. If you need more information just let me know. I am pretty stuck.

The makefile.win from the site after being compiled looks like this.

# Project: Stroustrup
# Makefile created by Dev-C++ 4.9.9.2

CPP  = g++.exe
CC   = gcc.exe
WINDRES = windres.exe
RES  = Stroustrup_private.res
OBJ  = Makefile.o ../Users/Alex/C++/ch12_3.o ../Users/Alex/C++/Graph.o ../Users/Alex/C++/GUI.o ../Users/Alex/C++/Simple_Window.o ../Users/Alex/C++/Window.o $(RES)
LINKOBJ  = Makefile.o ../Users/Alex/C++/ch12_3.o ../Users/Alex/C++/Graph.o ../Users/Alex/C++/GUI.o ../Users/Alex/C++/Simple_Window.o ../Users/Alex/C++/Window.o $(RES)
LIBS =  -L"C:/Dev-Cpp/lib" -mwindows -lfltk -lole32 -luuid -lcomctl32 -lwsock32 -lm  
INCS =  -I"C:/Dev-Cpp/include" 
CXXINCS =  -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include" 
BIN  = Stroustrup.exe
CXXFLAGS = $(CXXINCS)  
CFLAGS = $(INCS) -DWIN32 -mms-bitfields  
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before Stroustrup.exe all-after


clean: clean-custom
    ${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
    $(CPP) $(LINKOBJ) -o "Stroustrup.exe" $(LIBS)

Makefile.o: Makefile.win
    $(CPP) -c Makefile.win -o Makefile.o $(CXXFLAGS)

../Users/Alex/C++/ch12_3.o: ../Users/Alex/C++/ch12_3.cpp
    $(CPP) -c ../Users/Alex/C++/ch12_3.cpp -o ../Users/Alex/C++/ch12_3.o $(CXXFLAGS)

../Users/Alex/C++/Graph.o: ../Users/Alex/C++/Graph.cpp
    $(CPP) -c ../Users/Alex/C++/Graph.cpp -o ../Users/Alex/C++/Graph.o $(CXXFLAGS)

../Users/Alex/C++/GUI.o: ../Users/Alex/C++/GUI.cpp
    $(CPP) -c ../Users/Alex/C++/GUI.cpp -o ../Users/Alex/C++/GUI.o $(CXXFLAGS)

../Users/Alex/C++/Simple_Window.o: ../Users/Alex/C++/Simple_Window.cpp
    $(CPP) -c ../Users/Alex/C++/Simple_Window.cpp -o ../Users/Alex/C++/Simple_Window.o $(CXXFLAGS)

../Users/Alex/C++/Window.o: ../Users/Alex/C++/Window.cpp
    $(CPP) -c ../Users/Alex/C++/Window.cpp -o ../Users/Alex/C++/Window.o $(CXXFLAGS)

Stroustrup_private.res: Stroustrup_private.rc 
    $(WINDRES) -i Stroustrup_private.rc --input-format=rc -o Stroustrup_private.res -O coff
+1  A: 

You shouldn't explicitly define CPP and CC. These are already defined for you by Make. Also, you should use CXX instead of CPP (by default, CXX refers to the c++ compiler, while CPP refers to the C preprocessor). Also, you don't need to give so many targets. There are already automatic build rules that will generate a .o file from the .cpp file with the same basename. Additionally, your rule "Makefile.o: Makefile.win" doesn't make any sense (I doubt you are compiling a makefile). I highly recommend you learn CMake, since it will make your life a whole lot easier. Barring that, you might want to read up more about Make.

EDIT:

I noticed that your paths have forward slashes ("/") instead of backslashes ("\"), which might be a problem on Windows. While ordinarily it is not a problem with Cygwin, it can be a problem if you mix both types of slash.

Michael Aaron Safyan
All I did was download the file from the site. I didn't write any of this except for the first file I posted.
trikker
Perhaps you should get a different instructor / textbook, then. This one seems to be leading you down a dark and scary road. For example, Qt is simpler and more cross-platform than FLTK. And the makefiles you've been given are highly non-portable and fragile.
Michael Aaron Safyan
Well the textbook is the new one from Bjarne Stroustrup. It only covers GUI for a few chapters. I feel like I just organized the files incorrectly or did something wrong along the way. Unfortunately the book and the site provide absolutely no tutorial on getting FLTK to work because "all IDE's are vastly different."
trikker
Stroutstrup did an awesome job inventing C++, but that doesn't mean he is up to date on coding best practices, especially vis-a-vis project organizing and building. You might want to read a textbook by someone who has been using C++ out in the field on a day-to-day basis and has tried a wide variety of libraries and build tools.
Michael Aaron Safyan
Hmm...I might just skip the GUI chapters, but I'm going to try a little bit more to get this to work.
trikker
From what I understand 'no rule to make target 'blabla.cpp''' means that the makefile can't find the blabla.cpp. However the makefile code looks like it's looking in the right place to find c12_3.cpp
trikker
You understand that correctly.
Michael Aaron Safyan
It's a very high quality textbook by the author of C++, so I wouldn't abandon it just yet. Stroustrup is right that it is impractical for him to provide build instructions for every environment. I don't have experience of your exact setup so can't tell you exactly what's wrong. I would advise you to persist though - start with the simplest possible "hello world" scenario and build up from there. I think you'll learn a lot from the exercise.
Bill Forster
He could have used a portable makefile -- you know, one that relies on the predefined pattern rules and predefined commands.
Michael Aaron Safyan
He also could have used BOOST and Qt, two free, very high quality, very well-known, and cross-platform libraries.
Michael Aaron Safyan
Also, it is reasonable to assume that users are on Windows or Mac OS X/Linux/UNIX.
Michael Aaron Safyan
Alright I decided that when I add files and headers to the project I'm going to compile each of them one at a time. The Graph.h has a warning in line 131 and 132 saying warning: converting to int from double. If you want me to post the header I will or you can just look at it on the site.
trikker
Well I've been persisting with this for close to a week now and still nothing so I'm just going to skip the GUI chapters. I can always buy a book on GUI after I'm done with this.
trikker