2

My machine in Windows 7 32-bit and my compiler for C++ is Visual Studio 2012 so first I downloaded FLTK from here (http://www.stroustrup.com/Programming/FLTK/) and then I did the works as follows has wanted me:

I. Unzip the downloaded file and open the main folder, fltk-l.l.? In a Visual C++ folder (e.g., vc2005 or vcnet), open fltk.dsw. If asked about updating old project files, choose Yes to All.

PS: My compiler is vc2012 instead of vc2005 and there wasn't any file named fltk.dsw in vc2005 or vcnet folders, so I chose the fltk.sln from vcnet and installed it. There were some failing when installing but it finished finally!

  1. From the Build menu, choose Build Solution. This may take a few minutes. The source code is being compiled into static link libraries so that you do not have to recompile the FLTK source code any time you make a new project. When the process has finished , close Visual Studio.

  2. From the main FLTK directory open the lib folder. Copy (not just move/drag) all the .lib files except README.lib (there should be scven) into C:\Prograrn Files\Microsoft Visual Studio\Vc\lib.

  3. Go back to the FLTK main directory and copy the FL folder into C:\Program Files\Microsoft Visual Studio\Vc\include.

  4. Create a new project in Visual Studio with one change to the usual procedure: create a "\Vin32 project" instead of a "console application" when choosing your project type. Be sure to create an "empty project"; otherwise, some "software wizard" will add a lot of stuff to your project that you are unlikely to need or understand.

  5. In Visual Studio, choose Project from the main (top) menu, and from the drop-down menu choose Properties.

  6. In the Properties dialog box, in the left menu, click the Linker folder. This expands a sub-menu. In this sub-menu, click Input. In the Additional Dependencies text field on the right, enter the following text: fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib fltkimagesd.lib [The following step may be lIImecessary because il is now the default.] In the Ignore Specific Library text field, enter the following text: libcd.lib

  7. [This step may be unnecessary because /MDd is now the default.] In the left menu of the same Properties window, dick C/C++ to expand a different sub-menu. Click the Code Generation sub-menu item. In the right menu, change the Runtime Library drop-down to Multi-threaded Debug DLL (/MDd). Click OK to close the Properties window.

I this step I added a new item to that newly created project (I named that project testv.cpp) and pasted this simple code for testing the FLTK:

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

//***************************

int main() 
{
  FI_Window window(200, 200, "Window title");
  FL_Box box(O,O,200,200, "Hey, I mean, He llo, World! ");
  window.show();
  return Fl::run();
}

After running this project (pressing F5), 11 errors appeared! They are in bellow:

Error 1 error LNK2019: unresolved external symbol "public: static int __cdecl Fl::run(void)" (?run@Fl@@SAHXZ) referenced in function _main C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 2 error LNK2019: unresolved external symbol "protected: __thiscall Fl_Widget::Fl_Widget(int,int,int,int,char const *)" (??0Fl_Widget@@IAE@HHHHPBD@Z) referenced in function "public: __thiscall Fl_Box::Fl_Box(int,int,int,int,char const *)" (??0Fl_Box@@QAE@HHHHPBD@Z) C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 3 error LNK2019: unresolved external symbol "public: virtual __thiscall Fl_Widget::~Fl_Widget(void)" (??1Fl_Widget@@UAE@XZ) referenced in function "public: virtual __thiscall Fl_Box::~Fl_Box(void)" (??1Fl_Box@@UAE@XZ) C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 4 error LNK2001: unresolved external symbol "public: virtual void __thiscall Fl_Widget::resize(int,int,int,int)" (?resize@Fl_Widget@@UAEXHHHH@Z) C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 5 error LNK2001: unresolved external symbol "protected: virtual void __thiscall Fl_Box::draw(void)" (?draw@Fl_Box@@MAEXXZ) C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 6 error LNK2001: unresolved external symbol "public: virtual int __thiscall Fl_Box::handle(int)" (?handle@Fl_Box@@UAEHH@Z) C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 7 error LNK2019: unresolved external symbol "public: __thiscall Fl_Window::Fl_Window(int,int,char const *)" (??0Fl_Window@@QAE@HHPBD@Z) referenced in function _main C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 8 error LNK2019: unresolved external symbol "public: virtual __thiscall Fl_Window::~Fl_Window(void)" (??1Fl_Window@@UAE@XZ) referenced in function _main C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 9 error LNK2019: unresolved external symbol "public: virtual void __thiscall Fl_Window::show(void)" (?show@Fl_Window@@UAEXXZ) referenced in function _main C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj

Error 10 error LNK2019: unresolved external symbol WinMain@16 referenced in function __tmainCRTStartup C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\MSVCRTD.lib(crtexew.obj)

Error 11 error LNK1120: 10 unresolved externals C:\Users\CS\documents\visual studio 2012\Projects\testv\Debug\testv.exe

I think the problem is to do with the creating the project. After I created an empty project from Win32 Project I clicked on Add new item and chose the .cpp type. I don't know was it correct or not.

Any idea for fixing the problem?

abbasi
  • 121
  • 1
  • 10
  • When you added your libraries, did you type them in on one line or did you click on the ellipsis and type them in on separate lines? Use fltkd.lib (not fltkd.1ib) and ws2_32.lib (not ws0ck32.lib, which really should have been wsock32.lib). – cup Jan 06 '14 at 10:02
  • Also, when you built fltk, was it MT or MD? You need to follow the same model in your executable. If you have to use a particular compilation model, then change your fltk projects to match and rebuild. It is quite tedious and there is no simple way around it. – cup Jan 06 '14 at 10:04
  • I corrected those typing errors and ran the code again. The only error was this: Error 1 error LNK1104: cannot open file 'fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib fltkimagesd.lib' c:\Users\CS\documents\visual studio 2012\Projects\testv\testv\LINK – abbasi Jan 06 '14 at 12:14
  • I don't what do you mean by " when you built fltk, was it MT or MD?", sorry. I didn't build the fltk, I downloaded it from mentioned site. – abbasi Jan 06 '14 at 12:18
  • So what did you do after changing fltk.dsw to fltk.sln? Did you build it or just convert it without building. Anyway check the fltk project whether it was built as MT or MD. – cup Jan 06 '14 at 12:39
  • I didn't change it because I didn't find the fltk.dsw. Instead I installed the fltk.sln. – abbasi Jan 06 '14 at 13:11

2 Answers2

1

You are getting that error because you are entering all the library names on one line without a separator. It is taking the whole list as one library. Click on the ellipsis then enter each library name separated by a newline.

Instead of wsock32.lib, use ws2_32.lib

cup
  • 7,589
  • 4
  • 19
  • 42
  • What step are you talking about, the step no 6? If so, first I added the libraries like this fltkd.lib, wsock32.lib, comctl32.lib, fltkjpegd.lib, fltkimagesd.lib without new lines in () and ran the code again but got this error: Error LNK1104: cannot open file 'fltkd.lib, wsock32.lib, comctl32.lib, fltkjpegd.lib, fltkimagesd.lib'. Then I changed each one to be in one line with the (,) separator and ran the code. This time I got this error: Error LNK1104: cannot open file 'fltkd.lib,'. I appreciate your responses. Please help me until end so that I can solve this problem. Thanks. – abbasi Jan 07 '14 at 07:30
  • HEY WOW, I changed each one in one line without separator and it WORKED. THANK YOU VERY VERY MUCH. THANKS MATE. – abbasi Jan 07 '14 at 07:33
  • After the above code I tested this one: #include "Simple_window.h" #include "Graph.h" int main() { using namespace Graph_lib; Point tl(100,100); Simple_window win(tl,600,400,"Canvas"); Polygon poly; poly.add(Point(300,200)); poly.add(Point(350,100)); poly.add(Point(400,200)); poly.set_color(Color::red); win.attach (poly); win.wait_for_button();} And then ran the code. I got 11 errors first is: Error C1083: Cannot open include file: 'Simple_window.h': No such file or directory. – abbasi Jan 07 '14 at 07:39
  • You've probably got this from the Stourstrop book. Those aren't fltk headers - all FLTK headers begin with FL/. Have a look at the book, maybe it will tell you where to get the headers/sources/libraries for those files. – cup Jan 07 '14 at 09:04
  • OK, so the recent errors weren't my fault or the project settings and I should find those headers somewhere in the book, yes? PS: I searched, fltk-1.3.2-source, fltk-1.1.9-source, fltk-1.1.10-source and fltk-1.3.0-source and my own include directory (C:\...)for those two headers (Simple_window.h & Graph.h) and couldn't find them. A big thanks for your helps until now. – abbasi Jan 07 '14 at 12:23
  • I could to find the header files and add them into my include directory. Now the problem of this thread has been solved for me. Thanks. I have another one problem with the next simple code of this book That I state it in another thread. – abbasi Jan 07 '14 at 13:45
  • There are quite a few postings on graph.h. Have a look at what the others did. – cup Jan 07 '14 at 16:07
  • That issue is not about the headers. The case is that my compiler doesn't know the _Polygon_. I stated that issue here(http://stackoverflow.com/questions/20973419/trouble-with-polygon-in-stroustrups-ppp-book) – abbasi Jan 07 '14 at 16:56
0

You are getting that error because you are entering all the library names on one line without a separator. It is taking the whole list as one library. Click on the ellipsis then enter each library name separated by a newline.

Instead of wsock32.lib, use ws2_32.lib

Just to add. To Separate each library, put a semicolon after each library name (ex. libraryname.lib; libraryname.lib) or just press enter on the text box to go to the next line so Visual Studio will read it as next line and anything you enter to it will consider it as a library name.

Example:

libraryname.lib - Now, press enter so it will go to the next line, VS will recognize at a library name. libraryname.lib - This is the next line and your new library

I am studying C++ and using Microsoft Visual Studio 2015 ^_^