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

Linux 下cmake编译工程出现 "major" is defined冲突?如何解决? #338

Open
JUMP-ZYX opened this issue Jul 17, 2024 · 2 comments

Comments

@JUMP-ZYX
Copy link

[build] /home/MicroOcpp/./src/MicroOcpp/Version.h:30:13: warning: In the GNU C Library, "major" is defined
[build] by <sys/sysmacros.h>. For historical compatibility, it is
[build] currently defined by <sys/types.h> as well, but we plan to
[build] remove this soon. To use "major", include <sys/sysmacros.h>
[build] directly. If you did not intend to use a system-defined macro
[build] "major", you should undefine it after including <sys/types.h>.
[build] ProtocolVersion(int major = 1, int minor = 6, int patch = 0) : major(major), minor(minor), patch(patch) { }

‘const int MicroOcpp::ProtocolVersion::minor’ should be initialized

出错代码
/*

  • OCPP version type, defined in Model
    */
    struct ProtocolVersion {
    const int major, minor, patch;
    ProtocolVersion(int major = 1, int minor = 6, int patch = 0) : major(major), minor(minor), patch(patch) { }
    };

}

@ryanchang419
Copy link

Me same ! do you solve this problem ?

@nithinmanne
Copy link

I was able to get the code to build by making the following change in Version.h. But I'm not sure what the cause is, or why this change fixes it.

Add this before definition of struct ProtocolVersion.

#ifdef major
#undef major
#endif

#ifdef minor
#undef minor
#endif

Git Patch:

diff --git a/src/MicroOcpp/Version.h b/src/MicroOcpp/Version.h
index 92a2ea4..a61fa19 100644
--- a/src/MicroOcpp/Version.h
+++ b/src/MicroOcpp/Version.h
@@ -22,6 +22,14 @@
 
 namespace MicroOcpp {
 
+#ifdef major
+#undef major
+#endif
+
+#ifdef minor
+#undef minor
+#endif
+
 /*
  * OCPP version type, defined in Model
  */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants