How to build and use FLTK with CLion?

1,719 views
Skip to first unread message

Jordan Harris

unread,
Jul 8, 2015, 8:40:33 PM7/8/15
to fltkg...@googlegroups.com
Hello,

Does anyone know how to easily build FLTK using CLion, which uses the CMake build system. I'm a Visual Studio guy and I've only used it, but I really want to give CLion a try and using FLTK with it would be a great way to try it.

I would really appreciate any help you guys could give me. I'm not an experienced programmer at all so there's a lot I don't know about things, like CMake for example. I'm actually using FLTK because I'm reading the book Programming Principles and Practice Using C++ 2nd Ed. Anyways, thanks in advance for any help anyone can give me.

I might end up needing help with figuring out how to actually use FLTK with CLion, but I need to figure out how to build it first.

- Jordan

Albrecht Schlosser

unread,
Jul 9, 2015, 10:11:22 AM7/9/15
to fltkg...@googlegroups.com
On 09.07.2015 02:31 Jordan Harris wrote:

> Does anyone know how to easily build FLTK using CLion, which uses the
> CMake build system.

I don't know of any FLTK dev using CLion, but recently there was a post
about it. I can't tell how to use CLion with FLTK, but maybe it's
straightforward because FLTK has CMake build files you may use. OTOH
this might need some deeper knowledge if it doesn't work immediately.

> I'm a Visual Studio guy and I've only used it, but I
> really want to give CLion a try and using FLTK with it would be a great
> way to try it.

IIRC you can use CLion only with certain compilers (toolchains), and I
don't know if one comes bundled with CLion. Again, IIRC, I believe that
you can use gnu compilers under Windows, and that would probably be
MinGW or Cygwin. Hence it is likely a good idea to try to build FLTK
with a supported development environment first, and we (the FLTK team)
recommend using MinGW. If you need help we can support you pretty well
with questions about MinGW and FLTK. See more below.

> I would really appreciate any help you guys could give me. I'm not an
> experienced programmer at all so there's a lot I don't know about
> things, like CMake for example.

Note that CMake is a system to configure the build system you want to
use, not a build system of its own. Hence you basically need a compiler
and maybe make etc., or you can even create Visual Studio IDE files with
CMake - but that is something you probably don't want to do, according
to your question.

> I'm actually using FLTK because I'm
> reading the book Programming Principles and Practice Using C++ 2nd Ed.
> Anyways, thanks in advance for any help anyone can give me.

Okay, then you should also know that FLTK 1.3.x is the only supported
FLTK version right now. Don't try anything else.

> I might end up needing help with figuring out how to actually use FLTK
> with CLion, but I need to figure out how to build it first.

I'd recommend to install MinGW including the MSYS build tools and use
standard autoconf + make to see how that works. If you install the FLTK
tarball somewhere you can just run 'make' to build FLTK. Everything
should work OOTB.

Once this is working you can try to import the FLTK CMake files into
CLion and try if this works as well.

But maybe I'm talking nonsense and CLion has all you need and you don't
need to install MinGW separately...

Michael Surette

unread,
Jul 9, 2015, 10:17:37 AM7/9/15
to fltkg...@googlegroups.com

If you use a recent version of FLTK it should just work. The Cmake support is fairly well flushed out, although more testing would be great. Let us know how it works for you.

fabien

unread,
Jul 9, 2015, 5:32:24 PM7/9/15
to fltkg...@googlegroups.com, Albrech...@online.de
As already explained by my peers,t it should be straightforward as the only thing you should care about is to import the cmake initial project into CLion and let it parse it and generate its cmake cache first.

Now, because I noted slight differrences in the way CLion target is building (it is creating its own output temporary target path override by default) you might want to revisit the CMakeCache flags.

The good news is these flags are also accessible from the CLion interface from the project top node selection (look a t the bottom tabs thumbnail views)

Glad to see other people interested by new IDE's naively supporting CMake !
Let us know if you encounter specific problems as user experience for sure differs slightly between platforms (i.e.: windows MinGW compilers don't  install LLVM compilers by default so don't expect modern C++11/14/17 features to be present there and only use a subset of them common to both gnu GCC and CLang as an example which is only a problem in your own code as fltk does not use these extensions).

Hope that helps,
-Fab

Jordan Harris

unread,
Jul 10, 2015, 10:09:30 AM7/10/15
to fltkg...@googlegroups.com
So I tried the demos and they all work so I think I did get it to compile, but I have no idea how to link and include the FLTK files with CMake. Is there an easy solution to this? It's about to drive me nuts trying to figure this out.

Jordan Harris

unread,
Jul 10, 2015, 10:09:30 AM7/10/15
to fltkg...@googlegroups.com
Thanks for the replies everyone. So it appears I was able to build FLTK from the command line after using 4.9.1 instead of 4.9.2 and using make. I say appear because I haven't tested it yet. I've had a long run at trying to get this to work and searching the internet for info. I pretty much got nowhere searching the internet, but it saddens like I built FLTK because I got all the files in the lib folder.

