質問

I'm attempting to follow Programming - Principles and Practice Using C, and am loving it so far. At the start of last week, I hit a problem that has stopped further progress. I'm required to install FLTK.

After successfully managing to build and run FLTK-1.3.0 (see my other question/solution), I've run into the problem that it doesn’t run with Stroustrup's header files. I think this is due to the versions being different, but don't know for sure.

So I'm back to trying to get 1.1 working.

I've not managed to be able to build FLTK-1.1.10 or the fltk-1.1.9 from his website using MVC++2010.

So this leads us to the questions

1) If I build it using MinGW/Msys, will it still be able to be run from VC++? I've been trying to figure out MinGW/Msys with little success so far, so I've yet to build anything, so I can't test this myself yet.

2) If it won't run a MinGW build, is there a way to build it with VC++?

From my understanding -Building will create more files in the FLTK directory that will allow me to use it. -MinGW uses a different compiler to VC++ and they won't play well together

I feel I've wasted a lot of time on this section, however it's a good learning experience. Probably not so good for my blood pressure.

I guess at this point my main alternative is to move to another IDE. Eclipse seems pretty nice. But I'd really like to solve this problem rather than move away from VC++.

My previous post ( Microsoft 2010 visual c , installing FLTK ) details the errors that occur during compile, in case that is of any interest.

I've heavily googled this issue, and have yet to find a real solution. I hope this post will clarify the issue for myself and other future programmers.

役に立ちましたか?

解決

Well, it's taken me long enough, but I've finally got it all figured out. This appears to be the lay of the land.

  1. FLTK 1.3.0 is compatible with the header files, but graph.cpp needs a small change to allow things to run.
  2. FLTK 1.1.10 won't build properly with Visual Express 2010, but will work with the 2008 version.
  3. The header files work with both, but you need to make a small change to Graph.cpp for them to work.

After all the frustration I had getting these all working, I think it's only fair to write up a step by step guide for people who may be in similar situations. The book is aimed at novice programmers, not people already able to debug his header and cpp files. I apologize is the solution is a little lengthy, but I think it's only appropriate for people like myself who are likely to be facing it.

Visual Express 2008 / 2010 guide

1) Build FLTK. Not as easy as it sounds, but not too bad. In 2008 use FLTK 1.1.0. In 2010 use 1.3.0.

  1. For 2010 see the solution I wrote here – Microsoft 2010 visual c , installing FLTK

  2. For 2008 run C:\fltk-1.1.10\vc2005\fltk.lib.vcproj instead.

    If there are any errors during the build process, you will need to figure out what the problem is.

2) Set up a new project

  1. For 2010 just follow the guide above
  2. For 2008 – basically the same idea but with a few changes
    1. Make sure to change all references of 1.3.0 to 1.1.10
    2. In the input section, instead of separating the .lib files with a semi-colon ; use a space instead, so the linker>Input>Additional dependencies will look like this c:\fltk-1.1.10\lib\fltk.lib wsock32.lib comctl32.lib c:\fltk-1.1.10\lib\fltkjpeg.lib c:\fltk-1.1.10\lib\fltkimages.lib

3) Run a test programme to make sure your FLTK is working properly, try -

#include <FL/Fl.h>
#include <FL/Fl_Window.h>

int main()
{
Fl_Window win(320,200);
win.show();
return Fl::run();
}

If there are any errors here, then you won't be able to proceed.

4) Put the files from his website into the right folders.

  1. For 2008 in a project named headertest -
    1. C:\Users\User\Documents\Visual Studio 2008\Projects\headertest\ put std_lib_facilities.h here
    2. C:\Users\User\Documents\Visual Studio 2008\Projects\headertest\headertest\ Put all the other .cpp and .h files from his website here, and of course your headertest.cpp and .h (if required) will be created here.
    3. Make sure you have set up the project correctly as in the steps from my guide above.
  2. For 2010 in a project named Fri_FLTK_Test -
    1. Do the same as above, but put the files in the 2010 equivalent - C:\Users\User\Documents\Visual Studio 2008\Projects\headertest and ..Visual Studio 2010\Projects\Fri_FLTK_Test\Fri_FLTK_Test

5) Add the .h and .cpp files to your active project.

  1. Simply right click the project add>Existing Items – select all the .h and.cpp files in the default directory. You won't need to add ..\std_lib_facilities.h as you are already directly referencing this. Don't ask me why, but this works.

6) Now you will find that if you run the project, you'll get a bunch of errors, the most important reads -

c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.cpp(237): error C2084: function 'Graph_lib::Circle::Circle(Point,int)' already has a body

7) We can fix this by opening Graph.cpp and commenting out the Circle::Circle section, like -

//Circle::Circle(Point p, int rr)    // center and radius
//:r(rr)
//{
//    add(Point(p.x-r,p.y-r));       // store top-left corner
//}

8) Save changes and run your project again, you should find that it works! 9) Now the best part, put in the code from the book (or copy it from – Chapter13/chapter.13.2.cpp and run it! It should work.

Mission complete!

Think I deserve a beer after that! Took me a ton of time to figure it all out, took a look at Msys, g++ , Netbeans and a load of other IDE related things. But it's a nice feeling to have it working on my original choice. I hope this guide helps others in similar situations.

Special thanks go out to Skydiver from the Dream.In.Code forums for his help with this problem.

他のヒント

Could it be because you are running the Express edition? I've encountered similar problems like that and had to switch to an older version of Express.

Have you seen this post?

http://answerpot.com/showthread.php?275672-FLTK+%26+Visual+C%2B%2B+Express%3F

-Si.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top