Reliable code inspection results while using WSL

Completed

I'm using CLion 2018.1.2 EAP with WSL (Ubuntu). I'm using the environment for development based on Boost libraries. So, I have Boost source tree with staged-libraries in `/mnt/d/boost.wsl` and test project in `/mnt/d/workshop/test_boost`.

Currently, the code parsing/inspection seems to have problems with recognising Boost definitions, so it dumps numerous errors and spreads red squiggles across source files in editor:

Note, that CMake is happy to find Boost on WSL:

 

```

/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DBOOST_ROOT=/mnt/d/boost.wsl -G "CodeBlocks - Unix Makefiles" /mnt/d/workshop/test_boost
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.67.0
-- Found the following Boost libraries:
--   unit_test_framework
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/d/workshop/test_boost/cmake-build-debug

```

If I switch to Visual Studio 2017 toolchain and CMake finds Boost in `C:\local\boost_1_67_0`, then everything works as expected:

What configuration steps I need to carry in order to teach the code inspection for betterWSL toolchain experience and find libraries on WSL?

 

UPDATE: Adding `include_directories(SYSTEM ${Boost_INCLUDE_DIR})` to my `CMakeLists.txt` does not seem to help.

0
9 comments
Avatar
Permanently deleted user

Hi! 

> So, I have Boost source tree with staged-libraries in `/mnt/d/boost.wsl`

Could you please clarify that moment? 

 

Have you tried to install boost-libs in your WSL distribution? 

sudo apt-get install libboost-all-dev

 

 

0
Avatar
Permanently deleted user

Hi,

It means, I build the special Boost stage target that places the binaries in

$BOOST_ROOT\stage\lib

where `BOOST_ROOT` is the  Boost source tree (its git repo clone).

Then, I point CMake search for Boost libraries in `$BOOST_ROOT` and, since `FindBoost.cmake` does support staged 'installation', CMake finds all the libraries and headers.

So, no I haven't tried to install Boost from the packages and that is on purpose - I'm actually using CLion to develop, build and test some of the Boost libraries, not just a client program that uses Boost.

I hope it makes sense.

Mateusz

0
Avatar
Permanently deleted user

I see. 

Am I right that CLion shows you "red code", but it successfully compiles on WSL?   

 

0
Avatar
Permanently deleted user

Vasily,

Yes, you are correct. The project compiles despite the "red code". I should have mentioned that.

 

0
Avatar
Permanently deleted user

It would be great if you provide a minimal example and short instruction how to reproduce this problem on WSL.  

Thanks in advance. 

0
Avatar
Permanently deleted user

Vasily, I was hoping the screenshot present enough details to copy, but I guess it is more convenient to copy text than OCR :) So, here we go:


Use Boost from cloned git repository and staged installation of libraries - REPRODUCE PROBLEM

1. On Windows, run `cmd.exe` and clone Boost repository

mkdir d:\boost.wsl
cd d:\boost.wsl
git clone --recursive https://github.com/boostorg/boost.git
cd boost
git checkout develop
.\bootstrap.bat


2. Install Boost headers in `d:\boost.wsl\boost` directory

cd boost.wsl
.\b2 headers

This will populate the `boost` directory with links (Windows `mklink`) tofolders and files in modular Boost.
That is how the Boost development source tree works :)

The step 1. and 2. are basically based on the "1. Clone Boost super-project"paragraph from this guide I prepared for Boost.GIL library: https://github.com/boostorg/gil/blob/develop/CONTRIBUTING.md

3. On WSL (Start > Ubuntu), build Boost.Test library and install in stage:

cd /mnd/d/boost.wsl
./b2 --with-test stage

and verify you get all necessary libraries deployed in `/mnd/d/boost.wsl/stage/lib`, eg. `libboost_unit_test_framework`, etc.

4. On Windows, launch CLion 2018.1.2. EAP and create `test_boost` project

- CMakeLists.txt

cmake_minimum_required(VERSION 3.11)
project(test_boost)
set(Boost_DETAILED_FAILURE_MSG ON)
find_package(Boost REQUIRED
  COMPONENTS unit_test_framework)
# HACK: CLion, which uses extra generator "CodeBlocks - X Makefiles",
# relies on the old-style include_directories.
if(CMAKE_EXTRA_GENERATOR)
  message(STATUS "Setting Boost_INCLUDE_DIR globally to help IDEs (eg. CLion)")
  include_directories(SYSTEM ${Boost_INCLUDE_DIR})
endif()
add_executable(use_test use_test.cpp)
target_link_libraries(use_test
  PRIVATE Boost::unit_test_framework)

- use_test.cpp

#define BOOST_TEST_MODULE test_channel_channel_traits
#include <boost/test/included/unit_test.hpp>
#include <boost/array.hpp>
#include <iostream>

auto foo() { return 1; }

BOOST_AUTO_TEST_CASE(sample_test_case)
{
    BOOST_CHECK_EQUAL(foo(), 1);

    boost::array<int, 10> a;
    BOOST_CHECK_EQUAL(a.size(), 10);
}



5. In CLion Settings > fiddle with Toolchains and CMake to target WSL.

6. In CLion Settings > CMake > CMake options > ADD `-DBOOST_ROOT=/mnt/d/boost.wsl`

7. Delete cache, reload project in CLion so CMake (re)configures it.

8. Verify, CMake finds Boost 1.67 (master branch) or 1.68 (develop branch)

10. Build (build is successful!) and wait until CLion completes analysing sources, etc.

11. Observe the red underlines/squiggles and analysis reporting errors about `BOOST_AUTO_TEST_CASE` and `BOOST_CHECK_EQUAL` macros as well as `boost::array` type cannot be resolved.


Use Boost form Ubuntu libboost packages - WORKING USE CASE FOR COMPARISON

1. Go to WSL and install Boost test (and all headers) from packages `sudo apt install libboost-test-dev`

2. In CLion Settings > CMake > CMake options > REMOVE  `-DBOOST_ROOT=/mnt/d/boost.wsl`

3. Reload project in CLion so CMake (re)configures it.

4. Verify, CMake finds Boost 1.58 - version available in Ubuntu 16.04 (WSL).

5. Rebuild, wait until CLion completes analysing sources, updating index, etc.

6. Observe all the red underlines are gone!

 

 

I hope it helps. Let me know if you need any more details.

Mat

p.s. I have to admit, lack of Markdown support for comments is a major PITA.

 

0
Avatar
Permanently deleted user

If anyone is curious what is the problem here, as explained earlier the command `./b2 headers` in `$BOOST_ROOT` populates `$BOOST_ROOT/boost/` directory with symlinks to directories for Boost source tree. Obviously, this command runs as build workflow on WSL, on Linux, and the symlinks are `ln -s` ones on Linux.

CLion running on Windows can successfully build a program including headers from `$BOOST_ROOT/boost/` the compilation runs on Linux and is able to resolve the symlinks there, but CLion running on Windows cannot resolve the Linux symlinks for code inspection and browsing.

0

@mloskot, thanks a lot for sharing the information! It seems to be related to https://youtrack.jetbrains.com/issue/CPP-12261.

1
Avatar
Permanently deleted user

Anna Falevskaya Yes, it is related. I failed to find that issue report. I think this case here can now be closed.

0

Please sign in to leave a comment.