34

While running my OpenCL code in VC++ 10 by using CMake I am getting the following error:

CMake Error at CMakeLists.txt:6 (set): Syntax error in cmake code at
C:/Users/Shreedhar/Desktop/testCL/CMakeLists.txt:6

when parsing string
C:\Users\Shreedhar\Desktop\test_CL\CMakeLists
Invalid escape sequence \U
Simon
  • 31,675
  • 9
  • 80
  • 92
shunya
  • 533
  • 1
  • 5
  • 16

3 Answers3

51

Use forward slashes / in your paths

C:/Users/Shreedhar/Desktop/test_CL/CMakeLists
Simon
  • 31,675
  • 9
  • 80
  • 92
  • 4
    Or escape the backslashes: `C:\\Users\\Shreedhar\\Desktop\\test_CL\\CMakeLists` – Fraser Dec 06 '12 at 18:54
  • In a lot of cases you could also use quotes. Most of the time I just use slashes instead of backslashes and avoid this. – drescherjm Dec 06 '12 at 19:19
  • 2
    Really confused where to change the path.I'm using `camke gui` on `windows ` it just get the path by selecting,not by typing. – Shihe Zhang May 13 '17 at 03:22
  • 2
    In Windows, one should be able to give paths to CMake using backslashes. What would fix this is if the project defined a variable properly with type PATH and assigned the path there. If CMake knows it has a path, it can do backslash conversion automatically. – jmalmari May 09 '18 at 13:50
18

If you are reading user input like environment variables then you'll need to do this by character replacement feature of string method.

string(REPLACE "\\" "/" outputVar ${_inputVar})
Baris Demiray
  • 1,539
  • 24
  • 35
  • 3
    Why it no to do cmake automaticaly? – 23W Nov 25 '16 at 15:28
  • How does one do this when the value is a parameter... for example: `MACRO(foobar input) string(REPLACE "\\" "/" output ${input}) ENDMACRO()` doesn't work. It gives the parse error. I know we can do it at the calling point, but that is often inefficient – John Rocha Oct 24 '19 at 00:06
3

For those who receive this error under Windows:

CMake Error at C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:903 (list):
Syntax error in cmake code at

C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:903

when parsing string

C:\Dev\mongodb\src\boost/lib${_arch_suffix}-msvc-15.0

Invalid character escape '\D'. Call Stack (most recent call first): C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:1379 (_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS)
src/bsoncxx/CMakeLists.txt:100 (find_package)

Don't set the BOOST_ROOT environment variable to a backslash-ended value.

Alexander Pravdin
  • 4,982
  • 3
  • 27
  • 30