README.MSWindows.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. README.MSWindows.txt - 2010-10-25 - Building FLTK under Microsoft Windows
  2. -------------------------------------------------------------------------
  3. CONTENTS
  4. ==========
  5. 1 INTRODUCTION
  6. 2 HOW TO BUILD FLTK USING MinGW/Cygwin
  7. 2.1 The Tools
  8. 2.2 Recommended Command Line Build Environment
  9. 2.3 Prerequisites
  10. 2.4 Downloading and Unpacking
  11. 2.5 Configuring FLTK
  12. 2.6 Building FLTK
  13. 2.7 Testing FLTK
  14. 2.8 Installing FLTK
  15. 2.9 Creating new Projects
  16. 3 HOW TO BUILD FLTK USING VISUAL STUDIO 2008
  17. 3.1 Prerequisites
  18. 3.2 Downloading and Unpacking
  19. 3.3 Configuring FLTK
  20. 3.4 Building FLTK
  21. 3.5 Testing FLTK
  22. 3.6 Installing FLTK
  23. 3.7 Creating new Projects
  24. 4 HOW TO BUILD FLTK USING VISUAL STUDIO 2010
  25. 4.1 Prerequisites
  26. 4.2 Downloading and Unpacking
  27. 4.3 Configuring FLTK
  28. 4.4 Building FLTK
  29. 4.5 Testing FLTK
  30. 4.6 Installing FLTK
  31. 4.7 Creating new Projects
  32. 5 FREQUENTLY ASKED QUESTIONS
  33. 7 LINKS
  34. 6 DOCUMENT HISTORY
  35. INTRODUCTION
  36. ==============
  37. FLTK 1.3 and later is officially supported on Windows (2000,) 2003,
  38. XP, and later. Older Windows versions are not officially supported,
  39. but may still work. The main reason is that the OS version needs
  40. to support UTF-8. FLTK 1.3 is known to work on Windows 7 and Vista.
  41. FLTK currently supports the following development
  42. environments on the Windows platform:
  43. - Free Microsoft Visual C++ 2008 Express and Visual
  44. C++ 2010 Express using the supplied workspace and
  45. project files. Older and the commercial versions can
  46. be used as well, if they can open the project files.
  47. Be sure to get your service packs!
  48. The project files can be found in the ide/ directory.
  49. Please read ide/README.IDE for more info about this.
  50. - GNU toolsets (Cygwin or MinGW) hosted on Windows.
  51. CAUTION: Libraries built by any one of these environments can not be mixed
  52. with object files from any other environment!
  53. HOW TO BUILD FLTK USING MinGW and Cygwin
  54. ==========================================
  55. This chapter of this document gives a brief overview of
  56. compiling and using FLTK with the Cygwin and MinGW compiler
  57. toolkits. Both toolkits provide a build environment based
  58. around the GNU C/C++ compiler. Further information is
  59. available from the FLTK website at http://www.fltk.org, such
  60. as this Howto note: http://www.fltk.org/articles.php?L598
  61. The Cygwin build environment supplies a library (the Cygwin
  62. DLL) that is primarily intended to provide a number of
  63. Unix-like POSIX facilities for programs being ported to the
  64. Windows environment (Win32 or WinNT). Cygwin also supplies
  65. a very Unix-like build environment for Windows, including
  66. the "BASH" Bourne-compatible shell and all of the standard
  67. Unix file utilities (ls, cat, grep, etc.).
  68. Cygwin is developed by Cygnus (now part of RedHat, Inc).
  69. Although provided for free download under the GPL,
  70. distributing programs that require the Cygwin DLL under a
  71. license other than the GPL requires a commercial license for
  72. the Cygwin DLL. Native Windows programs that do not require
  73. the Cygwin DLL (compiled and linked with the "-mno-cygwin"
  74. option) may be released under any license freely.
  75. Note: Since December 2009, there is a new gcc 4.x compiler
  76. that doesn't support the -mno-cygwin option anymore. You
  77. must use the older gcc-3 compiler instead.
  78. An alternative is to install the new (since about Oct. 2010)
  79. mingw cross tools that support newer gcc compilers for building
  80. native Windows applications (like -mno-cygwin above).
  81. Currently you would have to install mingw64-i686-gcc-g++ for
  82. 32-bit Windows applications (despite its name!), and/or
  83. mingw64-x86_64-gcc-g++ for 64-bit applications. You may also
  84. need to install the corresponding '-headers' packages as well.
  85. Currently these tools support gcc 4.5.x or newer, but the
  86. setup for FLTK is somewhat more complicated and not yet
  87. completely supported automatically (you may need to edit
  88. some lines in the generated makeinclude file).
  89. The MinGW distribution (Minimalist GNU for Windows) provides
  90. a similar toolset but geared solely towards native Windows
  91. development without the Unix-like POSIX library. The lack of
  92. any libraries under the GPL or any other restrictive license
  93. means that programs built with the MinGW environment may
  94. always be released under any license freely. MinGW also
  95. supplies a Unix-like build environment for Windows,
  96. including MSYS (a Bourne-compatible shell) and the standard
  97. Unix file utilities (ls, cat, grep, etc.)
  98. If you are not familiar with these GNU-like toolkits please
  99. refer to the links section later in this note. In particular,
  100. check out their license conditions carefully before use.
  101. The Tools
  102. -----------
  103. There are currently three main configurations supported by
  104. FLTK with the GNU tools:
  105. 1. Cygwin: Built using the Cygwin toolset and using the
  106. Unix-like POSIX compatibility layer provided by the
  107. Cygwin DLL.
  108. 2. Cygwin using the "-mno-cygwin" option: Built using
  109. the Cygwin toolset but not using the Cygwin DLL.
  110. 3. MinGW: Built using the MinGW utilities, compiler and
  111. tools. This is, in many aspects, analogous to the
  112. Cygwin "-mno-cygwin" option. This is the recommended
  113. one if you want to build native Windows programs only.
  114. Recommended Command Line Build Environment
  115. --------------------------------------------
  116. Our recommendation is to:
  117. 1. Get the current Cygwin toolset.
  118. This can either produce executables that do or do not
  119. rely on the Cygwin DLL (check licensing) at your
  120. choice.
  121. 2. Get the latest MinGW toolset. It is recommended that
  122. you also get the MSYS shell and the msysDTK developer
  123. toolset.
  124. This will only produce normal Windows native
  125. executables without any Unix or POSIX compatibility
  126. layer.
  127. See the links section below for more information.
  128. Either option can generate windows-native executables and
  129. option 1 can provide a Unix-like POSIX portability layer that
  130. is reliant on a GPLed library.
  131. See the later sections for detailed information about using
  132. one of these configurations.
  133. Prerequisites
  134. ---------------
  135. In order to build FLTK from the command line, you need to install the MinGW
  136. environment from www.mingw.org. The graphical installer "mingw-get-inst" can
  137. be downloaded here for free:
  138. http://www.mingw.org/wiki/Getting_Started
  139. Launch the installer and follow the instructions. In the "Select Components"
  140. dialog, add "C++ Compiler", "MSYS Basic System", and "MinGW Developer Toolkit".
  141. Wait for the installer to finish.
  142. After downloading and installing, you need to launch the MinGW Shell through
  143. the Start menu.
  144. Downloading and Unpacking
  145. ---------------------------
  146. Download FLTK from here:
  147. http://www.fltk.org/software.php
  148. into your home folder. The default location as seen from MSWindows is similar
  149. to
  150. C:\MinGW\msys\1.0\home\matt\
  151. If you are familiar with "subversion" and like to stay current with your
  152. version, you will find the subversion access parameters at the bottom of
  153. that page. Unpack FLTK into a convenient location. I like to have everything
  154. in my dev directory:
  155. cd
  156. mkdir dev
  157. cd dev
  158. tar xvfz fltk-1.3.xxxx.tar.gz
  159. cd fltk-1.3.xxxx
  160. Configuring FLTK
  161. ------------------
  162. If you got FLTK via subversion then you need one extra step. Otherwise skip
  163. over this part. Stay in your FLTK source-code directory and type the
  164. following:
  165. NOCONFIGURE=1 ./autogen.sh
  166. Now configure your FLTK installation:
  167. ./configure
  168. ADVANCED: type "./configure --help" to get a complete list of optional
  169. configuration parameters. These should be pretty self-explanatory. Some
  170. more details can be found in README.
  171. :END_ADVANCED
  172. The configuration script will check your machine for the required resources
  173. which should all have been part of your MinGW installation. Review the
  174. Configuration Summary, maybe take some notes.
  175. ADVANCED: some versions of MinGW/Msys are broken and complain about a missing
  176. --enable-auto-import. The solution is to upgrade to the current release. If
  177. that is not possible, you can include the --enable-auto-import flag when
  178. linking:
  179. ./configure <config flags> LDFLAGS=-Wl,--enable-auto-import
  180. :END_ADVANCED
  181. Building FLTK
  182. ---------------
  183. Now this is easy. Stay in your FLTK source-code directory and type:
  184. make
  185. The entire FLTK toolkit including many test programs will be built for you.
  186. No warnings should appear.
  187. (actually, as of Oct 25 2010, quite a lot of warnings related to suggested
  188. parentheses and others will appear, this is normal and will be fixed. The
  189. linker will also spit out a bunch of warnings for every program linked. This
  190. needs to be fixed. Lastly, there is no generator for man pages in a default
  191. MinGW installation, but you can install man and groff to fix this.)
  192. Testing FLTK
  193. --------------
  194. After a successful build, you can test FLTK's capabilities:
  195. test/demo
  196. Installing FLTK
  197. -----------------
  198. If you did not change any of the configuration settings, FLTK will be
  199. installed in "/usr/local/include" and "/usr/local/lib" by typing
  200. make install
  201. It is possible to install FLTK in user space by changing the installation path
  202. to a location within the user account by adding the "--prefix=PREFIX" parameter
  203. to the "./configure" command.
  204. Creating new Projects
  205. -----------------------
  206. FLTK provides a neat script named "fltk-config" that can provide all the flags
  207. needed to build FLTK applications using the same flags that were used to build
  208. the library itself. Running "fltk-config" without arguments will print a list
  209. of options. The easiest call to compile an FLTK application from a single
  210. source file is:
  211. fltk-config --compile myProgram.cxx
  212. "fltk-config" and "fluid" will be installed in "/usr/local/bin/" by default.
  213. I recommend that you add it to the command search path.
  214. HOW TO BUILD FLTK USING VISUAL STUDIO 2008
  215. ============================================
  216. Prerequisites
  217. ---------------
  218. In order to build FLTK from within VisualStudio 2008, you need to install the
  219. VisualC developer environment from the Microsoft web site. The Express edition
  220. is free of charge and sufficient to develop FLTK applications:
  221. http://www.microsoft.com/express/Downloads/
  222. You must make sure that at least VisualStudio 2008 Service Pack 1 is installed
  223. or building FLTK on a multicore CPU will be very painful!
  224. Downloading and Unpacking
  225. ---------------------------
  226. Download FLTK from here:
  227. http://www.fltk.org/software.php
  228. If you are familiar with "subversion" and like to stay current with your
  229. version, you will find the subversion access parameters at the bottom of
  230. that page.
  231. Unpack FLTK by using an appropriate unpacker and copy the new folder into a
  232. convenient location. I have set up a "dev" folder in my home folder for all
  233. my projects.
  234. Configuring FLTK
  235. ------------------
  236. Launch VisualStudio. Open the project file in
  237. ...\fltk-1.3.xxxx\ide\VisualC2008\fltk.sln
  238. Choose "Debug" or "Release" mode from the "Solution Configurations" menu.
  239. Building FLTK
  240. ---------------
  241. Use the context menu of the "demo" project to "Set as StartUp Project". Then
  242. select "Build Solution" from the "Build" menu or press F7 to build all
  243. libraries.
  244. VisualC 2008 has a bug that messes up building a Solution on multicore CPUs.
  245. Make sure that Visual Studio 2008 Service Pack 1 is installed or, as a
  246. workaround, set the "maximum number of parallel project builds" to 1 (Tools >
  247. Options > Projects and Solutions > Build and Run > maximum number of parallel
  248. project builds). Also, repeating the build command two or three times may
  249. clear unresolved reference errors.
  250. Testing FLTK
  251. --------------
  252. Select "Start Debugging" from the "Debug" menu or just press F5 to run the
  253. Demo program. Use "Demo" to explore all test programs.
  254. Installing FLTK
  255. -----------------
  256. The default location for VisualC 2008 libraries and headers is here:
  257. C:\Program Files\Microsoft Visual Studio 9.0\VC\
  258. It is possible to move the FLTK libraries, headers, and Fluid into the
  259. respective subdirectories, so that they are available for future development
  260. without adding link and include paths to the solution.
  261. copy the entire FL directory into the include path
  262. copy all .lib files from the fltk lib directory to the VC lib directory
  263. copy fluid.exe in the fluid directory to the bin directory
  264. I highly discourage using dll's (dynamically linking libraries) on MSWindows
  265. because they will require an installation process and likely cause version
  266. conflicts. Use the static .lib libraries instead.
  267. Creating new Projects
  268. -----------------------
  269. This chapter assumes that libraries and headers are copied into
  270. C:\Program Files\Microsoft Visual Studio 9.0\VC\
  271. Create a new project of type "General", "Empty Project" and add a simple "C++"
  272. file to it. The FLTK "hello" source code is a good base.
  273. Now open the Project Properties dialog and add "Comctl32.lib" and all the FLTK
  274. libraries that you want to use (at least "fltk.lib") to Additional Dependencies
  275. (Configuration Properties > Linker > Additional Dependencies). In the same
  276. dialog, add "WIN32" to the C++ Preprocessor Definitions (Configuration
  277. Properties > C/C++ > Preprocessor > Preprocessor Definitions).
  278. Compile and run your test program with F5.
  279. You can also include .fl resources: add a new Header file to your project, but
  280. let the name end in .fl. Right-click and select "Open with...". Add "fluid.exe"
  281. from the "bin" directory and set it as the default editor.
  282. To automatically compile .fl files, open the Properties editor and set the
  283. Custom Build Steps to:
  284. Command Line: fluid.exe -c $(InputPath)
  285. Description: Compiling Fluid .fl file
  286. Outputs: $(InputDir)$(InputName).cxx; $(InputDir)$(InputName).h
  287. Now add the generated .cxx file to your project as well. Whenever the .fl file
  288. is changed, the corresponding .cxx file will be recompiled.
  289. HOW TO BUILD FLTK USING VISUAL STUDIO 2010
  290. ============================================
  291. Prerequisites
  292. ---------------
  293. In order to build FLTK from within VisualStudio 2010, you need to install the
  294. VisualC developer environment from the Microsoft web site. The Express edition
  295. is free of charge and sufficient to develop FLTK applications:
  296. http://www.microsoft.com/express/Downloads/
  297. Downloading and Unpacking
  298. ---------------------------
  299. Download FLTK from here:
  300. http://www.fltk.org/software.php
  301. If you are familiar with "subversion" and like to stay current with your
  302. version, you will find the subversion access parameters at the bottom of
  303. that page.
  304. Unpack FLTK by using an appropriate unpacker and copy the new folder into a
  305. convenient location. I have set up a "dev" folder in my home folder for all
  306. my projects.
  307. Configuring FLTK
  308. ------------------
  309. Launch VisualStudio. Open the project file in
  310. .../fltk-1.3.xxxx/ide/VisualC2010/fltk.sln
  311. Choose "Debug" or "Release" mode from the "Solution Configurations" menu.
  312. Building FLTK
  313. ---------------
  314. Use the context menu of the "demo" project to "Set as StartUp Project". Then
  315. select "Build Solution" from the "Build" menu or press F7 to build all
  316. libraries.
  317. Testing FLTK
  318. --------------
  319. Select "Start Debugging" from the "Debug" menu or just press F5 to run the
  320. Demo program. Use "Demo" to explore all test programs.
  321. Installing FLTK
  322. -----------------
  323. The default location for VisualC 2010 libraries and headers is here:
  324. C:\Program Files\Microsoft Visual Studio 10.0\VC\
  325. It is possible to move the FLTK libraries, headers, and Fluid into the
  326. respective subdirectories, so that they are available for future development
  327. without adding link and include paths to the solution.
  328. copy the entire FL directory into the include path
  329. copy all .lib files from the fltk lib directory to the VC lib directory
  330. copy fluid.exe in the fluid directory to the bin directory
  331. I highly discourage using dll's (dynamically linking libraries) on MSWindows
  332. because they will require an installation process and likely cause version
  333. conflicts. Use the static .lib libraries instead.
  334. Creating new Projects
  335. -----------------------
  336. This chapter assumes that libraries and headers are copied into
  337. C:\Program Files\Microsoft Visual Studio 10.0\VC\
  338. Create a new project of type "General", "Empty Project" and add a simple "C++"
  339. file to it. The FLTK "hello" source code is a good base.
  340. Now open the Project Properties dialog and add "Comctl32.lib" and all the FLTK
  341. libraries that you want to use (at least "fltk.lib") to Additional Dependencies
  342. (Configuration Properties > Linker > Additional Dependencies). In the same
  343. dialog, add "WIN32" to the C++ Preprocessor Definitions (Configuration
  344. Properties > C/C++ > Preprocessor > Preprocessor Definitions).
  345. Compile and run your test program with F5.
  346. You can also include .fl resources: add a new Header file to your project, but
  347. let the name end in .fl. Right-click and select "Open with...". Add "fluid.exe"
  348. from the "bin" directory and set it as the default editor.
  349. To automatically compile .fl files, open the Properties editor and change the
  350. Element Type to Custom Build and click Apply. Now set the
  351. Custom Build Steps to:
  352. Command Line: fluid.exe -c %(FullPath)
  353. Description: Compiling Fluid .fl file
  354. Outputs: $(InputDir)$(InputName).cxx; $(InputDir)$(InputName).h
  355. Now add the generated .cxx file to your project as well. Whenever the .fl file
  356. is changed, the corresponding .cxx file will be recompiled.
  357. FREQUENTLY ASKED QUESTIONS
  358. ============================
  359. Why does a console window appear when I run my program?
  360. ---------------------------------------------------------
  361. Windows has a flag that determines whether an application
  362. runs in the foreground with a console or in the background
  363. without a console.
  364. If you're using gcc (i.e. MinGW or Cygwin), then use the
  365. linker option "-mwindows" to make your application run in
  366. the background and "-mconsole" to run in the foreground. Use
  367. fltk-config --ldflags to see appropriate linker flags, or use
  368. fltk-config --compile to compile a single source file.
  369. If you're using MS VC++, then you must set the linker option
  370. "/subsystem:windows" to create a "Windows" program (w/o console
  371. window), or set the linker option "/subsystem:console" for a
  372. console program, i.e. with a console window. These options
  373. are set differently in the FLTK project files, depending on
  374. whether you select a "Debug" or "Release" build.
  375. Other compilers and build systems may have different options.
  376. Keep in mind that a windows application cannot send output
  377. to stdout, even if you run it from an existing console
  378. application.
  379. (Note: A special case of this exists if running a MinGW
  380. application from the command line of an MSYS shell, when an
  381. application is able to write to stdout, even if compiled with
  382. "-mwindows". The same applies to Cygwin.)
  383. How do I get OpenGL to work?
  384. ------------------------------
  385. Both builds should automatically support OpenGL.
  386. The configuration file config.h has a number of settings
  387. which control compile-time compilation. One such setting is
  388. "HAVE_GL". This may be set to 0 to disable Open GL operation.
  389. Changing the line in config.h to
  390. #define HAVE_GL 1
  391. will change this to compile and link in OpenGL.
  392. LINKS
  393. =======
  394. The following links may be of use:
  395. 1. Main Cygwin homepage:
  396. http://www.cygwin.com/
  397. 2. Main Mingw homepage:
  398. http://www.mingw.org/
  399. In particular look for the MinGW FAQ at this link for
  400. a lot of useful Mingw-native development
  401. documentation.
  402. 3. Check out the FLTK newsgroups at the FLTK homepage:
  403. http://www.fltk.org/
  404. Its archival search facilities are EXTREMELY useful
  405. to check back through previous problems with this
  406. sort of configuration before posting new questions.
  407. 4. GNU Compiler Collection (GCC) compiler homepage:
  408. http://gcc.gnu.org/
  409. 5. OpenGL page - for OpenGL and GLUT libs
  410. http://www.opengl.org/
  411. DOCUMENT HISTORY
  412. ==================
  413. Oct 25 2010 - matt: restructured entire document and verified instructions
  414. Dec 20 2010 - matt: merged with README.win32
  415. Dec 22 2010 - AlbrechtS: added newer Cygwin (cross/mingw-w64) options
  416. Feb 24 2012 - AlbrechtS: clarified console window FAQ