Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: definition of macro differs between the precompiled header ('\\') and the command line(')" #1341

Open
lursyy opened this issue Feb 23, 2024 · 1 comment

Comments

@lursyy
Copy link

lursyy commented Feb 23, 2024

Similar to #410, and maybe related to bdd86b8 and 5a46525.

Problem

Some of the <PreprocessorDefinitions> generated by our custom build tool contain escaped backslashes, e.g.

[...];VCXPROJ_DIR=L"D:\\src\\path\\to\\some\\project";[...]

The corresponding clang++ parameter generated by clang-build.ps1 looks like this (from verbose output):

INVOKE: C:\Program Files\LLVM\bin\clang++.exe [...] "-DVCXPROJ_DIR=L\"D:\\src\\path\\to\\some\\project\"" [...].

Clang then produces the following error:

error: definition of macro 'VCXPROJ_DIR' differs between the precompiled header ('L"D:\\src\\path\\to\\some\\project"')
and the command line ('L"D:\src\path\to\some\project"') [clang-diagnostic-error]

What I tried

First, am I correct to assume that the escaped backslashes in our generated .vcxproj are not the problem? I tried adding a -replace "\\", "\\" in Get-ProjectPreprocessorDefines, which didn't help:

error: definition of macro 'VCXPROJ_DIR' differs between the precompiled header ('L"D:\\\\src\\\\path\\\\to\\\\some\\\\project"')
and the command line ('L"D:\\\src\\\path\\\to\\\some\\\project"') [clang-diagnostic-error]

Then I tried removing the double backslashes, i.e. -replace "\\\\", "\". That seemed to work, but somehow I doubt that this is the real solution: Wouldn't we want to preserve the ecape sequences as is? Does the Clang(++) handle these escapes differently than CL? Can the PCH be fixed so that both contain the escaped backslashes?

@lursyy
Copy link
Author

lursyy commented Mar 7, 2024

I think I just noticed an additional bug in the jsondb-export job: See JsonDB-Push:

# use only slashes
$command = $command.Replace('\', '/')
$file = $file.Replace('\', '/')
$directory = $directory.Replace('\', '/')

# escape double quotes
$command = $command.Replace('"', '\"')

where in my case $command contains backslash-escaped quotes. This results in

 \"-DVCXPROJ_DIR=L/\"D://src//path//to//some//project/\"\"

When I the run a tool that uses this compilation database (e.g. clang-rename), clang complains:

In file included from <built-in>:444:
<command line>:14:23: warning: missing terminating '"' character [-Winvalid-pp-token]
   14 | #define VCXPROJ_DIR L/"
      |                       ^

Should I create a separate issue, or are they related enough?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant