Visual Studio 编译使用FLTK库

FLTK介绍

FLTK (Fast Light Tool Kit 发音为fulltick) 是一种使用C++开发的GUI工具包,它可以应用于Unix,Linux,MS-Windows95/98/NT/2000和MacOS操作系统平台,相 对于其它的许多图形接口开发工具包(如MFC、GTK、QT等),它具有体积很小、速度比较快,且有着更好的移植性。

下载界面库

FLTK官网下载最新版本的源码(e.g. fltk-1.3.4-1-source.tar.gz)。解压源码文件到相应的目录,

C:UsersyournameDownloadsfltk-1.3.4

Build FLTK库

下面介绍如果再Visual Studio中Build Solution

  1. 找到工程文件夹。
    fltk-1.3.4ideVisualC2010
  2. 双击fltk.sln,耐心等待visual studio打开。
  3. Build菜单中找到 Configuration Manager并打开,切换到Release。
  4. Build菜单中找到 Rebuild Solution并点击,耐心等待Build完成。

将FLTK库添加到Visual Stidio中

Build成功之后我们需要做的就是把文件拷贝到相应的目录内。

  1. 复制 FL and GL 文件夹, 例如,
    C:UsersyournameDownloadsfltk-1.3.4FL
    C:UsersyournameDownloadsfltk-1.3.4GL
    到Visual Studio的$(VC_IncludePath)文件夹下
    C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.10.25017include
  2. 复制lib文件夹下的所有文件,
    C:UsersyournameDownloadsfltk-1.3.4lib
    到Visual Studio的$(VC_LibraryPath_x86) 文件夹下
    C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.10.25017libx86

测试是否通过

重新打开Visual Studio 新建一个win32 project,在project wizard中选择Empty。
好了,现在我们新建一个main.cpp

#include <Windows.h> // include Windows.h only if using WinMain
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>

// Use standard main to have console background:
// int main()

// Use WinMain if you don't want the console in the background:
int __stdcall WinMain(
    __in HINSTANCE hInstance,
    __in_opt HINSTANCE hPrevInstance,
    __in LPSTR lpCmdLine,
    __in int nShowCmd
    )
{
    Fl_Window window( 200, 200, "My window title" );
    Fl_Box box( 0, 50, 200, 20, "Hello" );
    window.show();
    return Fl::run();
}

项目右键Properties,需要做以下几个修改,需要注意的是Release和Debug都需要进行设置

Configuration Properties
        C/C++
            Code Generation
                Runtime Library
                        Multi-threaded Debug DLL (/MDd)
        Linker
            Input
                Additional Dependecies
                        fltk.lib
						fltkimages.lib
						fltkjpeg.lib
						fltkpng.lib
						fltkzlib.lib
						fltkgl.lib
						fltkforms.lib

                Ignore Specific Default Libraries
                        libcd.lib

Project Properties

现在我们可以Build并运行了,如果可以正常运行就表示我们安装成功了。

原文地址:https://www.cnblogs.com/lkpp/p/Installing-FLTK-with-VisualStudio.html