Closed
Description
Hi,
I'm typically working on open-ocpp using my Linux laptop and haven't encountered any issues during compilation. However, I recently tried building the project on my M1 MacBook and ran into some compilation errors using Clang.
Here is the relevant portion of the output:
Starting clang build...
...
[ 52%] Built target config
In file included from /Users/thomasbrunel/Documents/Perso/open-ocpp/src/tools/json/JsonValidator.cpp:19:
/Users/thomasbrunel/Documents/Perso/open-ocpp/src/tools/json/JsonValidator.h:54:17: error: implicit instantiation of undefined template 'std::basic_string<char>'
54 | std::string m_last_error;
| ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include/c++/v1/__fwd/string.h:43:28: note: template is declared here
43 | class _LIBCPP_TEMPLATE_VIS basic_string;
| ^
1 error generated.
make[3]: *** [src/tools/json/CMakeFiles/json.dir/JsonValidator.cpp.o] Error 1
make[2]: *** [src/tools/json/CMakeFiles/json.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
/Users/thomasbrunel/Documents/Perso/open-ocpp/src/websockets/libwebsockets/LibWebsocketServer.cpp:318:26: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
318 | char uri[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/thomasbrunel/Documents/Perso/open-ocpp/src/websockets/libwebsockets/LibWebsocketServer.cpp:318:47: note: function parameter 'wsi' with unknown value cannot be used in a constant expression
318 | char uri[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
| ^
/Users/thomasbrunel/Documents/Perso/open-ocpp/src/websockets/libwebsockets/LibWebsocketServer.cpp:265:51: note: declared here
265 | int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len)
| ^
/Users/thomasbrunel/Documents/Perso/open-ocpp/src/websockets/libwebsockets/LibWebsocketServer.cpp:448:22: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
448 | char uri[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/thomasbrunel/Documents/Perso/open-ocpp/src/websockets/libwebsockets/LibWebsocketServer.cpp:448:43: note: function parameter 'wsi' with unknown value cannot be used in a constant expression
448 | char uri[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
| ^
/Users/thomasbrunel/Documents/Perso/open-ocpp/src/websockets/libwebsockets/LibWebsocketServer.cpp:265:51: note: declared here
265 | int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len)
| ^
2 errors generated.
make[3]: *** [src/websockets/CMakeFiles/ws.dir/libwebsockets/LibWebsocketServer.cpp.o] Error 1
make[2]: *** [src/websockets/CMakeFiles/ws.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [clang] Error 2
I’ve fixed these issues locally and verified that the build works correctly on both macOS (Clang) and Linux (GCC).
For completeness, I encountered two additional issues after resolving the ones above:
- The use of sprintf in the doctest library is flagged by Clang; it should be replaced with snprintf.
- A usage of WEXITSTATUS on the result of a system call directly (i.e., on a temporary value) causes an error.
Since doctest is a third-party library, I’m not planning to submit a PR for it unless you're open to vendor-side changes. As for the three other issues, I plan to open PRs for each of the errors.
Let me know how you'd like to proceed!
Thanks,
Thomas
Metadata
Metadata
Assignees
Labels
No labels