eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.63k stars 382 forks source link

compile error: duration.inl - duration literals are not found #1078

Closed niclar closed 2 years ago

niclar commented 2 years ago

seems like the duration literals are not resolved during compilation of iceoryx_hoofs/internal/units/duration.inl in vs

e.g iceoryx_hoofs/internal/units/duration.inl(79,23): error C3861: '_ns': identifier not found

they are defined later in the header (inline namespace duration_literals)

elfenpiff commented 2 years ago

@niclar Again, thanks for the hint :D ... I am wondering why our CI did not catch this.

niclar commented 2 years ago

I'm running vs 2022 (Version 17.1.0 Preview 5.0)

niclar commented 2 years ago

I don't really understand why the operators don't resolve but I got it compile by using a wrapper in place of the user literals as;

inline constexpr Duration to_ns(unsigned long long int value) noexcept
{
    return operator"" _ns(value);
}

template <typename T>
constexpr Duration Duration::fromNanoseconds(const T value) noexcept
{
    return to_ns(positiveValueOrClampToZero(value, __PRETTY_FUNCTION__));
}
elfenpiff commented 2 years ago

I think the problem lies in the inline namespace duration_literals which has some issues with msvc. Turning this inline namespace into a normal namespace should solve the problem. But I cannot verify this yet (my VS2022 installation takes some time ;) ).

elfenpiff commented 2 years ago

@niclar Would you be able to test #1080 for me? This should fix this problem in theory.

niclar commented 2 years ago

@elfenpiff sure. -It did not unfortunately. -So the issue is with the user define literal lookup specifically. My fix above, albeit ugly, fixes it though

elfenpiff commented 2 years ago

@niclar I tried to reproduce it on windows 10 and windows 11 with the current preview version but without success.

Here are the versions of the toolchain: Build for: Visual Studio 17 2022 Windows SDK version: 10.0.19041.0 Build Engine version: 17.0.0+c9eb0dd64 for .NET Frameworks MSVC compiler version: 19.30.30709

You see them when you remove the build directory and start cmake from command line like:

cd iceoryx
cmake -Bbuild -Hiceoryx_meta -DEXAMPLES=ON -DBUILD_TEST=ON

Can you send me your version numbers?

niclar commented 2 years ago

@elfenpiff run the latest preview. The icoryx_packackage.vcxproj builds. But the includes below (following an example, iceoryx/iceoryx_examples/singleprocess/single_process.cpp) triggers the error.

-- Building for: Visual Studio 17 2022 -- The C compiler identification is MSVC 19.31.31104.0 -- The CXX compiler identification is MSVC 19.31.31104.0

include <iceoryx_hoofs/cxx/convert.hpp>

include <iceoryx_hoofs/log/logmanager.hpp>

include <iceoryx_hoofs/posix_wrapper/signal_watcher.hpp>

include <iceoryx_posh/iceoryx_posh_config.hpp>

include <iceoryx_posh/iceoryx_posh_types.hpp>

include <iceoryx_posh/internal/roudi/roudi.hpp>

include <iceoryx_posh/popo/publisher.hpp>

include <iceoryx_posh/popo/subscriber.hpp>

include <iceoryx_posh/roudi/iceoryx_roudi_components.hpp>

include <iceoryx_posh/runtime/posh_runtime_single_process.hpp>

... iox::runtime::PoshRuntime::initRuntime("test");

elfenpiff commented 2 years ago

@niclar It was my fault, I did not use the latest preview. But even now I cannot reproduce the error.

This is my msvc version: 19.31.31104.0

Can you please do the following:

  1. stash your changes and use the current iceoryx master
  2. Open a powershell
    cd iceoryx
  3. Check the current git hash you are using (just to make sure we both use the current master), mine is 9937240a0:
    git rev-parse --short HEAD
  4. Remove the build folder if it exists
    Remove-Item -recurse -force build
  5. Regenerate the cmake configs
    cmake -Bbuild -Hiceoryx_meta -DEXAMPLES=ON -DBUILD_TEST=ON
  6. Build everything with
    cmake --build build

When the build fails could you send me please the console output leading to this error or maybe the whole log?

niclar commented 2 years ago

I'm on 947a850e185951dbb8d1108c4e1347e5fa757119 but I see no later changes that would remedy this..

1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/cxx/helplets.hpp(225,9): warning C4068: unknown pragma 'GCC' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/cxx/helplets.hpp(226,9): warning C4068: unknown pragma 'GCC' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/cxx/helplets.hpp(230,9): warning C4068: unknown pragma 'GCC' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.inl(79,23): error C3861: '_ns': identifier not found 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.hpp(87,31): message : This diagnostic occurred in the compiler generated function 'iox::units::Duration iox::units::Duration::fromNanoseconds(const T) noexcept' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.inl(84,23): error C3861: '_us': identifier not found 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.hpp(95,31): message : This diagnostic occurred in the compiler generated function 'iox::units::Duration iox::units::Duration::fromMicroseconds(const T) noexcept' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.inl(89,23): error C3861: '_ms': identifier not found 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.hpp(103,31): message : This diagnostic occurred in the compiler generated function 'iox::units::Duration iox::units::Duration::fromMilliseconds(const T) noexcept' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.inl(94,23): error C3861: '_s': identifier not found 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.hpp(111,31): message : This diagnostic occurred in the compiler generated function 'iox::units::Duration iox::units::Duration::fromSeconds(const T) noexcept' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.inl(99,23): error C3861: '_m': identifier not found 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.hpp(119,31): message : This diagnostic occurred in the compiler generated function 'iox::units::Duration iox::units::Duration::fromMinutes(const T) noexcept' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.inl(104,23): error C3861: '_h': identifier not found 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.hpp(127,31): message : This diagnostic occurred in the compiler generated function 'iox::units::Duration iox::units::Duration::fromHours(const T) noexcept' 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.inl(109,23): error C3861: '_d': identifier not found 1>C:\src\thirdparty\vcpkg\installed\x64-windows-static\include\iceoryx_hoofs/internal/units/duration.hpp(135,31): message : This diagnostic occurred in the compiler generated function 'iox::units::Duration iox::units::Duration::fromDays(const T) noexcept'

