Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is there no MSVC support?
#1
I have seen some people struggling with compiling Colobot using Visual Studio, but when I run cmake I get an error: "Your C++ compiler doesn't seem to support C++11. Supported compilers at this time are GCC 4.6+ and clang." Does that mean that Colobot uses C++11 features which are only available in GCC and clang, but not in other compilers (like MSVC)? I wanted to try to build the project using Visual Studio Community 2013, but I don't want to waste time struggling because of the compiler itself not supporting some necessary features for building.

I have found a table with supported C++11 features in MSVC, it may be useful: https://msdn.microsoft.com/en-us/library/hh567368.aspx
[Image: XvN5CTW.png] [Image: UYXyyMS.png]
#2
It might be just that it doesn't know how to enable C++11 features in the compiler, or maybe the compiler doesn't support everything that's needed. I guess @piotrdz would know better.
Take a look at this fragment of code: https://github.com/colobot/colobot/blob/...#L117-L135
#3
Accroding to this http://stackoverflow.com/questions/19372...cc-std-c11 MSVC doesn't need any flag for C++11 support. What is important though is what actual C++11 features are used in Colobot.
[Image: XvN5CTW.png] [Image: UYXyyMS.png]
#4
I've found this: http://cpprocks.com/c1114-compiler-and-l...-shootout/
I don't know which features are needed from C++11 standard, but it seems MSVC still lack from supporting them. Maybe we could rewrite some parts of code, but:
1) if we'll have separate versions of code to gcc/clang and separate to msvc, some parts of code will be doubled, some issues could appear only to owners of specific compiler, what could make it more difficult to debug. And there will be need of copying same code two times.
2) if we'll rewrite current code to more universal - well, I don't know, it may be harder to develop, or have worst optimalisation.
Spoiler :
[Image: unknown.png]
#5
Then, @Simbax could try adding this before the final else():
Code:
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
    message(STATUS "Detected MSVC compiler")
    set(CXX11_FLAGS "")
#6
Initially we focused on porting to Linux, so support for GCC and Clang was first priority. Then, adding Windows support was easier using MinGW and MXE, as GCC was already supported. The problem with MSVC was until recently poor support for C++11, especially two features we use: range-based for loops and initializer lists. With latest updates to MSVC 2013, it seems all we need is supported, so we can finally add it as supported. The remaining problem is getting it to compile with all necessary libraries. I could give it a try sometime later and see if it really works.

PS. Yeah, I'm back Smile
#7
Ok, so who's gonna try with MSVC 2013?
PS. Welcome again Smile
Spoiler :
[Image: unknown.png]
#8
Well, Colobot uses not implemented features.


I managed to install all necessary dependencies except po4a (it took me about 3 hours and I encountered some problems, but I think I can make a proper package) and CMake successfully generated VS2013 project files. I opened a solution and tried to build it. Even music is converted without problems, but some parts of code give errors.

In app.h:
Code:
#include <unistd.h>
#include <getopt.h>
unistd.h and getopt.h are for UNIX-based systems. However, I have found these files in the Internet (their Win32 versions) and put them along the dependencies and this error no longer occured. But it's the last error that can be fixed without changing the code.

In the same file:
Code:
usleep(20000); // should still give plenty of fps

usleep function doesn't exist on Windows. There is an ugly workaround:
Code:
// Ugly fix for MSVC
#include <windows.h>

void usleep(__int64 usec)
{
   HANDLE timer;
   LARGE_INTEGER ft;

   ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time

   timer = CreateWaitableTimer(NULL, TRUE, NULL);
   SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
   WaitForSingleObject(timer, INFINITE);
   CloseHandle(timer);
}

I'm leaving here rest of the errors. I'm too tired to try to fix them and not sure if you would even let me to push these changes to the repository.

Code:
1>D:\Projects\colobot\gold\repo\src\object/level/parserexceptions.h(35): error C3646: 'noexcept' : unknown override specifier
1>D:\Projects\colobot\gold\repo\src\object/level/parserexceptions.h(36): error C3646: 'noexcept' : unknown override specifier
1>D:\Projects\colobot\gold\repo\src\object/level/parserexceptions.h(37): error C3646: 'noexcept' : unknown override specifier
1>D:\Projects\colobot\gold\repo\src\object/level/parserexceptions.h(46): error C3646: 'noexcept' : unknown override specifier
1>D:\Projects\colobot\gold\repo\src\object/level/parserexceptions.h(47): error C3646: 'noexcept' : unknown override specifier
1>D:\Projects\colobot\gold\repo\src\object/level/parserexceptions.h(53): error C3646: 'noexcept' : unknown override specifier
1>D:\Projects\colobot\gold\repo\src\object/level/parserexceptions.h(54): error C3646: 'noexcept' : unknown override specifier
...
1>D:\Projects\colobot\gold\repo\src\common\resources\sndfile.cpp(31): error C2797: 'CSNDFile::m_snd_callbacks': list initialization inside member initializer list or non-static data member initializer is not implemented
...
1>D:\Projects\colobot\gold\repo\src\object\auto\autoflag.cpp(33): fatal error C1017: invalid integer constant expression

