magiblot / tvision

A modern port of Turbo Vision 2.0, the classical framework for text-based user interfaces. Now cross-platform and with Unicode support.
Other
2k stars 151 forks source link

building on Win11/64bit/Visual Studio 2022 - util.h errors #67

Closed abhishekmishra closed 2 years ago

abhishekmishra commented 2 years ago

First of all, thanks for the excellent library. I've been building a tiny program on linux and it works fine. I'm using tvision as a git submodule, and building using cmake.

However, when I use Visual Studio 2022 with the same code, I get the following errors when building the generated solution... Is there something obvious I'm missing?

<prj>\tvision\include\tvision/util.h(21,22): error C2062: type 'int' unexpected [<prj>\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(21,22): error C2059: syntax error: ')' [<prj>\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(22,1): error C2143: syntax error: missing ';' before '{' [<prj>\build\ 
ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(22,1): error C2447: '{': missing function header (old-style formal list?) [D: 
\code2\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(26,22): error C2062: type 'int' unexpected [<prj>\build\ed6.vcxproj]   
<prj>\tvision\include\tvision/util.h(26,22): error C2059: syntax error: ')' [<prj>\build\ed6.vcxproj]       
<prj>\tvision\include\tvision/util.h(27,1): error C2143: syntax error: missing ';' before '{' [<prj>\build\ 
ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(27,1): error C2447: '{': missing function header (old-style formal list?) [D: 
\code2\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(34,27): error C2988: unrecognizable template declaration/definition [D:\code2 
\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(34,27): error C2059: syntax error: 'const' [<prj>\build\ed6.vcxproj]   
<prj>\tvision\include\tvision/util.h(34,1): error C2059: syntax error: ')' [<prj>\build\ed6.vcxproj]        
<prj>\tvision\include\tvision/util.h(35,1): error C2143: syntax error: missing ';' before '{' [<prj>\build\ 
ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(35,1): error C2447: '{': missing function header (old-style formal list?) [D: 
\code2\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(40,27): error C2988: unrecognizable template declaration/definition [D:\code2 
\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(40,27): error C2059: syntax error: 'const' [<prj>\build\ed6.vcxproj]   
<prj>\tvision\include\tvision/util.h(40,1): error C2059: syntax error: ')' [<prj>\build\ed6.vcxproj]        
<prj>\tvision\include\tvision/util.h(41,1): error C2143: syntax error: missing ';' before '{' [<prj>\build\ 
ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(41,1): error C2447: '{': missing function header (old-style formal list?) [D: 
\code2\ed6\build\ed6.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include\limits(41,67): fatal error C190 
3: unable to recover from previous error(s); stopping compilation [<prj>\build\ed6.vcxproj]
magiblot commented 2 years ago

Hi, Abhishek! I'm glad you like it.

Hmm, that's strange. Are you building from the command-line or from the IDE? If you are using the IDE, did you select the CMakeLists.txt file when opening the project so that Visual Studio recognizes this as a CMake project? Note that the CMake files in this project specify some custom compilation settings which may be required for the program to compile with MSVC.

Cheers.

abhishekmishra commented 2 years ago

Hi magiblot, thanks for your response. To answer your question yes I ran the build from the command prompt (via cmake) as well as from visual studio. I tried building your app turbo and it built fine with VS, then I went back and started commenting out code in my program. I was using a few C libraries, as soon as I removed them, the compilation errors for util.h went away. Turns out inclusion of c language headers is causing an error in this particular build. I'm still trying to figure out why... Once i've figured it out I will update this thread.

thanks again.

abhishekmishra commented 2 years ago

quick update - finally got the build working by moving turbovision includes above all the others. And then the build works fine without errors on vs2022.

magiblot commented 2 years ago

Now that you say that, I think I can guess what was going on. Among those other headers you were including there probably was, directly or indirectly, windows.h. When windows.h is included and the NOMINMAX macro is not defined, then it defines the min() and max() macros, which result in compilation errors if you later define functions of the same name. This is exactly the case of the tvision/util.h header where the compilation error happened. Therefore, you should also be able to solve this issue by defining the NOMINMAX macro in your CMake target.

abhishekmishra commented 2 years ago

Now that you say that, I think I can guess what was going on. Among those other headers you were including there probably was, directly or indirectly, windows.h. When windows.h is included and the NOMINMAX macro is not defined, then it defines the min() and max() macros, which result in compilation errors if you later define functions of the same name. This is exactly the case of the tvision/util.h header where the compilation error happened. Therefore, you should also be able to solve this issue by defining the NOMINMAX macro in your CMake target.

thanks this makes sense, i'll give it a shot and let you know.

abhishekmishra commented 2 years ago

hi magiblot, can confirm that defining this macro fixes the issue on msvc builds. thanks a lot for helping me fix this. here's the entry in my CMakeLists.txt

# see issue https://github.com/magiblot/tvision/issues/67#issuecomment-1038207921
# stop windows.h from definiing min and max
if (WIN32)
    add_compile_definitions(NOMINMAX)
endif (WIN32)