13 Replies - 3967 Views - Last Post: 23 June 2011 - 01:35 AM Rate Topic: -----

#1 DJplex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 11

C++ FLTK BJARNE STROUSTRUP BOOK

Posted 21 June 2011 - 04:34 PM

I just started learning programming. I'm reading "Programming Principles and Practice Using C++." I'm at the beginning of the book and it tells me to install FLTK and Visual Studio 2010 Ultimate. I have both programs, I managed to install FLTK by clicking a differently named file in the VS2010 folder of FLTK. After that I see the FLTK GUI and I closed Visual Studio and in the book it tells me to write some code to see if FLTK was installed correctly. I get an error "Can't find filename.exe" after trying to build it. I also got the same error when I tried building "HelloWorld.cpp"

TL;DR

I get a build error when I try debugging my program. I press debug and Visual Studio 2010 asks me "Would you like to build it?" I press "Yes." Then it says "There were build errors, would you like to run the last successful build?" I click "Yes" again. Then it says "Unable to start program C:Users\admin\documents\visual studio 2010\Projects\HelloWorld\Debug\HelloWorld.exe The system cannot find the file specified"

The code is:

#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_window.H>

int main()
{
	Fl_Window window(200, 200,"Window title");
	Fl_Box box(0,0,200,200,"Hey, I mean, Hello, World!");
	window.show();
	return Fl::run();
}


I keep getting that error. Is there a way to fix it? I can't seem to compile anything. My specs are: iMac 27'' Core i7 3.4 gHz 6970M 4GB DDR3 RAM 1TBHDD. Windows 7 Ultimate running in bootcamp using Visual Studio 2010 Ultimate SP1 as my IDE.

Is This A Good Question/Topic? 0
  • +

Replies To: C++ FLTK BJARNE STROUSTRUP BOOK

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1311
  • View blog
  • Posts: 4,503
  • Joined: 19-February 09

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 21 June 2011 - 05:25 PM

Have you moved the libs and includes or told VS where they are?

How do I install FLTK for VS2010?
Was This Post Helpful? 0
  • +
  • -

#3 DJplex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 11

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 21 June 2011 - 06:50 PM

Hey, I'm not too sure. I'm a complete beginner and I've been going by that book. It told me about adjusting some settings. Now that I'm going back to the book, I see Appendix C which could be useful. It gives instructions on installing Visual Studio and there should be some instructions on how to set it up correctly.

My computer knowledge is advanced, but I don't know the settings and what I should be using. I'll read that section and get back to you.

Thanks for your help :)
Was This Post Helpful? 0
  • +
  • -

#4 DJplex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 11

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 10:32 AM

I went through Appendix C and I'm still getting the same error. My Visual Studio 2010 Ultimate is not making executable files for some reason. I might have to switch IDEs and sell or try to get a refund for Visual Studio.
Was This Post Helpful? 0
  • +
  • -

#5 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 207
  • View blog
  • Posts: 550
  • Joined: 12-July 09

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 11:20 AM

If there is an error in your code, you get a build error and the executable isn't created. The message "There were build errors, would you like to run the last successful build?" asks you if you want to run the exexcutable from the previous time you succesfully built the program. Because the program was never succesfully built, there is no executable and you should say "No".

If you want us to help you, you should copy and paste the build error you got. By default Visual Studio prints it somewhere on the bottom of the screen.
Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 11:34 AM

Have you tried to just make a basic Hello World application in VS. I may be you and not the IDE...

So I loaded my VS2010 (which I rarely use) clicked on file->new
chose console program
Put in a directory and project name: (C:\CProjects\Forum Help) / (HWExample)

In the "Win32 Application Wizard" I clicked "Next" to go to the first page and then selected:
Console application
Empty project
(unchecked Precompiled headers as they always cause troubles for me so I have never used that feature)

Clicked "Finish"

Right clicked on the HWExample project and went to Add->New Item.. then C++File (.cpp) and named it "HelloMain.cpp"

Then I used the following code:
#include <iostream>

using namespace std;

class World {
public:
	World() {
		cout << "Hello World" << endl;
	}
	~World() {
		cout << "Goodbye World" << endl;
	}
};

World world;

int main() {
	return 0;
}


hit the little green button at the top next to "Debug" and it asked me if I wanted to build the solution and I said Yes.

There was a flash of a black window and then the output window at the bottom of VS's IDE said:
'HWExample.exe': Loaded 'C:\CProjects\Forum Help\HWExample\Debug\HWExample.exe', Symbols loaded.
'HWExample.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'HWExample.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'HWExample.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'HWExample.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'HWExample.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The program '[7648] HWExample.exe: Native' has exited with code 0 (0x0).


The important part here is: HWExample.exe: ... has exited with code 0

So it built the exe and executed it and it exited with a zero. The reason the window popped away is because VS no longer holds the execution window open when the application exits. So to see the output of the application open a CMD window

What I do is add a little tool to do this for me:

in VS IDE: click on Tools > Settings > "Expert Setting" (this may take a second to reset the IDE's windows)

Then Tools > External Tools
(we are basically going to make a copy of "Visual Studio &Comand Prompt)

click Add
Title: Command Prompt @ Program
Command: %systemroot%\system32\cmd.exe
Arguments: /K vcvars32.bat
Initial Directory: $(BinDir)
check "Close on Exit"
click OK

Now if you go to: Tools > Command Prompt @ Program
a cmd window will open at the binary directory

Type HWExample.exe (or I just do HWE <press tab> and the .exe should come up, if it doesn't keep pressing tab and it should eventually roll around).

The output should be:
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

C:\CProjects\Forum Help\HWExample\Debug>HWExample.exe
Hello World
Goodbye World

C:\CProjects\Forum Help\HWExample\Debug>


you can type exit or press the X to close the window when you are done.
Was This Post Helpful? 0
  • +
  • -

#7 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 12:12 PM

View PostNickDMax, on 22 June 2011 - 11:34 AM, said:

The reason the window popped away is because VS no longer holds the execution window open when the application exits.

Strange, I just tested with the same project creation options as you did, and Ctrl+F5 works just fine, keeping the console window open with "Press any key to continue..." message. That's in VS 2010 of course.
Was This Post Helpful? 0
  • +
  • -

#8 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 12:18 PM

Yeup that works for me too... I always forget that little *trick*.

I have never understood why they don't do that in debug (or at least give the OPTION somewhere).

Well, alas I hardly ever use VS.

@DJplex -- if it makes you feel any better (and it probably doesn't) I am also having troubles getting FLTK working with VS2010. I can compile the demo programs with no problem, but creating a new project seem to be problematic. I was getting X11 errors (you have to add /DWIN32 because they didn't use the standard _WIN32) and now I am getting linker errors...

So... sometimes it takes a little work to get a library properly integrated into your build environment. That's just part of C/C++
Was This Post Helpful? 0
  • +
  • -

#9 DJplex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 11

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 02:15 PM

NickDMax,

The "Precompiled header" checkbox is greyed out unless I choose the "Static library" option. I chose static library and I got the following error when I tried compiling your code:

"The specified file is an unrecognized or unsupported binary format."

I think the easiest thing to do is go to a different IDE thta's beginner friendly. Come back to VS2010 when I think I'm ready. I installed Visual C++ Express and I've been getting the same error as well. I must be doing something wrong, but Bjarne Stroustrup did warn the reader that it's the hardest IDE to use.
Was This Post Helpful? 0
  • +
  • -

#10 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 02:26 PM

It'd be great if you could paste your errors exact, in FLTK program, and simple Hello World one, instead of telling us there were some errors. What compile or link errors do you have? Are you sure you linked to the FLTK .lib file?
Was This Post Helpful? 0
  • +
  • -

#11 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 02:59 PM

First about the precompiled headers. You should be able to leave the on. But to turn them off uncheck them BEFORE you select "Empty Project". (sorry I didn't notice that it mattered).

Next you don't want "static library" you want "console program" -- why would you want to make a library? :)

--VS is a little over-kill for a beginner I admit. It is a very good IDE but it does have many bells and whistles that can get in the way.

Unfortunately you are following a book that is not really "VS friendly" and you are not the only one having troubles (heck I have been working on it for hours and I can't figure out how to build a simple hello world FLTK program). One of the really irritating things is that either no-one has a solution, or its so simple that no one bothers to post what they did to fix the issue in the long run. I find lots of threads on the issue and not a single one (and I have found 25-30 of them) has a solution -- it seems people either get board and give up, or are so excited when they figure it out they never mention what fixed it.

My thoughts on it: Well I can build the file if I make the project part of the fltk-1.3.0\ide\VisualC2010 solution. But when I try to make a new project (in a new solution) I get all kinds of linker errors. I have mirrored the compiler/linker settings from the fltk vc project and still nothing.

The errors that I am getting:
1>HelloMain.obj : warning LNK4217: locally defined symbol ?run@Fl@@SAHXZ (public: static int __cdecl Fl::run(void)) imported in function _main
1>HelloMain.obj : warning LNK4217: locally defined symbol ?end@Fl_Group@@QAEXXZ (public: void __thiscall Fl_Group::end(void)) imported in function _main
1>HelloMain.obj : warning LNK4217: locally defined symbol ?labeltype@Fl_Widget@@QAEXW4Fl_Labeltype@@@Z (public: void __thiscall Fl_Widget::labeltype(enum Fl_Labeltype)) imported in function _main
1>HelloMain.obj : warning LNK4217: locally defined symbol ?labelsize@Fl_Widget@@QAEXH@Z (public: void __thiscall Fl_Widget::labelsize(int)) imported in function _main
1>HelloMain.obj : warning LNK4217: locally defined symbol ?labelfont@Fl_Widget@@QAEXH@Z (public: void __thiscall Fl_Widget::labelfont(int)) imported in function _main
1>HelloMain.obj : warning LNK4217: locally defined symbol ?box@Fl_Widget@@QAEXW4Fl_Boxtype@@@Z (public: void __thiscall Fl_Widget::box(enum Fl_Boxtype)) imported in function _main
1>HelloMain.obj : warning LNK4217: locally defined symbol ??0Fl_Box@@QAE@HHHHPBD@Z (public: __thiscall Fl_Box::Fl_Box(int,int,int,int,char const *)) imported in function _main
1>HelloMain.obj : warning LNK4217: locally defined symbol ??0Fl_Window@@QAE@HHPBD@Z (public: __thiscall Fl_Window::Fl_Window(int,int,char const *)) imported in function _main
1>HelloMain.obj : warning LNK4217: locally defined symbol ??1Fl_Box@@UAE@XZ (public: virtual __thiscall Fl_Box::~Fl_Box(void)) imported in function "public: virtual void * __thiscall Fl_Box::`scalar deleting destructor'(unsigned int)" (??_GFl_Box@@UAEPAXI@Z)
1>HelloMain.obj : warning LNK4217: locally defined symbol ??1Fl_Window@@UAE@XZ (public: virtual __thiscall Fl_Window::~Fl_Window(void)) imported in function "public: virtual void * __thiscall Fl_Window::`scalar deleting destructor'(unsigned int)" (??_GFl_Window@@UAEPAXI@Z)
1>HelloMain.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall Fl_Window::show(int,char * *)" (__imp_?show@Fl_Window@@QAEXHPAPAD@Z) referenced in function _main
1>HelloMain.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) enum Fl_Labeltype __cdecl fl_define_FL_SHADOW_LABEL(void)" (__imp_?fl_define_FL_SHADOW_LABEL@@YA?AW4Fl_Labeltype@@XZ) referenced in function _main
1>C:\CProjects\Forum Help\HWExample\Debug\HWExample.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


indicate a mismatch of /MT /MTd compiler options but alas it really does not make a difference what I try I can't escape these errors (though I can manage a whole lot more if I try).

So... well I will try to see if I can figure it out and put a step-by-step process on my blog. But chances are that I too will give up in a few hours...
Was This Post Helpful? 0
  • +
  • -

#12 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 03:08 PM

...Ok... I got it to work... now to figure out WTF I did!
Was This Post Helpful? 0
  • +
  • -

#13 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 22 June 2011 - 09:32 PM

I realize the that OP has probably moved on to another IDE. Just in case someone else need to know how to set this up I have written a blog entry that shadows a successful compile of a FLTK project.

This is literally step by step what I did as I did it to get a FLTK project compiled.
Was This Post Helpful? 2
  • +
  • -

#14 DJplex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 11

Re: C++ FLTK BJARNE STROUSTRUP BOOK

Posted 23 June 2011 - 01:35 AM

Nick,

I have not given up VS just yet. I'm still reading the books and other online sources so I can fully understand what's going on. I could UL videos to YouTube of the error messages and screen shots too. After that, I'm going to post a solution to fix VS if I manage to resolve this inconvenience. Thanks all of you for the great help and support :)

P.S. I don't want to waste server space on this great website with unnecessary posts. I'm about to go to sleep and I will try out what you've written on your blog tomorrow!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1