FLTK with Visual Studio 2010 and Stroustrup's headers

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

40 Replies - 13041 Views - Last Post: 01 October 2013 - 09:49 PM Rate Topic: -----

#1 Slazia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 25-July 12

FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 26 July 2012 - 12:12 AM

I'm working through the Programming: Principles and Practice Using C++ and am finding the book a very good starting point. I worked my way up to chapter 12, and have hit a roadblock.

Basically I'm supposed to start using FLTK 1.1.9. This will not compile under VS2010 so I'm using 1.3 instead. This might be the root of my problems, but as yet, nobody has verified this or denied it.

After a lot of trial and error I have managed to compile FLTK 1.3 in both debug and final configurations. I have also managed to successfully run a simple test programme. So far, so good.

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

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



Now the problem is, when I add the header files from his website - http://www.stroustru...mming/Graphics/
it won't compile. Even if I am only using the same test programme above.

The errors I get -

Quote

------ Build started: Project: Fri_FLTK_Test, Configuration: Debug Win32 ------
Graph.cpp
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.h(45): warning C4305: 'initializing' : truncation from 'Graph_lib::Color::Transparency' to 'char'
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.h(45): warning C4309: 'initializing' : truncation of constant value
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.h(47): warning C4305: 'initializing' : truncation from 'Graph_lib::Color::Transparency' to 'char'
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.h(47): warning C4309: 'initializing' : truncation of constant value
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.cpp(64): warning C4018: '<' : signed/unsigned mismatch
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.cpp(130): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.cpp(131): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
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
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.h(286) : see previous definition of '{ctor}'
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.cpp(388): warning C4800: 'void *' : forcing value to bool 'true' or 'false' (performance warning)
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.cpp(413): warning C4018: '>=' : signed/unsigned mismatch
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I see a few options at this point.

1 My most desirable, to fix this problem and put a solution on the web for others.
2 Skip the graphics section of the book completely.
3 Move out of VS2010 and into Msys or something else.

Option 2 would leave me a little disappointed, as I really want to mess around with simple graphics. Option 3 is a possibility, but I really am not looking to learning another development environment. I've dabbled with Msys and am having a ton of problems as there is a lot to learn. I don't think this is the best option for someone starting out.

A solution would be best, but advice would also be much appreciated. Where can I go from here? I can't be the only person with this problem.

If anyone needs helping running FLTK 1.3 with VS2010, I can point you to a guide I wrote on another site. I don't know if linking is encouraged on this forum.

Anyway, thanks for reading. This problem has been causing me a lot of problems, and I'd really like to get it solved. There must be some experienced programmers out there who have a clear answer to this question. I've googled the issue more times than I care to remember.

Is This A Good Question/Topic? 0
  • +

Replies To: FLTK with Visual Studio 2010 and Stroustrup's headers

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,246
  • Joined: 05-May 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 26 July 2012 - 12:31 AM

The compiler is accurately reporting the issue at hand.

Quote

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
c:\users\user\documents\visual studio 2010\projects\fri_fltk_test\graph.h(286) : see previous definition of '{ctor}'


In Graph.h:
	Circle(Point p, int rr)	// center and radius
		:r(rr) { add(Point(p.x-r,p.y-r)); }



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



You'll have to modify your copy of the header or the .cpp file to get past the error.

This post has been edited by Skydiver: 26 July 2012 - 12:33 AM

Was This Post Helpful? 0
  • +
  • -

#3 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1392
  • View blog
  • Posts: 4,394
  • Joined: 20-March 10

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 26 July 2012 - 12:54 AM

Hi,

See this link

My link

Where I help another member called Laserbeak
build FLTK Version 1.1.10.

This should help with your problems.

Best Wishes

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#4 Slazia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 25-July 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 26 July 2012 - 08:08 AM

Excellent! Thank you so much for the replies! I have the whole day off tomorrow, so if this works that means I can make up on some of the time I lost! Thanks again for the replies, I'll give you some feedback on how it works out.
Was This Post Helpful? 0
  • +
  • -

#5 Slazia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 25-July 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 26 July 2012 - 08:52 PM

View PostSkydiver, on 26 July 2012 - 12:31 AM, said:

You'll have to modify your copy of the header or the .cpp file to get past the error.


Thanks Skydiver! But I don't understand what I should modify to fix it. Looking at Snoopy's post now. He's using FLTK 1.1.0, so I need to build that again now. Does that mean FLTK 1.3.0 is incompatible with the headers?

Thanks again for the replies, it's really nice to get a bit of momentum up on this again. Being stuck is no fun.
Was This Post Helpful? 0
  • +
  • -

#6 Slazia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 25-July 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 26 July 2012 - 09:43 PM

Skydiver, I followed the instructions listed but I can't even get FLTK 1.1.10 to run with VS 2010. I installed the Windows 7SDK, but I get a ton of errors when I build it.

Quote

========= Build: 69 succeeded, 0 failed, 0 up-to-date, 1 skipped ==========
72 warnings

