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

Windows compilation using MSVS does not seem to work #525

Closed
Pomax opened this issue Jan 19, 2024 · 12 comments · Fixed by #526
Closed

Windows compilation using MSVS does not seem to work #525

Pomax opened this issue Jan 19, 2024 · 12 comments · Fixed by #526

Comments

@Pomax
Copy link
Contributor

Pomax commented Jan 19, 2024

Using the cmake approach with MSVC 2022 Community Edition and the desktop c++ workload installed:

PS D:\temp\cmark> mkdir build
PS D:\temp\cmark> cd build
PS D:\temp\cmark\build> cmake ..
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.29.30151.0
-- The CXX compiler identification is MSVC 19.29.30151.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Found Python3: C:/Program Files/Python39/python.exe (found version "3.9.11") found components: Interpreter
-- Configuring done
-- Generating done
-- Build files have been written to: D:/temp/cmark/build
PS D:\temp\cmark\build> make
make : The term 'make' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ make
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (make:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Using the nmake command:

PS D:\temp\cmark> nmake

Microsoft (R) Program Maintenance Utility Version 14.38.33134.0
Copyright (C) Microsoft Corporation.  All rights reserved.

makefile(3) : fatal error U1001: syntax error : illegal character '?' in macro
Stop.
PS D:\temp\cmark>
@jgm
Copy link
Member

jgm commented Jan 19, 2024

Are you using code from current git master, or the last tagged release?
There have been a lot of cmake changes since the last release, so it would be good to know if there was a regression.

@Pomax
Copy link
Contributor Author

Pomax commented Jan 19, 2024

current master. Although those build instructions haven't changed in a literal decade as far as I can tell, so that might be part of the problem too =)

@jgm
Copy link
Member

jgm commented Jan 20, 2024

Can you try the last tagged release?

@Pomax
Copy link
Contributor Author

Pomax commented Jan 20, 2024

Absolutely. Trying https://github.com/commonmark/cmark/tree/0.30.3:

PS D:\temp\cmark> git checkout 0.30.3
Note: switching to '0.30.3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 5ba25ff Update changelog.
PS D:\temp\cmark> cd build
PS D:\temp\cmark\build> cmake ..
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.29.30151.0
-- The CXX compiler identification is MSVC 19.29.30151.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAVE_FLAG_ADDRESS_SANITIZER
-- Performing Test HAVE_FLAG_ADDRESS_SANITIZER - Failed
-- Performing Test HAVE_FLAG_SANITIZE_ADDRESS
-- Performing Test HAVE_FLAG_SANITIZE_ADDRESS - Failed
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Looking for stdbool.h
-- Looking for stdbool.h - found
-- Performing Test HAVE___BUILTIN_EXPECT
-- Performing Test HAVE___BUILTIN_EXPECT - Failed
-- Performing Test HAVE___ATTRIBUTE__
-- Performing Test HAVE___ATTRIBUTE__ - Failed
-- Found PythonInterp: C:/Program Files/Python311/python.exe (found suitable version "3.11.5", minimum required is "3")
-- Configuring done
-- Generating done
-- Build files have been written to: D:/temp/cmark/build
PS D:\temp\cmark\build> make
make : The term 'make' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ make
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (make:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS D:\temp\cmark\build>

That one's not too surprising, because MSVS does not come with make. Trying the nmake instructions:

To compile with MSVC and NMAKE:

nmake

PS D:\temp\cmark> nmake

Microsoft (R) Program Maintenance Utility Version 14.38.33134.0
Copyright (C) Microsoft Corporation.  All rights reserved.

makefile(3) : fatal error U1001: syntax error : illegal character '?' in macro
Stop.
PS D:\temp\cmark>

So, same problem.

(this is on Windows 10, with today's download of MSVS Community Edition 2022, with only the desktop C++ workload component installed, and using visual studio's view -> terminal terminal, which has all the build paths etc. preset so you don't have to wonder whether you forgot something in PATH or the like)

@jgm
Copy link
Member

jgm commented Jan 20, 2024

Makefile.nmake contains

$(SRCDIR)\case_fold_switch.inc: $(DATADIR)\CaseFolding-3.2.0.txt
	perl mkcasefold.pl < $? > $@

which is the misplaced ?. Does changing $? to $< in this file fix the problem? If so, make a PR?

@Pomax
Copy link
Contributor Author

Pomax commented Jan 20, 2024

It does not appear to. Even with this change:

$(SRCDIR)\case_fold_switch.inc: $(DATADIR)\CaseFolding-3.2.0.txt
	perl mkcasefold.pl < $< > $@

running nmake in the MSVS terminal still yields:

PS D:\temp\cmark> nmake

Microsoft (R) Program Maintenance Utility Version 14.38.33134.0
Copyright (C) Microsoft Corporation.  All rights reserved.

makefile(3) : fatal error U1001: syntax error : illegal character '?' in macro
Stop.
PS D:\temp\cmark>

I did notice that there's an nmake.bat, which can't run in powershell, so switching to cmd and trying that reports:

D:\temp\cmark>nmake.bat
NMAKE : fatal error U1064: MAKEFILE not found and no target specified
Stop.
NMAKE : fatal error U1077: 'cd build && "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX86\x86\nmake.exe" /nologo && cd ..' : return code '0x2'
Stop.

@jgm
Copy link
Member

jgm commented Jan 20, 2024

is there a --verbose option or something on nmake that would give us a more targeted error message?

@jgm
Copy link
Member

jgm commented Jan 20, 2024

Also, did you try deleting the cmake build directory and starting over after making that change to Makefile.nmake?

@Pomax
Copy link
Contributor Author

Pomax commented Jan 20, 2024

Not that I can tell.

PS D:\temp\cmark> nmake -?

Microsoft (R) Program Maintenance Utility Version 14.38.33134.0

Usage:  NMAKE @commandfile
        NMAKE [options] [/f makefile] [/x stderrfile] [macrodefs] [targets]

Options:

/B Build if time stamps are equal
/C Suppress output messages
/D Display build information
/E Override env-var macros
/ERRORREPORT:{NONE|PROMPT|QUEUE|SEND} Report errors to Microsoft
/G Display !include filenames
/HELP Display brief usage message
/I Ignore exit codes from commands
/K Build unrelated targets on error
/N Display commands but do not execute
/NOLOGO Suppress copyright message
/P Display NMAKE information
/Q Check time stamps but do not build
/R Ignore predefined rules/macros
/S Suppress executed-commands display
/T Change time stamps but do not build
/U Dump inline files
/Y Disable batch-mode
/W Display full command of any failed child process
/? Display brief usage message
PS D:\temp\cmark>

Unfortunately, none of these seems to give any more insight, which is all the more problematic given that it's still complaining about a question mark when the makefile itself no longer contains any...

And I did indeed remove the build dir.

@Pomax
Copy link
Contributor Author

Pomax commented Jan 20, 2024

Oh, hello. nmake /f Makefile.nmake gets things to compile, even though nmake Makefile.nmake does not.

PS D:\temp\cmark> nmake /f .\Makefile.nmake

Microsoft (R) Program Maintenance Utility Version 14.38.33134.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        cd build &&  cmake  -G "NMake Makefiles"  -D CMAKE_BUILD_TYPE=  -D CMAKE_INSTALL_PREFIX=windows  .. &&  cd ..
-- The C compiler identification is MSVC 19.38.33134.0
-- The CXX compiler identification is MSVC 19.38.33134.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx86/x86/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx86/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAVE_FLAG_ADDRESS_SANITIZER
-- Performing Test HAVE_FLAG_ADDRESS_SANITIZER - Failed
-- Performing Test HAVE_FLAG_SANITIZE_ADDRESS
-- Performing Test HAVE_FLAG_SANITIZE_ADDRESS - Failed
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Looking for stdbool.h
-- Looking for stdbool.h - found
-- Performing Test HAVE___BUILTIN_EXPECT
-- Performing Test HAVE___BUILTIN_EXPECT - Failed
-- Performing Test HAVE___ATTRIBUTE__
-- Performing Test HAVE___ATTRIBUTE__ - Failed
-- Found PythonInterp: C:/Program Files/Python311/python.exe (found suitable version "3.11.5", minimum required is "3")
-- Configuring done
-- Generating done
-- Build files have been written to: D:/temp/cmark/build
[  2%] Building C object src/CMakeFiles/cmark_static.dir/cmark.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
cmark.c
D:\temp\cmark\src\cmark.c(31): warning C4232: nonstandard extension used: 'free': address of dllimport 'free' is not static, identity not guaranteed
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\corecrt_malloc.h(89): note: see declaration of 'free'
[  4%] Building C object src/CMakeFiles/cmark_static.dir/node.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
node.c
D:\temp\cmark\src\node.c(351): warning C4244: '=': conversion from 'int' to 'int8_t', possible loss of data
[  6%] Building C object src/CMakeFiles/cmark_static.dir/iterator.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
iterator.c
[  8%] Building C object src/CMakeFiles/cmark_static.dir/blocks.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
blocks.c
D:\temp\cmark\src\blocks.c(996): warning C4244: '=': conversion from 'int' to 'int8_t', possible loss of data
D:\temp\cmark\src\blocks.c(1006): warning C4244: '=': conversion from 'bufsize_t' to 'uint8_t', possible loss of data
D:\temp\cmark\src\blocks.c(1034): warning C4244: '=': conversion from 'int' to 'int8_t', possible loss of data
[ 10%] Building C object src/CMakeFiles/cmark_static.dir/inlines.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
inlines.c
[ 13%] Building C object src/CMakeFiles/cmark_static.dir/scanners.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
scanners.c
[ 15%] Building C object src/CMakeFiles/cmark_static.dir/utf8.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
utf8.c
[ 17%] Building C object src/CMakeFiles/cmark_static.dir/buffer.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
buffer.c
[ 19%] Building C object src/CMakeFiles/cmark_static.dir/references.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
references.c
[ 21%] Building C object src/CMakeFiles/cmark_static.dir/render.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
render.c
D:\temp\cmark\src\render.c(99): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
D:\temp\cmark\src\render.c(105): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
[ 23%] Building C object src/CMakeFiles/cmark_static.dir/man.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
man.c
[ 26%] Building C object src/CMakeFiles/cmark_static.dir/xml.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
xml.c
[ 28%] Building C object src/CMakeFiles/cmark_static.dir/html.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
html.c
[ 30%] Building C object src/CMakeFiles/cmark_static.dir/commonmark.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
commonmark.c
D:\temp\cmark\src\commonmark.c(51): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
D:\temp\cmark\src\commonmark.c(57): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
D:\temp\cmark\src\commonmark.c(62): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
[ 32%] Building C object src/CMakeFiles/cmark_static.dir/latex.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
latex.c
[ 34%] Building C object src/CMakeFiles/cmark_static.dir/houdini_href_e.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
houdini_href_e.c
[ 36%] Building C object src/CMakeFiles/cmark_static.dir/houdini_html_e.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
houdini_html_e.c
[ 39%] Building C object src/CMakeFiles/cmark_static.dir/houdini_html_u.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
houdini_html_u.c
[ 41%] Building C object src/CMakeFiles/cmark_static.dir/cmark_ctype.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
cmark_ctype.c
[ 43%] Linking C static library cmark_static.lib
[ 43%] Built target cmark_static
[ 45%] Building C object src/CMakeFiles/cmark_exe.dir/main.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
main.c
[ 47%] Linking C executable cmark.exe
[ 47%] Built target cmark_exe
[ 50%] Building C object src/CMakeFiles/cmark.dir/cmark.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
cmark.c
D:\temp\cmark\src\cmark.c(31): warning C4232: nonstandard extension used: 'free': address of dllimport 'free' is not static, identity not guaranteed
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\corecrt_malloc.h(89): note: see declaration of 'free'
[ 52%] Building C object src/CMakeFiles/cmark.dir/node.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
node.c
D:\temp\cmark\src\node.c(351): warning C4244: '=': conversion from 'int' to 'int8_t', possible loss of data
[ 54%] Building C object src/CMakeFiles/cmark.dir/iterator.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
iterator.c
[ 56%] Building C object src/CMakeFiles/cmark.dir/blocks.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
blocks.c
D:\temp\cmark\src\blocks.c(996): warning C4244: '=': conversion from 'int' to 'int8_t', possible loss of data
D:\temp\cmark\src\blocks.c(1006): warning C4244: '=': conversion from 'bufsize_t' to 'uint8_t', possible loss of data
D:\temp\cmark\src\blocks.c(1034): warning C4244: '=': conversion from 'int' to 'int8_t', possible loss of data
[ 58%] Building C object src/CMakeFiles/cmark.dir/inlines.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
inlines.c
[ 60%] Building C object src/CMakeFiles/cmark.dir/scanners.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
scanners.c
[ 63%] Building C object src/CMakeFiles/cmark.dir/utf8.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
utf8.c
[ 65%] Building C object src/CMakeFiles/cmark.dir/buffer.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
buffer.c
[ 67%] Building C object src/CMakeFiles/cmark.dir/references.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
references.c
[ 69%] Building C object src/CMakeFiles/cmark.dir/render.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
render.c
D:\temp\cmark\src\render.c(99): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
D:\temp\cmark\src\render.c(105): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
[ 71%] Building C object src/CMakeFiles/cmark.dir/man.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
man.c
[ 73%] Building C object src/CMakeFiles/cmark.dir/xml.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
xml.c
[ 76%] Building C object src/CMakeFiles/cmark.dir/html.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
html.c
[ 78%] Building C object src/CMakeFiles/cmark.dir/commonmark.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
commonmark.c
D:\temp\cmark\src\commonmark.c(51): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
D:\temp\cmark\src\commonmark.c(57): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
D:\temp\cmark\src\commonmark.c(62): warning C4244: 'function': conversion from 'int32_t' to 'char', possible loss of data
[ 80%] Building C object src/CMakeFiles/cmark.dir/latex.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
latex.c
[ 82%] Building C object src/CMakeFiles/cmark.dir/houdini_href_e.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
houdini_href_e.c
[ 84%] Building C object src/CMakeFiles/cmark.dir/houdini_html_e.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
houdini_html_e.c
[ 86%] Building C object src/CMakeFiles/cmark.dir/houdini_html_u.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
houdini_html_u.c
[ 89%] Building C object src/CMakeFiles/cmark.dir/cmark_ctype.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
cmark_ctype.c
[ 91%] Linking C shared library cmark.dll
[ 91%] Built target cmark
[ 93%] Building CXX object api_test/CMakeFiles/api_test.dir/cplusplus.cpp.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
cplusplus.cpp
[ 95%] Building C object api_test/CMakeFiles/api_test.dir/harness.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
harness.c
[ 97%] Building C object api_test/CMakeFiles/api_test.dir/main.c.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
main.c
[100%] Linking CXX executable api_test.exe
[100%] Built target api_test
PS D:\temp\cmark>

@Pomax
Copy link
Contributor Author

Pomax commented Jan 20, 2024

So that might just require a quick change to the README.md to tell folks to run that, rather than a bare nmake. Though given that modern Visual Studio no longer uses cmd but PowerShell, that nmake.bat file might do more harm than good - if I just delete it and the build directory and then rerun nmake /f Makefile.nmake, things still compile just fine it looks like.

@Pomax
Copy link
Contributor Author

Pomax commented Jan 20, 2024

And with the /f argument, even the unedited Makefile.nmake appears to work.

Pomax added a commit to Pomax/cmark-gfm that referenced this issue Jan 20, 2024
@Pomax Pomax mentioned this issue Jan 20, 2024
@jgm jgm closed this as completed in #526 Jan 20, 2024
jgm pushed a commit that referenced this issue Jan 20, 2024
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

Successfully merging a pull request may close this issue.

2 participants