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

Can't build with clang compiler #190

Closed
Pichas opened this issue Jan 18, 2025 · 2 comments
Closed

Can't build with clang compiler #190

Pichas opened this issue Jan 18, 2025 · 2 comments

Comments

@Pichas
Copy link

Pichas commented Jan 18, 2025

Hello. I'm trying to build your library with clang and have warning and error.

Warning:

src\fastpbkdf2.c:30:9: warning: redefining builtin macro [-Wbuiltin-macro-redefined]
[build]    30 | #define _Pragma __pragma

Errors

[build] src\aegis\common\cpu.c:150:44: error: too few arguments provided to function-like macro invocation
[build]   150 |     __cpuid((int *) cpu_info, cpu_info_type);
[build] C:\Program Files\LLVM\lib\clang\19\include\cpuid.h:269:9: note: macro '__cpuid' defined here
[build]   269 | #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) 

[build] src\aegis\common\cpu.c:150:5: error: builtin functions must be directly called
[build]   150 |     __cpuid((int *) cpu_info, cpu_info_type);

Proposed solutions:

for warning: add a guard

+ #ifndef _Pragma
#define _Pragma __pragma
+ #endif

for error: disambiguate function call by using round brackets

- __cpuid((int *) cpu_info, cpu_info_type);
+ (__cpuid)((int *) cpu_info, cpu_info_type);

or use pragma push/pop

+ #pragma push_macro("__cpuid")
+ #undef __cpuid
    __cpuid((int*)cpu_info, cpu_info_type);
+ #pragma pop_macro("__cpuid")
@utelle
Copy link
Owner

utelle commented Jan 18, 2025

Both problems result from clang pretending to be MSVC compatible by defining the macro _MSC_VER, but actually not being compatible.

IMHO a preferred solution would be to check explicitly for clang without any trickery in the _MSC_VER code branches.

In the error case it is a problem in the libaegis code which should be fixed in the upstream repo as well.

utelle added a commit that referenced this issue Jan 19, 2025
Compiling with clang on Windows results in a warning and an error.

- eliminate warning in fastpbkdf2.c by excluding macro definitions for clang
- eliminate error in aegis/common/cpu.c by enclosing function name in parentheses
@utelle
Copy link
Owner

utelle commented Jan 19, 2025

In commit 03e0414 the code is changed to avoid the warning and the error.

For now I used the solution with the parentheses around the function name:

- __cpuid((int *) cpu_info, cpu_info_type);
+ (__cpuid)((int *) cpu_info, cpu_info_type);

This may change if the author of libaegis decides otherwise.

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

2 participants