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

Compile error on Intel compiler running in Windows #2346

Closed
3 of 5 tasks
ongjunjie opened this issue Aug 8, 2020 · 12 comments
Closed
3 of 5 tasks

Compile error on Intel compiler running in Windows #2346

ongjunjie opened this issue Aug 8, 2020 · 12 comments
Assignees
Labels
kind: bug platform: icc related to Intel compiler release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@ongjunjie
Copy link

Unable to compile using Intel compiler in Windows. This is caused by a bug in Hedley nemequ/hedley#39. Opening an issue here to track it.

What is the issue you have?

Can't compile. See Hedley issue for details.

Please describe the steps to reproduce the issue.

  1. Build unit tests using combination of Intel compiler and Windows OS

Can you provide a small but working code example?

No.

What is the expected behavior?

Unit tests compiles.

And what is the actual behavior instead?

Build fails.

Which compiler and operating system are you using?

  • Compiler: Intel Compiler 18.0
  • Operating system: Windows 7

Which version of the library did you use?

  • latest release version 3.9.1
  • other release - please state the version: ___
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below
..\single_include\nlohmann\json.hpp(2366): error : expected a type specifier
        JSON_HEDLEY_NON_NULL(3)
@nlohmann
Copy link
Owner

Thanks for reporting! I will create a branch with the new Hedley version to see whether the issue is fixed then.

@ongjunjie
Copy link
Author

ongjunjie commented Aug 12, 2020

I did a quick hack by forcing JSON_HEDLEY_INTEL_VERSION to always evaluate false. The compilation passes but linking fails.

unresolved external symbols "__declspec(dllimport) public: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)"

The problem stems from doing a #define private while including standard headers.

#define private public
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private

Unfortunately I don't see any quick fix to this issue. Some ideas:

  • Rewrite test to use public interfaces instead of private scoped functions
  • Include all the standard headers first before doing the #define trick
  • Use protected scope instead of private. Protected members can be promoted to public scope in inherited classes.
  • Use a macro, for example JSON_private, in place of private in the library, so it can be modified without affecting STL.

@nlohmann
Copy link
Owner

This is a an issue that keeps coming up. Maybe using a macro for certain instances of private is a good idea. I’ll check.

@nlohmann
Copy link
Owner

I created PR #2352 for the private/public issue.

@nlohmann
Copy link
Owner

@ongjunjie I merged #2352. Could you please try if the tests compile now?

@ongjunjie
Copy link
Author

Unit tests compiles. Passes all tests only if I pass extra flag /fp:precise to the compiler. Intel by default uses unsafe floating point optimization.

https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/floating-point-options/fp-model-fp.html

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Aug 13, 2020
@nlohmann
Copy link
Owner

Very good! I'll wait for the Hedley release. I will also add a note to the README on the /fp:precise flag. Can you tell me which tests fail if the parameter is not set?

@ongjunjie
Copy link
Author

Failing tests when compiled without /fp:precise are:

  • test-cbor
TEST CASE:  CBOR roundtrips
  input from flynn
  • test-msgpack
TEST CASE:  MessagePack roundtrips
  input from msgpack-python
  • test-testsuites
TEST CASE:  compliance tests from nativejson-benchmark
  roundtrip

@cppshuli
Copy link

hello ,I can not complier with platform Visual Studio 2017 (v141) ,but Visual Studio 2015 (v140) works well.

@nlohmann
Copy link
Owner

Ok. Hedley 14 is now released (see #2367).

@nlohmann nlohmann added the platform: icc related to Intel compiler label Aug 24, 2020
@ongjunjie
Copy link
Author

Build and tests passing with latest develop branch. Possible to close this issue.

@nlohmann
Copy link
Owner

I added a note to the README on flag /fp:precise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug platform: icc related to Intel compiler release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants