From C/C++ to native development: Rust and Fortran plugins in CLion

Anastasia Kazakova

While CLion’s main focus is on C and C++, it also provides extensive support for other languages that supplement the C/C++ ecosystem:

  • Python (interesting fact: according to feature usage statistics, Python is used in 30% of projects opened in CLion!)
  • JavaScript, HTML, and other web technologies
  • Objective-C / Objective-C++ as supported for the first time in CLion 2018.1 EAP

Support for these languages is included in CLion by default, along with C and C++.

We also offer multiple plugins that expand CLion’s focus and make it a viable IDE for native development. We’ve recently announced support for Kotlin/Native, our technology that compiles Kotlin directly to machine code and produces executables that can run without a virtual machine.

Today, we are happy to tell you about two new language plugins that can be installed on top of your CLion (the latest improvements are available in 2018.1 EAP):

Both plugins are on their early stage of development, so issues are possible and some functionality might be missing. Your feedback and bug reports are welcome (feedback on the Fortran plugin, feedback on the Rust plugin).

Fortran

GNU Fortran compiler is provided as part of the GCC installation. The Fortran plugin is compatible with all IntelliJ-based IDEs. However, to work with Fortran project in CLion, you need to have a CMake-based project. Find a sample Fortran project build with CMake in this wiki.

The plugin supports FORTRAN 77, FORTRAN 90, FORTRAN 95, FORTRAN 2003, and FORTRAN 2008 source code. It parses Fortran code and highlights it for you. In addition, it offers many smart actions:

  • For editing code:
    • Code formatting (available for free source form files only for now)
      fortran_format
    • Add a line comment (Ctrl+Slash for Windows/Linux, ⌘/ on macOS)
    • Code folding
    • Brace matching
  • For navigation:
    • Find Usages
      fortran_usages
    • Go to Definition
    • Structure view
  • For analyzing code, a set of useful code inspections to catch potential errors:
    fortran_inspections
  • A debugger (switch to GDB in CLion):
    fortran_debugger

Rust

Like the Fortran plugin, the Rust plugin is also compatible with all IntelliJ-based IDEs. However, as we’ve already mentioned in our company blog, the debugging feature is available only in CLion for now.

If you’ve already tried the Rust plugin in CLion, your next question may be, Does it work without CMake? Well, now the answer is a resounding Yes! The Rust plugin for CLion comes with Cargo support on board!

To start a new project, use the New Project wizard, select Rust, and provide paths to the toolchain and standard library. CLion will do its best to detect it automatically if you already have it installed on your machine; the standard library can be downloaded via rustup right from the wizard:
rust_new_prj
A new Cargo project will be created for you by CLion.

To learn more about how to get Rust, configure CLion, and start a new project or work with an existing one, check out the IntelliJ Rust Quick Start Guide.

The plugin’s capabilities include:

  • plenty of smart editing features,
  • on-the-fly code analysis:
    rust_analysis
  • lots of navigation actions (like Find Usage, Go to Class, Go to Super, a File Structure view, and others),
  • options for code generation and some important refactorings,
  • Quick Documentation popup (including documentation for library functions):
    rust_quick_doc
  • and even more.

Find more details about all of the plugin’s features on its site.

Now, if you are using the Rust plugin in CLion, you can debug your Rust application right from the IDE!
Rust Debug

So, get the latest CLion 2018.1 EAP, check out one or both plugins from the plugin repository (you can do this right from the IDE in Settings/Preferences | Plugins | Browse repositories…), and enjoy!

Your CLion Team
JetBrains
The Drive to Develop

Comments below can no longer be edited.

30 Responses to From C/C++ to native development: Rust and Fortran plugins in CLion

  1. Tano says:

    March 13, 2018

    Hi Anastasia, is “Typeahead timeout is exceeded” bug in “Find in Files” fixed?
    I hope it’s fixed before releasing 2018.1, Find in Files is very hard to use with this bug.
    Thanks

    • Anastasia Kazakova says:

      March 14, 2018

      Do you mean this https://youtrack.jetbrains.com/issue/IDEA-187808? It’s under investigation now.

      • Tano says:

        March 16, 2018

        Yes please, the Find in Files is unusable because of this,thank you

        • Anastasia Kazakova says:

          March 16, 2018

          Could you please provide here https://youtrack.jetbrains.com/issue/IDEA-187808 a new stack trace, CLion build number and action you are running?

          • Tano says:

            March 21, 2018

            Ok I did.
            I am a bit worried cause it’s already RC2 and this important issue is not fixed yet, it would be bad if 2018.1 it will be released without this fixed. Thanks.

            • Anastasia Kazakova says:

              March 22, 2018

              We are on it and even if we not ready for 2018.1, we’ll provide a fix in the 2018.1.x updates soon after the release. As for now, please use a workaround.

  2. Russel Winder says:

    March 14, 2018

    I can attest that the Rust support is most excellent. Especially the debugging. Although I have stopped using C and C++ entirely, I shall be using CLion for a long while – unless JetBrains issue a Rust specific IDE.

    • Anastasia Kazakova says:

      March 14, 2018

      Thank you for your support!

  3. Graham Nash says:

    March 14, 2018

    Got yourself a CLion customer with this update. Thanks!

    • Graham Nash says:

      March 14, 2018

      (Due to the Rust part)

  4. Andreas says:

    March 16, 2018

    I like the Fortran plugin but unfortunately I cannot compile my Fortran project with cmake. I can compile it with a single gfortran line but cmake gives me weird errors. That is a pitty because of this I cannot use the debugger. 🙁

    • Anastasia Kazakova says:

      March 16, 2018

      What is the issue with CMake?

      The team plans to add Fortran/CMake project template. Meanwhile, you can add simple CMake to your project. You need to include “enable_language (Fortran)” into your CMakeLists.txt file.

      • Andreas says:

        March 16, 2018

        I have quite a simple CMake file like this:

        project(ALYA)
        cmake_minimum_required(VERSION 3.9)
        enable_language(Fortran)

        set(SOURCE “here are some source files”)

        set(CMAKE_Fortran_FLAGS “-ffree-line-length-none -fimplicit-none -fno-automatic -fbounds-check -Wall -fbacktrace -ftrapv -x f95-cpp-input -DI_AM_NOT_ALYA”)
        add_executable(“andreas.x” “${SOURCE}”)

        I can compile it normally with a single gfortran line:
        “gfortran -ffree-line-length-none -fimplicit-none -fno-automatic -fbounds-check -Wall -fbacktrace -ftrapv -x f95-cpp-input -DI_AM_NOT_ALYA -o andreas.x src/*”

        But when I compile it via cmake (either in CLion or with cmake/make on its own) I get one million error messages. I am showing only the last ones:
        “Error: Invalid character in name at (1)
        CMakeFiles/andreas.x.dir/src/andreas.f90.o:103:0:

        Error: Unclassifiable statement at (1)
        make[3]: *** [CMakeFiles/andreas.x.dir/build.make:277: andreas.x] Error 1
        make[2]: *** [CMakeFiles/Makefile2:69: CMakeFiles/andreas.x.dir/all] Error 2
        make[1]: *** [CMakeFiles/Makefile2:81: CMakeFiles/andreas.x.dir/rule] Error 2
        make: *** [Makefile:118: andreas.x] Error 2”

        • Semyon Atamas says:

          March 16, 2018

          1) Flag that causes problems: -x f95-cpp-input
          2) Problem can reproduced with gfortran if you will compile project with -c option and then will try to link .o files with provided flags (exactly what CMake does)
          3) It can be fixed by changing CMAKE_Fortran_LINK_EXECUTABLE option. See this [question](https://stackoverflow.com/questions/1867745/cmake-use-a-custom-linker) for example

          • Andreas says:

            March 19, 2018

            I think I got further but problems still remain. I used this line “set(CMAKE_Fortran_LINK_EXECUTABLE ” -o “)”

            and cmake says “/usr/bin/ld: unrecognized option ‘-Wall'”
            So I removed from the LINK_EXECUTABLE line because they are compiler and no linker flags, right?

            But then I get uncountable number of error messages like:
            “path/to/file/andreas.f90:2:undefined reference to `_gfortran_set_args’
            path/to/file/andreas.f90:2: undefined reference to `_gfortran_set_options'”
            Do I have to set another flag or variable in cmake or what am I missing here?

          • Semyon Atamas says:

            March 20, 2018

            CMAKE_Fortran_LINK_EXECUTABLE is not flags, it’s executable, that’s your problem. I didn’t found any better way to set compiler-only flags for fortran, so I proposed this as solution, maybe there is better one.
            You can find command that will be called in file ./cmake-build-debug/CMakeFiles/andreas.x.dir/link.txt or something similar. Without CMAKE_Fortran_LINK_EXECUTABLE variable it’s /usr/bin/gfortran.exe -ffree-line-length-none -fimplicit-none -fno-automatic -fbounds-check -fbacktrace -ftrapv -DI_AM_NOT_ALYA -x f95-cpp-input -g -Wl,–enable-auto-import CMakeFiles/andreas.x.dir/f.f95.o -o andreas.x.exe -Wl,–out-implib,libandreas.x.dll.a -Wl,–major-image-version,0,–minor-image-version,0 .
            You have to generate something similar with this variable. For simple linking set(CMAKE_Fortran_LINK_EXECUTABLE ” -o “) will be fine

          • Semyon Atamas says:

            March 20, 2018

            Looks like real values of this variable were corrupted in our comments. My proposal was `set(CMAKE_Fortran_LINK_EXECUTABLE “<CMAKE_Fortran_COMPILER> <OBJECTS> -o <TARGET>”)`

          • Andreas says:

            March 20, 2018

            Thank you very much! That was it. Now it compiles! That is awesome!

            But one last thing. I added the “-g” flag for debugging and set a breakpoint. But if I then start the debugging it goes directly through the program without stopping.
            Do I have to set more than that?
            I tried it with the bundled gdb and with the current gdb version 8.1.1 on Arch Linux.

            Again thank you very much for your help.

          • Semyon Atamas says:

            March 21, 2018

            As far as I know, -g flag will be added automatically when you compile program for debug.
            Are you using CLion eap, or stable? If you are using stable version of CLion then you have to use “Fortran” run configuration to debug your program.

          • Andreas says:

            March 21, 2018

            I am using stable. The Fortran Run Configuration works. Thank you for the great support!

  5. Olzhas says:

    March 23, 2018

    are there any plans on adding dlang?

    • Anastasia Kazakova says:

      March 23, 2018

      No such plans for now.

  6. Pedro N. Rodriguez says:

    September 12, 2018

    Hi,

    Great news!

    Quick question: is there a way to leverage OpenCoarrays “caf” and “cafrun” scripts from the Fortran plugin?

    Thanks!

    • Semyon Atamas says:

      September 13, 2018

      Hi,

      For now there is now special support of OpenCoarrays in plugin. If you just want to launch such program from CLion looks like you can do this with CMake. If you have any concrete ideas about what can be done inside plugin to simplify work with OpenCoarrays you are welcome to submit issue to https://github.com/satamas/fortran-plugin/issues.

  7. keru says:

    November 14, 2019

    You have no idea how happy i am to see Fortran in the list of supported language <3
    CLion was in my list from "nice to i would like to have" to "okay, i seriously want it, and will have it" 😀

    • Anastasia Kazakova says:

      November 14, 2019

      Glad to hear that!)

  8. schrajo says:

    December 18, 2019

    Is there any list and description of build-in library functions with fortran?

    • Semyon Atamas says:

      December 18, 2019

      If you mean support of fortran build in functions like SQRT, than no, plugin doesn’t have such support

  9. schrajo says:

    December 18, 2019

    no, I think of functions like system calls, file operrations etc.

    • Anastasia Kazakova says:

      December 18, 2019

      Not sure what IDE can do about such a list. Can you please comment?

Subscribe

Subscribe for updates