alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization 📊🗾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.11k stars 313 forks source link

[compilation error] 'localtime_s' was not declared in this scope #282

Closed erusyd closed 1 year ago

erusyd commented 1 year ago

Bug category

Describe the bug Compile from the source, it complains: error: ‘localtime_s’ was not declared in this scope

Steps to Reproduce

# Your steps go here
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O2" -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF 
sudo cmake --build . --parallel 2 --config Release
sudo cmake --install .

Output /source/matplot/core/axis_type.cpp:260:21: error: ‘localtime_s’ was not declared in this scope; did you mean ‘localtime_r’? 260 | localtime_s(&buf, &now); | ^~~ | localtime_r make[2]: *** [source/matplot/CMakeFiles/matplot.dir/build.make:128: source/matplot/CMakeFiles/matplot.dir/core/axis_type.cpp.o] Error 1

```console # The output you got ```

Platform

Environment Details:

Additional context

IasonManolas commented 1 year ago

I face the same issue under Ubuntu 20.04 while compiling with clang 12. It seems as if the localtime_s is not portable see this for an explanation.

TheGreatRambler commented 1 year ago

Ah hmm this is my fault, sorry guys. A PR adding support for timestamps I added was merged with this bug

TheGreatRambler commented 1 year ago

Msvc actually errors, not warns, when you use localtime so I mistakenly believed I missed something...

mangoschorle commented 1 year ago

Same here OS: linux ubuntu OS Version: 22.04 Compiler: g++ Compiler version: 9.4.0

Menzoc commented 1 year ago

Hello Fellows,

I had the same issue. There is two localtime_s, one fromWindows Visual Studio extension and one from C standard library.

My compiler clearly understood that we are using Window ones so it doesn't compile.

For the time being I came back to a previous versions by the following command git reset --hard 8dbea7 I didn't find yet the way to change from Window.

To be honest, I'm a bit disappointed to see two function with the exact same name not compatible. However, it is clearly state in the description of the C Library:

The implementation of localtime_s in Microsoft CRT is incompatible with the C standard since it has reversed parameter order and returns errno_t.