Vscode-cpptools: Code formatting does not work in the latest version of libtinfo

Created on 14 Feb 2019  路  21Comments  路  Source: microsoft/vscode-cpptools

Type: LanguageService

Describe the bug

  • OS and Version: Kubuntu 18.10
  • VS Code Version: 1.31.1
  • C/C++ Extension Version: 0.21.0
  • Other extensions you installed (and if the issue persists after disabling them): vscjava.vscode-java-debug, dbaeumer.vscode-eslint, redhat.java, james-yu.latex-workshop, felixfbecker.php-debug, felixfbecker.php-pack, felixfbecker.php-intellisense, ms-python.python, redhat.vscode-yaml
  • A clear and concise description of what the bug is.
    The code formatting does not work unless libtinfo5 package is installed. It shows a notification "Formatting failed" with the prompt to check the output window. The current package is libtinfo6 which comes installed in Kubuntu 18.10 as default and the package manager identifies libtinfo5 as the legacy version.

To Reproduce

  1. Install the Microsoft C/C++ extension in VS Code installed on a fresh Kubuntu 18.10 installation.
  2. Run the 'Format Document' command in the 'Command Palette' (or press Ctrl + Shift + I which is the default keybinding)
  3. Open the output window (Ctrl + J) and choose C/C++ in the drop down list.
  4. See error (error shown in the output window given below)

Expected behavior

The code will be formatted with proper indentation, spacing, etc.

Screenshots

Additional context
From the output window:

Formatting failed:
/home/user/.vscode/extensions/ms-vscode.cpptools-0.21.0/bin/../LLVM/bin/clang-format -style={ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0 } -fallback-style=LLVM -sort-includes=0 -assume-filename=/home/user/program.c
  /home/user/.vscode/extensions/ms-vscode.cpptools-0.21.0/bin/../LLVM/bin/clang-format: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

-->I believe that giving the Microsoft C/C++ extension support for libtinfo6 will solve the problem.

Code Formatting Language Service bug fixed (release pending)

Most helpful comment

I have the same issue running similar specs to OP except regular Ubuntu 18.10

Here is my output when I try to format the code using VSCode.

Formatting failed:
/home/jorge/.vscode/extensions/ms-vscode.cpptools-0.21.0/bin/../LLVM/bin/clang-format -style={BasedOnStyle: Google, ColumnLimit: 70} -fallback-style=LLVM -assume-filename=/home/jorge/Programming/testing/fishy/main.cpp
  /home/jorge/.vscode/extensions/ms-vscode.cpptools-0.21.0/bin/../LLVM/bin/clang-format: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

When running from the command line:

$ ./../../../.vscode/extensions/ms-vscode.cpptools-0.21.0/LLVM/bin/clang-format main.cpp 

./../../../.vscode/extensions/ms-vscode.cpptools-0.21.0/LLVM/bin/clang-format: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
zsh: exit 127   ./../../../.vscode/extensions/ms-vscode.cpptools-0.21.0/LLVM/bin/clang-format

As a work around I instsalled clang-format

sudo apt install clang-format

and then figured out where it lived in my system

which clang-format
# outputs: /usr/bin/clang-format

and used that output for the value in my settings.json

{
  "C_Cpp.clang_format_path": "/usr/bin/clang-format"
}

and everything seemed dandy!

All 21 comments

We redistribute clang-format (we do not compile it). Are you able to run it directly in your terminal window? /home/user/.vscode/extensions/ms-vscode.cpptools-0.21.0/LLVM/bin/clang-format

Does LLVM distribute a version of clang-format that works for you without installing libtinfo5?

@joeljosephreji ...as in, do newer versions (or the Ubuntu 18 one) at http://releases.llvm.org/download.html that work for you? I believe we ship the Ubuntu 14 version (or maybe the 16 one?), so we might need to ship additional ones.

I have the same issue running similar specs to OP except regular Ubuntu 18.10

Here is my output when I try to format the code using VSCode.

Formatting failed:
/home/jorge/.vscode/extensions/ms-vscode.cpptools-0.21.0/bin/../LLVM/bin/clang-format -style={BasedOnStyle: Google, ColumnLimit: 70} -fallback-style=LLVM -assume-filename=/home/jorge/Programming/testing/fishy/main.cpp
  /home/jorge/.vscode/extensions/ms-vscode.cpptools-0.21.0/bin/../LLVM/bin/clang-format: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

When running from the command line:

$ ./../../../.vscode/extensions/ms-vscode.cpptools-0.21.0/LLVM/bin/clang-format main.cpp 

./../../../.vscode/extensions/ms-vscode.cpptools-0.21.0/LLVM/bin/clang-format: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
zsh: exit 127   ./../../../.vscode/extensions/ms-vscode.cpptools-0.21.0/LLVM/bin/clang-format

As a work around I instsalled clang-format

sudo apt install clang-format

and then figured out where it lived in my system

which clang-format
# outputs: /usr/bin/clang-format

and used that output for the value in my settings.json

{
  "C_Cpp.clang_format_path": "/usr/bin/clang-format"
}

and everything seemed dandy!

That is strange because we have tested on Ubuntu 18 and formatting works for us. I ran ldd on the latest Ubuntu 18 clang 7 and it still has the libtinfo.so.5 dependency. Can you run "/usr/bin/clang-format --version" and "ldd /usr/bin/clang-format" to see what version it is and what libtinfo.so dependency it has?

@sean-mcmanus

$ /usr/bin/clang-format --version
clang-format version 7.0.0-3 (tags/RELEASE_700/final)

