Common project structure
IMPORTANT: It is assumed that you have installed the dependencies specific to your system as explained in the Dependencies of CGFLib page and downloaded the source package available at the Downloads page.
The library and example project provided in the Downloads page comprise a series of folders for organizing code, compilation output and runtime assets such as shaders and textures:
- src - source files for your project; you should include your header files here, to ease project submission.
- include - folder for (mainly external) header files. Includes a CGF folder in which CGFlib headers must be present.
- lib - library files to be used; CGFlib.lib must be here
- bin - folder where the executable will be placed
- obj - folder where compilation object files will be placed
- data - folder reserved for placing runtime assets such as textures, shaders or other data files (when providing a file name in code, it should be relative to the working directory when executing (e.g. if working dir is 'bin', path for data files should be e.g. '../data/myimage.jpg').
Additionally, project files for Visual Studio and Eclipse are provided, as well as makefiles for GNU Make.
The following sections provide details to take into account when setting up a project in each of these environments.
Visual Studio
The source package includes a Visual Studio 2010 solution containing two projects, one for building the library, and another for building the example. Rebuilding the whole solution will:
- compile the library
- copy the CGFlib.lib and the library headers respectively to the 'lib' and 'include/CGF' folders of the example
- compile and link the example
Check the following subsections for VS version-specific notes.
Visual Studio 2010
There is a pre-compiled package for those using VS 2010. It contains only the example project, and the CGFlib.lib and header files are already placed in the corresponding folders of that project. It assumes that dependencies have been taken care of.
Visual Studio 2012
For VS 2012 there is currently no pre-compiled package. You have to install the appropriate dependencies, and use the source package solution and projects in VS 2012. Some pitfalls you should be aware about (courtesy of Daniel Nora):
- Open the project's solution, located at the root of the extracted folder. When Visual Studio 2012 asks, choose to update in order to use Visual C++ 2012's compiler and libraries.
- Try to build the Project. If you manage to do it successfully, the work is done.
- If you get multiple errors similar to "fatal error C1083: Cannot open include file: '... .h'" , you need to configure VC++ so that it searches the correct directories for those include files (do it for both projects):
- If you find the message "... one or more multiply defined symbols found" during the linkage, return to Properties, go to Linker>Input and add LIBCMT.lib to Ignore Specific Default Libraries.
- Don't forget to repeat the instructions for both projects.
Eclipse
For both Windows and Linux, it is necessary to have the Eclipse CDT plugin installed - http://www.eclipse.org/cdt/.
You should import both projects (CGFlib and CGFExample) into the workspace, build the library, copy it to the example project, and then build the example, as described below:
- Right-Click in the Project Explorer and select 'Import' -> 'General' -> 'Existing Projects into Workspace'
- Browse and select the folder "CGFexample", followed by 'Finish'
- IMPORTANT: Right-click on the project and select "Build Configurations"->"Set Active" and select "DebugLinux" or "DebugWin" depending on your OS.
- Repeat the previous steps for the project "CGFlib"
- Right-click on the "CGFlib" project and select "Build Project". This will build the library. (Note: in some Eclipse Juno setups, an error is reported at the end of build, but the build succeeds anyway. Press 'Ok')
- Copy the 'libCGF.a' file in CGFlib/lib to CGFexample/lib (this step should be automated in the future)
- FOR WINDOWS: Right click the project and go to "Properties => C/C++ Build => Settings => Tool Settings => GCC C++ Linker => Libraries" and make sure that the libraries are in the following order:
- CGF
- glew32
- glui32
- freeglut
- glu32
- opengl32
- Right-click on the "CGFexample" project and select "Build Project". This will build the example.
- Click Run (Note: in the Juno setup with the error described above, a warning may come up here, click 'Yes')
After initial setup, new builds of the example only require the last steps: build and Run, or just run if the automatic building before running is enabled
Notes
If you have customised paths for your compilation tools, update the project properties according to those paths:
- includes:
- Project properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Includes
- libs:
- Windows: Project properties -> C/C++ Build -> Settings -> MinGW C++ Linker-> Libraries
- Linux: Project properties -> C/C++ Build -> Settings -> GCC++ Linker-> Libraries
Makefile
Makefiles are also provided for GNU Make/GCC environments. Executing 'make' on the corresponding folders should compile and build the library and/or example. Executing 'make' on the parent directory of both projects will build the library, copy the files to the example, and build the example.
- run the command "make"
- change directory to CGFexample/bin
- run the command "./CGFexample"