attaching my fix for reference; duration.inl.zip

niclar commented 2 years ago

@elfenpiff can you build iceoryx/iceoryx_examples/singleprocess/single_process.cpp with that vs compiler ?

elfenpiff commented 2 years ago

@niclar I can compile it without any problem but the example just crashes.

I created an issue for that #1082

But when I switch to your commit hash, remove the complete build folder I can still build everything successfully - including the single_process.cpp example.

niclar commented 2 years ago

@elfenpiff that is very strange... let me do some more digging

elfenpiff commented 2 years ago

@niclar Thank you. I am not so familiar with the whole Windows C++ toolchain so if you have some hints for I would be thankful.

I just started this example in vscode with the "cppvsdbg" and this states that in single_process.cpp:112 an exception is thrown, which is the beginning of main?!

But I have an idea what caused this, the stack size it should be 8Mb but the default on windows is 1Mb

niclar commented 2 years ago

@elfenpiff no worries. -Did you set c++20 generation in vs? I.e under "C++ Language Standard" set it to "Preview - Features from the Latest C++ Working Draft (/std:c++latest)"

elfenpiff commented 2 years ago

@niclar I fixed that issue at least. If you add -DCMAKE_CXX_STACK_SIZE=8000000 to the cmake generation command the default stack size is increased to 8Mb on windows and the crash of singleprocess is fixed.

niclar commented 2 years ago

@elfenpiff does iceoryx require a large stack space in general ?

elfenpiff commented 2 years ago

@niclar We do not use the heap since this is not allowed in the safety critical environment nevertheless iceoryx requires around ~2Mb of stack size which shouldn't pose a problem.

The main use case of windows are not safety critical applications so normally most applications use the heap and have therefore a decreased stack size.

But on Windows/Linux/Mac one can set the required stack size of an application during link time so we set this for every platform uniformly to 8Mb (default of linux) and we should never encounter this problem again.

elfenpiff commented 2 years ago

@niclar with /std:c++latest I am drowning in compiler errors right from the first file:

  file.cpp
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,52
): error C2760: syntax error: '&' was unexpected here; expected 'expression' [C:\Users\me\Development\iceoryx\build\hoo
fs\platform\iceoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,52
): error C2187: syntax error: '&' was unexpected here [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_pla
tform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,1)
: error C2059: syntax error: '>' [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,63
): error C2988: unrecognizable template declaration/definition [C:\Users\me\Development\iceoryx\build\hoofs\platform\ic
eoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,63
): error C2059: syntax error: '>' [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(52,1)
: error C2143: syntax error: missing ';' before '{' [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_platf
orm.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(52,1)
: error C2447: '{': missing function header (old-style formal list?) [C:\Users\me\Development\iceoryx\build\hoofs\platf
orm\iceoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\source\file.cpp(25,9): error C3861: '__Win32Call': identifie
r not found [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_platform.vcxproj]
  fnctl.cpp
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,52
): error C2760: syntax error: '&' was unexpected here; expected 'expression' [C:\Users\me\Development\iceoryx\build\hoo
fs\platform\iceoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,52
): error C2187: syntax error: '&' was unexpected here [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_pla
tform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,1)
: error C2059: syntax error: '>' [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,63
): error C2988: unrecognizable template declaration/definition [C:\Users\me\Development\iceoryx\build\hoofs\platform\ic
eoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(51,63
): error C2059: syntax error: '>' [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(52,1)
: error C2143: syntax error: missing ';' before '{' [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_platf
orm.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\include\iceoryx_hoofs/platform/win32_errorHandling.hpp(52,1)
: error C2447: '{': missing function header (old-style formal list?) [C:\Users\me\Development\iceoryx\build\hoofs\platf
orm\iceoryx_platform.vcxproj]
C:\Users\me\Development\iceoryx\iceoryx_hoofs\platform\win\source\fnctl.cpp(23,1): error C3861: '__Win32Call': identifi
er not found [C:\Users\me\Development\iceoryx\build\hoofs\platform\iceoryx_platform.vcxproj]
  getopt.cpp
niclar commented 2 years ago

@elfenpiff . Yeah that's it. You are getting that std::result_of_t error (https://github.com/eclipse-iceoryx/iceoryx/issues/1076 is not completed just yet - commented on that ticket) , ...ignore it by defining _HAS_DEPRECATED_RESULT_OF.

elfenpiff commented 2 years ago

@niclar Finally, I finally could reproduce your issue and found several new ones too (lucky me). But with #1085 the result_of should be gone once and for all, the duration is fixed and some other minor things.

niclar commented 2 years ago

thanks for fixing this