Warning 1 warning MSB8012: TargetPath(C:\fltk-1.1.10\vc2005\.\Release\libpng.lib) does not match the Library's OutputFile property value (C:\fltk-1.1.10\lib\fltkpng.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 1151
Warning 2 warning MSB8012: TargetName(libpng) does not match the Library's OutputFile property value (fltkpng). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 1153
Warning 3 warning MSB8012: TargetPath(C:\fltk-1.1.10\vc2005\.\Release\zlib.lib) does not match the Library's OutputFile property value (C:\fltk-1.1.10\lib\fltkz.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 1151
Warning 4 warning MSB8012: TargetName(zlib) does not match the Library's OutputFile property value (fltkz). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 1153
Warning 5 warning MSB8012: TargetPath(C:\fltk-1.1.10\vc2005\.\Release\jpeg.lib) does not match the Library's OutputFile property value (C:\fltk-1.1.10\lib\fltkjpeg.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 1151
Warning 6 warning MSB8012: TargetName(jpeg) does not match the Library's OutputFile property value (fltkjpeg). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 1153
Warning 7 warning MSB8012: TargetPath(C:\fltk-1.1.10\vc2005\.\Release\fltkimages.lib) does not match the Library's OutputFile property value (C:\fltk-1.1.10\lib\fltkimages.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 1151
Warning 8 warning MSB8012: TargetPath(C:\fltk-1.1.10\vc2005\.\Release\fltk.lib) does not match the Library's OutputFile property value (C:\fltk-1.1.10\lib\fltk.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 1151
Warning 9 warning MSB8012: TargetPath(C:\fltk-1.1.10\vc2005\.\Release\pixmap_browser.exe) does not match the Linker's OutputFile property value (C:\fltk-1.1.10\test\pixmap_browser.exe). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile). C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets 990


I think I will have to fix this before I can continue with the instructions.

Will reinstall visual studio and see if that does anything...

The Windows 7 SDK only seems to work with Visual Studio 2005 or 2008, so I think we can ignore that step.

Can I confirm this was done on Microsoft Visual C++ 2010 Express? I think this might all be down to version incompatibility.
Was This Post Helpful? 0
  • +
  • -

#7 Slazia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 25-July 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 26 July 2012 - 09:53 PM

Installed Visual C++ 2008, FLTK 1.1.10 builds correctly. So my original problem still stands, is it a 2010 issue? I guess the simple solution is for everyone to use 2008, but why?
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,246
  • Joined: 05-May 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 26 July 2012 - 11:16 PM

View PostSlazia, on 26 July 2012 - 08:52 PM, said:

View PostSkydiver, on 26 July 2012 - 12:31 AM, said:

You'll have to modify your copy of the header or the .cpp file to get past the error.


Thanks Skydiver! But I don't understand what I should modify to fix it.


The modification would have been either to remove the body of the constructor out of the header file, or remove the body of the constructor out of the source file.
Was This Post Helpful? 1
  • +
  • -

#9 Slazia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 25-July 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 27 July 2012 - 12:50 AM

Thanks Sky. That seemed to be the missing piece of the puzzle! Do you happen to know why that was there in the first place if it is going to cause errors?

I'm a little worried removing that section from graph.cpp may cause problems down the road, but I guess I'll deal with that when I get to it.

For now, I can happily report to have the first test programme from the book running using his header files in Visual Express 2008. I haven't got the 2010 version running yet, but I think it should be easy enough!
Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,246
  • Joined: 05-May 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 27 July 2012 - 01:18 AM

I got FLTK 1.3.0 downloaded, built, and running without any hitches in VS2010. I just followed the directions in README.MSWindows.txt starting at line 417 onwards.

The only "issue" I ran into is the README said use press F7 to build, but I picked a different key mapping when I was installing and running VS2010 for the first time. Just use Build.Build Solution from the UI instead.

Next, I'll try the code you referenced in your original post.
Was This Post Helpful? 0
  • +
  • -

#11 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,246
  • Joined: 05-May 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 27 July 2012 - 02:01 AM

Okay, I downloaded the files into a new directory. Since I don't own the book, I was just guessing, so I did the following:

(Ignored the makefile that builds library for Unix.)
Created a Win32 Console project.
Created a main.cpp.
Pasted in your simple program into it.
Built and ran without any problems.
Added the .cpp files from the download as source files, and the .h files as headers for the project.
Tried to build and fixed the following issues:
- Removed the body the Circle constructor from Graph.h.
- Fixed header paths std_lib_facilities.h. Apparently that file is supposed to live one directory above. Since I don't own the book I didn't know and downloaded everything into the same directory. Since I didn't want to pollute the directory above where I have this project, I just changed all instances where it said "../std_lib_facilities.h" to just "std_lib_facilities.h".
- Added the following libs to get a successful link:
fltk.lib
fltkimages.lib
fltkjpeg.lib
- Ignored the VS2010 Intellisense error "linkage specification is incompatible with previous "_hypot"" since I don't use Intellisense anyway is C++ because it is so "broken" in VS2010. I just checked the checkbox to not show Intellisense errors. But this maybe related even though we are not using CUDA: http://stackoverflow...ible-with-previ

Anyway, I got a successful build, but I don't know how the main.cpp in the OP needs to get changed to actually call the code that was in the downloaded headers and source files. As I said, I don't have the book.
Was This Post Helpful? 1
  • +
  • -

#12 Slazia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 25-July 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 27 July 2012 - 02:38 AM

Yup! All appears to be working. Thanks a lot for all your help. It took me 3 weeks to fix this problem. I've written up a full solution on the StackOverflow site for anyone who is in the same boat. So happy I can finally continue with his book.

Thanks again Skydiver, your help really made the world of difference.
Was This Post Helpful? 1
  • +
  • -

#13 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,246
  • Joined: 05-May 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 27 July 2012 - 02:50 AM

In step 6 in the full solution, you should put in the compiler error about the constructor, not the warning about the truncation.
Was This Post Helpful? 0
  • +
  • -

#14 Slazia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 25-July 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 27 July 2012 - 05:50 AM

Ahh, thank you. Is it this one -

Quote

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

Was This Post Helpful? 0
  • +
  • -

#15 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,246
  • Joined: 05-May 12

Re: FLTK with Visual Studio 2010 and Stroustrup's headers

Posted 27 July 2012 - 10:39 AM

Yup.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3