|
Resources |
Main / CompilingWithFltk - CS559 2007Compiling programs with FlTk and VS2005A tutorial for CS559 students There is another set of tutorials that walk you through setting up a project to use FlTk with Visual Studio for CS559. This one is a little different in that I will try to explain why you are doing each of the required steps, as well as giving you some alternatives. By understanding this, you should be more able to deal with things when they break. Overview: What needs to happenIn order to use an external library (like fltk), a number of things need to happen:
Notice that each of these steps require different things to be done, and will cause different problems if things go wrong. Part 1 - Finding Header FilesIn order for C++ to use some class, function, global variable, macro, or anything else, it must be declared. To get the declarations for a library into your program, you include a header file. So, in your .cpp files (or your own header files) you will have things like #include <Fl/Fl.H>
If you don't, the compiler will give you errors in your program. Be aware that FlTk has many header files, and you will need to include the ones that your program uses. Once you've told the compiler what file it needs, you must also tell it what directory to find the files in. In the CSL environment, the fltk include files are in: S:\fltk\include
However, if you are working on your own computer, you probably have FlTk in a different place. There are two different ways to tell Visual Studio where to find the FlTk include files:
Method #1 has the advantage that you do it once for Visual Studio, and then all your projects know about FlTk. It also has the advantage that you set it for each computer you use, and the projects don't need to be changed if the computers are different. The downside is that all your projects will search FlTk whether you need it or not, and your projects don't specify that they need FlTk includes (they assume you have Visual Studio set up in a particular way). The advantage of Method #2 is that it makes no assumptions about how visual studio is set up, but you do need to set things for each project and be careful to make things work across computers. To make #2 work across computers, rather than putting the hard path into your project, you set the include directory to refer to an environment variable. For example, I set the include search path to include $(FLTKHOME)/include
and I set the environment variable to be Part 2 - Using the right compilation settingsIn order for your program to work correctly with FlTk you need to make sure you use the same compiler settings as was used to build FlTk. Generally, this is easy because the defaults are OK - just be sure to use the right version of the FlTk library. (if you're building your project with debugging, use the debug build of the library) However: there is one setting that is not set correctly by default. The FlTk libraries are built using the "multi-threaded dll" versions of the C runtime. What this means is that the functions in the standard C/C++ library When you program in C or C++, you make use of a basic library for things you might think of as built-in (file I/O, memory allocation, ...). There are several versions of this library. |