This was my first time trying to use MinGW (and Cygwin) so I have no idea what I'm doing. Yeah, I'm a beginner. I'm willing to try and learn though and I'm willing to try out different environments and tools. Especially so on other platforms than Windows. I have to say, I really enjoy Visual Studio and it makes writing and understanding code write ready and enjoyable. For me, it actually helps me learn how to program easier since it's so simple to use and I can focus on the code.

From what I've tried in CLion so far (which really isn't much) and what I've seen in their videos, it seems like a great tool. I really like all of the refactoring and code generation tools it has, which is something Visual Studio is lacking (but getting better). I think trying to learn CMake is going to be the hardest part for me, since I know nothing about it.

I was hoping I would be able to build FLTK directly from CLion, but I couldn't seem to get that to work correctly. If anyone figures that out, please let me know. I didn't even know where to begin.

Matthias Melcher

unread,
Jul 10, 2015, 3:47:30 PM7/10/15
to fltkg...@googlegroups.com

On Fri Jul 10 2015 13:34:17, Jordan Harris wrote:
>
> From what I've tried in CLion so far (which really isn't much) and what I've seen in their videos, it seems like a great tool. I really like all of the refactoring and code generation tools it has, which is something Visual Studio is lacking (but getting better).

Yes, I am starting to get hooked. It looks like a really useful tool!

> I think trying to learn CMake is going to be the hardest part for me, since I know nothing about it.

Yes, on that one as well. ;-)

- Matthias


Albrecht Schlosser

unread,
Jul 10, 2015, 3:58:27 PM7/10/15
to fltkg...@googlegroups.com
Take a look at the file README.CMake in the FLTK root directory.

HTH

Matthias Melcher

unread,
Jul 10, 2015, 4:27:46 PM7/10/15
to fltkg...@googlegroups.com
Ok, sorry to answer to my own post. FLTK 1.3 on Xcode can be loaded into CLion simply by importing the directory. That's it. Nothing else to do. Just choose "Run..." and select "Fluid". CLion will build and run Fluid.

Awesome!

- Matthias

PS: this also means that likely nothing is wrong with FLTK, but with the Cygwin setup of the OP.

Jordan Harris

unread,
Jul 10, 2015, 7:21:03 PM7/10/15
to fltkg...@googlegroups.com
Ok, sorry to answer to my own post. FLTK 1.3 on Xcode can be loaded into CLion simply by importing the directory. That's it. Nothing else to do. Just choose "Run..." and select "Fluid". CLion will build and run Fluid.

Awesome!

 - Matthias

PS: this also means that likely nothing is wrong with FLTK, but with the Cygwin setup of the OP.

I'm actually able to build it directly from CLion as well, since I used a different version of MinGW. For a while, it was storing the builds in a really weird directory that I couldn't find. I finally figured out how to make it use a certain relative path from Settings -> Build, Execution, Deployment -> CMake -> Build output path. So yeah, apparently you can build it right from CLion, somewhat similarly to how you would with a Visual Studio project or something. Now I just need to figure out how to link FLTK and include the headers.

Thank you Albrecht Schlosser, I'll try to do what's instructed in the README.CMake file. Hopefully I can get a working project and make some sort of template so it's easy to start new projects, which I'm doing very often when I'm doing things from this book. That's how I set up FLTK in Visual Studio and it's pretty awesome.

By the way, here's the path that it was building to before I changed it:
C:/Users/Jordan/.clion10/system/cmake/generated/dd62ab6a/dd62ab6a/__default__

Matthias Melcher

unread,
Jul 11, 2015, 4:38:30 AM7/11/15
to fltkg...@googlegroups.com

On Sat Jul 11 2015 01:01:31, Jordan Harris wrote:
>
> Now I just need to figure out how to link FLTK and include the headers.

On Apple OS X the magic command line is:


sudo cmake -DBUILD_TYPE=Debug -P cmake_install.cmake


You probably don't need the 'sudo' in Cygwin and you can just leave it out. If that works, then adding


add_custom_target(myinstall COMMAND ${CMAKE_MAKE_PROGRAM} install)


to CMakeLists.txt will create a 'myinstall' target in CLion that will install fltk for you.


In you new project, start the CMakeLists.txt file like this, and everything will be built for you with FLTK:


<code>

cmake_minimum_required(VERSION 3.0.0)

project (CWatt)

INCLUDE_DIRECTORIES(/usr/local/include)
LINK_DIRECTORIES(/usr/local/lib)

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Cocoa")

add_executable(CWatt MACOSX_BUNDLE cwatt.cxx)
TARGET_LINK_LIBRARIES(CWatt fltk)

</code>

Reply all
Reply to author
Forward
0 new messages