In CBOT there are some of these errors:
Code:
1>d:\projects\colobot\gold\repo\src\cbot\CBot.h(75): fatal error C1017: invalid integer constant expression


Also, there are a lot of warnings. I'm not sure if they should be there.

Full logs are in attachments. I included only logs from building main Colobot source code and CBOT.


Attached Files
.zip   msvc13_colobot_cbot_logs.zip (Size: 65.99 KB / Downloads: 447)
[Image: XvN5CTW.png] [Image: UYXyyMS.png]
#9
Well, you're right, we still have some dependencies to Unix utilities. We should not be using unistd.h and getopt.h directly, but provide the necessary functions via SystemUtils interface. The noexcept error could be fixed by providing an empty noexcept macro and the two remaining errors can be fixed with some rewriting of code. Some warnings are also worth to look at. I have some time today, so I should be able to fix it.

Still, such problems are pretty embarrassing for Microsoft, as C++11 standard is now almost 4 years old, yet their compiler still doesn't fully support it.

Update: I almost forgot just how much pain it is to compile something under Windows. But I finally got it to compile Smile I will commit my fixes tomorrow as I'm too tired today.
#10
So 0.1.5 will have support for MSVC 2010 or 2013?
Spoiler :
[Image: unknown.png]
#11
(04-26-2015, 11:22 PM)tomangelo Wrote: So 0.1.5 will have support for MSVC 2010 or 2013?

Indeed it will as I've just committed my changes. I compiled the project successfully using MSVC 2013 with update 4, and I think this is the only version which works. I can also provide a link to download archive with necessary libraries. What still doesn't work is generation of translations in data submodule, as for this you need some minimum Unix environment (perl, bash, sed, etc.).
#12
So, here's my pack with all necessary dependencies to compile Colobot: Gold Edition using Microsoft Visual Studio 2013.

Content:
  • All files necessary for successful CMake build
  • oggenc to convert music files
  • All necessary DLL files needed to run a compiled game
  • Only tested with Microsoft Visual C++ 2013
  • Probably works only for 32-bit version
I'll assume you already have a local git repository or downloaded sources of the game.

Instructions:
  1. Install CMake.
  2. Unpack the zip file to some directory (f.e. C:\Dev\colobot-dependencies-msvc2013).
  3. If you want to have music, copy bin\oggenc.exe file to a directory which is included in your PATH. If you won't do it and you have music submodule in your local repository, it will result in errors during installation.
  4. Use cmake-gui or a command line in order to build Colobot to some directory (preferably colobot-repo\build).
  5. Run cmake with at least these variables set:
    • Visual Studio 12 2013 generator (or newer if you have other version installed, don't know if it will work)
    • CMAKE_PREFIX_PATH = path to the directory where you unpacked colobot-dependencies-msvc2013
    • BOOST_STATIC = 1 (dynamic build for some reason doesn't work for me)
    • CMAKE_BUILD_TYPE = Release or Debug
    • You can also add other configuration variables of course.
  6. Open generated colobot.sln file using Microsoft Visual Studio.
  7. Change the configuration type from Debug to Release.
  8. Right click on the solution in the Solution Explorer and set INSTALL to be built (in Configuration Properties.)
  9. Build solution (F7).
  10. Colobot will be probably installed to C:\Program Files\colobot. Copy there all DLL files from colobot-dependencies-msvc2013/DLLS.
  11. Set all convert* projects to not be built for better future compilation times (you only need to convert them once, but Visual Studio would convert them every time which takes some time).
  12. You can finally enjoy/test/develop the game with your own Windows build! (except translations...)
Download:
https://dl.dropboxusercontent.com/u/1668...vc2013.zip
[Image: XvN5CTW.png] [Image: UYXyyMS.png]
#13
Thanks Simbax, I'll try this when I'm back at home.
"After three days without programming, life becomes meaningless."
~The Tao of Programming
#14
For the record, here is my own package with necessary libraries: http://www.speedyshare.com/ApU57/colobot-msvc-libs.zip

The package contains basically the same as Simbax's one, but I changed SDL_image to use libpng in one version. It should also work according to instructions above.
#15
Finally, I can compile Colobot on Windows without messing with MinGW. And test new things. Thank you guys.
"After three days without programming, life becomes meaningless."
~The Tao of Programming


Forum Jump:


Users browsing this thread: 1 Guest(s)