apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.78k stars 6.79k forks source link

Error detecting C++11 and C++14 #16741

Open nikudyshko opened 5 years ago

nikudyshko commented 5 years ago

Description

During configuration process, I've noticed Cmake reporting failures when trying to detect C++11 support. If USE_CXX14_IF_AVAILABLE is enabled - Cmake also fails to detect it's suport. My compiler is MSVC 19, which is, obviously, supports these standarts. Looking through the logs, I've found out that compiler has been provided with incompatible GNU-style flags -std=c++11 and -std=c++14, while for VS /std:c++11 and /std:c++14 are valid.

Error Message

From CMakeError.log

Change Dir: C:/Users/UserName/Desktop/mxnet/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/MSBuild/Current/Bin/MSBuild.exe cmTC_09eb3.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.4.0-preview-19517-01+31c846a51 for .NET Framework

Copyright (C) Microsoft Corporation. All rights reserved.

  Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28218.2 for x64

  Copyright (C) Microsoft Corporation.  All rights reserved.

  src.cxx

  cl /c /Zi /W1 /WX- /diagnostics:column /MP /Od /Ob0 /D SUPPORT_CXX11 /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_09eb3.dir\Debug\\" /Fd"cmTC_09eb3.dir\Debug\vc142.pdb" /Gd /TP /errorReport:queue  /bigobj -std=c++11 C:\Users\UserName\Desktop\mxnet\CMakeFiles\CMakeTmp\src.cxx

cl : command line warning D9002: ignoring unknown option '-std=c++11' [C:\Users\UserName\Desktop\mxnet\CMakeFiles\CMakeTmp\cmTC_09eb3.vcxproj]

  cmTC_09eb3.vcxproj -> C:\Users\UserName\Desktop\mxnet\CMakeFiles\CMakeTmp\Debug\cmTC_09eb3.exe

Source file was:
int main() { return 0; } 

To Reproduce

Just download sources and try to configure it via Cmake (I've used GUI-version)

What have you tried to solve it?

I've tried to edit CMakeLists.txt files replacing every -std=c++11 and -std=c++14 with /std:c++11 and /std:c++14. That didn't work, probably, I've missed something.

Environment

I'm using Windows 10, VS 2019, Cmake 3.16

samskalicky commented 4 years ago

@zachgk assign @larroy

zachgk commented 4 years ago

@larroy Please comment if you want to take this issue.

larroy commented 4 years ago

those flags with dash are in the else branch of the MSVC conditional, how can they be added to your build flags? Can you add a print in the cmakefile to make sure you are in the MSVC branch? I agree these flags should not be present, something is wrong if they are.

Note that they are added in the else case:


else(MSVC)
  include(CheckCXXCompilerFlag)
  if(USE_CXX14_IF_AVAILABLE)
    check_cxx_compiler_flag("-std=c++14" SUPPORT_CXX14)
  endif()
  check_cxx_compiler_flag("-std=c++11"   SUPPORT_CXX11)
  check_cxx_compiler_flag("-std=c++0x"   SUPPORT_CXX0X)
nikudyshko commented 4 years ago

I've added message()'es after if(MSVC) and else(MSVC). According to output, cmake goes through if-branch (and this is how it should go, I suppose). As I mentioned, I've tried to replace every dash-style flags in every cmake-file in the source files folders, but that doesn't changed anything.

nikudyshko commented 4 years ago

@larroy I guess, I've found a place, where error occurs. In file CMakeLists.txt there are following lines:

if(USE_CUDA AND FIRST_CUDA) 
  include(3rdparty/mshadow/cmake/Utils.cmake)
  include(cmake/FirstClassLangCuda.cmake)
  include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) 

In the file FirstClassLangCuda.cmake there are calls:

check_cxx_compiler_flag("-std=c++11"   SUPPORT_CXX11)
if(USE_CXX14_IF_AVAILABLE)
  check_cxx_compiler_flag("-std=c++14"   SUPPORT_CXX14)
endif() 

And that's where error appears. If I change -std=c++11 to /std:c++14 dection is successfull. (It looks like, that VS2015, VS2017 and VS2019 doesn't support /std:c++11, that's why I used /std:c++14 for testing)

samskalicky commented 4 years ago

@lanking520 assign @larroy

larroy commented 4 years ago

@nikudyshko so in windows we don't need to supply the flag? Can we test for C++ standard iwith CMake in windows? What do you suggest to fix?

nikudyshko commented 4 years ago

@larroy For Windows we still have MinGW, clang, etc. And it's better to leave testing for them as it is. As for VS - hard to tell. Versions before VS2015 don't even have /std flags, so it's impossible to test them this way. Newer version have complete support of C++11 (except few things), so there is no reason to test them. Unfortunately, I'm not a pro in CMake, can't suggest any good fixes, sorry. For my builds I just replaced -std=c++11 and -std=c++14 with /std:c++14, but that's more like workaround.