question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not compile active file if definition has quoted text

See original GitHub issue

Brief Issue Summary

If CMakeLists.txt has any C++ definition with ampersands char it brokes compiling active file.

It does not mater what kind of cmake command used no one of add_definitions, add_compile_definitions nor target_compile_definitions.

Apparent Behavior:

Just add in the file

add_compile_definitions(_WRONG_CHAR_='&')

First try configure the project and check compile_commands.json to ensure that it was correctly processed in compilers option -D_WRONG_CHAR_=\"'&'\" And you can successfully build entire project as expected.

But if you try run compile only one active file with command cmake.compileFile you will get an error, because this definition will lost first part and leave only "'&'"

Expected:

Compile active file should use the same command from compile_commands.json as it was used to compile entire project.

Other Notes

Originally the issue was noticed with following cmake code:

string(LENGTH "${CMAKE_SOURCE_DIR}/" __SOURCE_PATH_SIZE)
add_compile_definitions(__FILENAME__=\(&__FILE__[${__SOURCE_PATH_SIZE}]\))

To set __FILENAME__ in relative path of current sorce file.

Platform and Versions

  • Operating System: openSUSE 15.0
  • CMake Version: 3.13.4
  • VSCode Version: 1.40.2
  • CMake Tools Extension Version: 1.2.3
  • Compiler/Toolchain: GCC 7.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Trass3rcommented, Sep 14, 2020

The problem appears to be in the argument splitting logic where the current token is cleared when a quote char is encountered.

https://github.com/microsoft/vscode-cmake-tools/blob/de7672c1c8e2e14ecb23abd4a2128b943147d64c/src/shlex.ts#L57

It’s much easier to just let the shell do its job via shell: true or similar. Had the same problem in another extension.

0reactions
andreeiscommented, Feb 11, 2021

We almost have CMake Tools 1.6.0 release out the door. Until then, if you want, you can also verify if this problem has been fixed correctly by installing the vsix built here: https://github.com/microsoft/vscode-cmake-tools/actions/runs/557242002#artifacts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Can not compile active file if definition has quoted text -
If CMakeLists.txt has any C++ definition with ampersands char it brokes compiling active file. It does not mater what kind of cmake command...
Read more >
Visual Studio Code g++ does not compile with c++17 when ...
When I start the debugger first the file should be compiled with the command: "preLaunchTask": "C/C++: g++ build active file",. in launch.json ...
Read more >
1.1. Compiling and Executing Programs
If the compiler says that a function is undeclared, it means that you tried to use it before presenting its declaration, or forgot...
Read more >
The C Preprocessor - Math
Most preprocessor features are active only if you use preprocessing ... A header file is a file containing C declarations and macro definitions...
Read more >
FAQ — Emscripten 3.1.26-git (dev) documentation
Calling a compiled function before a page has fully loaded can result in an error, if the function relies on files that may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found