$ ldd /usr/bin/clang-format
    linux-vdso.so.1 (0x00007ffda8bf9000)
    libLLVM-7.so.1 => /usr/lib/x86_64-linux-gnu/libLLVM-7.so.1 (0x00007fc3d192a000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc3d17a0000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc3d15b6000)
    libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fc3d13ae000)
    libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007fc3d1176000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc3d0f59000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc3d0f4d000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc3d0f47000)
    libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007fc3d0d1c000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc3d0cfb000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc3d0b6e000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc3d0b54000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fc3d59ad000)

@penguingovernor Okay -- we tested with Ubuntu 18.04 and not 18.10 -- the binary we ship appears to be incompatible with that OS, so the workaround you did is the recommended course until we can get an alternative binary.

We redistribute clang-format (we do not compile it). Are you able to run it directly in your terminal window? /home/user/.vscode/extensions/ms-vscode.cpptools-0.21.0/LLVM/bin/clang-format

I haven't tried terminal editing and the formatting worked without the clang-format package installed

Does LLVM distribute a version of clang-format that works for you without installing libtinfo5?

I don't have clang-format package installed

@joeljosephreji ...as in, do newer versions (or the Ubuntu 18 one) at http://releases.llvm.org/download.html that work for you? I believe we ship the Ubuntu 14 version (or maybe the 16 one?), so we might need to ship additional ones.

I haven't tried out clang-format in my terminal at all. I have to check it out. When I did an apt search llvm and an apt search clang, the only package I found installed is libllvm7. I will test clang-format in my terminal and share the results here.

@penguingovernor Okay -- we tested with Ubuntu 18.04 and not 18.10 -- the binary we ship appears to be incompatible with that OS, so the workaround you did is the recommended course until we can get an alternative binary.

Cool, so I guess from the looks of things clang-format6 (I got that by running ~/.vscode/extensions/ms-vscode.cpptools-0.21.0/bin/../LLVM/bin/clang-format --version) package is being shipped in the extensions which requires libtinfo5 package installed and the default clang-format for Ubuntu 18.10 is clang-format7 which requires libtinfo6 (which is installed by default). So, the solution would be to have the latest clang-format binaries isn't it?

@joeljosephreji Yes, this is a breaking incompatibility change with Ubuntu 18.10 -- I don't know if that is "by design" or a bug with the OS. Ubuntu 18.10 itself distributes a specially compiled clang-format 7 with the libtinfo6 dependency, which is not available from the pre-built binaries on the LLVM download site. Ubuntu 18.04 doesn't have this issue. Until we can ship a special version for Ubuntu 18.10, users will have to manually install clang-format and set our C_Cpp.clang_format_path to reference that.

@joeljosephreji Yes, this is a breaking incompatibility change with Ubuntu 18.10 -- I don't know if that is "by design" or a bug with the OS. Ubuntu 18.10 itself distributes a specially compiled clang-format 7 with the libtinfo6 dependency, which is not available from the pre-built binaries on the LLVM download site. Ubuntu 18.04 doesn't have this issue. Until we can ship a special version for Ubuntu 18.10, users will have to manually install clang-format and set our C_Cpp.clang_format_path to reference that.

Or the issue can be resolved by just installing libtinfo5 package in Ubuntu 18.10 and its variants.

As i said in another similar issue, if you have libtinfo.so.6 you can create a simple system link instead of downloading new packages. Here's how!
Run: ls /lib/ | grep libtinfo
Then if you can see libtinfo.so.6
Run: sudo link /lib/libtinfo.so.6 /lib/libtinfo.so.5

I see that folks are talking about clang/LLVM with regard to libtinfo, but out of curiosity I did a "pacman -Qo /usr/lib/libtinfo.so.6" (not .5 since it didn't exist) and I see it is owned by ncurses.
So... something is out of date?

I found it really odd that only now have I just encountered this issue.
In my other thread regarding /tmp/edg files, we've gone over the clang/gcc issue as well and I thought I had moved all over to gcc, but now this formatting thing also relates to clang for some reason.

Maybe I should just move over to clang and be done with gcc.

But yeah, after ln so.5 to so.6, formatting worked right away.

I see on my old OS partition, I already had that link and found the owner for that linkage is ncurses5-compat-libs which looks to only be available in the AUR.

Here is another workaround:

I have also tried 'sudo link /lib/libtinfo.so.6 /lib/libtinfo.so.5' (same as #GiuseppeCesarano suggested above).
It does work but it opens the door to dll hell, which can, someday, end in corrupted files.
Being a paranoid I took the longer way:

I have installed clang-format and friends, as described in the clang site

Then, following the path in the error report:

cd ~/.vscode/extensions/ms-vscode.cpptools-0.26.2/LLVM/bin
mv clang-format clang-format.bak
ln -s /usr/bin/clang-format clang-format

This works (Ubuntu 19.10). It calls the installed clang-format and relies on the integrity of its installation.

and used that output for the value in my settings.json

{
  "C_Cpp.clang_format_path": "/usr/bin/clang-format"
}

Could we make this default, and the shipped version as a fallback?

@Sam0523 We're tracking using the version on the path with https://github.com/microsoft/vscode-cpptools/issues/4618 .

{
  "C_Cpp.clang_format_path": "/usr/bin/clang-format"
}

In Manjaro Linux the solution I found is similar. Installing clang-format:

pamac install clang-format-all-git

And then editing settings.json as @penguingovernor exposed in his comment.

Our Insiders release fixes the clang-format dependency problems: https://github.com/microsoft/vscode-cpptools/releases/tag/0.27.0-insiders

0.27.0-insiders (accidentally) didn't have the new clang-format, but 0.27.0-insiders3 does.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DemoCrazer picture DemoCrazer  路  3Comments

montery8 picture montery8  路  3Comments

SkyRiderMike picture SkyRiderMike  路  3Comments

thndrwrks picture thndrwrks  路  3Comments

jrieken picture jrieken  路  3Comments