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

CMake: non-MSVC builds fail because MSVC CPUIDEX is used instead of x86 asm #492

Closed
scivision opened this issue Nov 1, 2021 · 1 comment · Fixed by #493
Closed

CMake: non-MSVC builds fail because MSVC CPUIDEX is used instead of x86 asm #492

scivision opened this issue Nov 1, 2021 · 1 comment · Fixed by #493

Comments

@scivision
Copy link
Contributor

scivision commented Nov 1, 2021

It does build with MSVC on same system.
I think this is a known issue, but just for tracking purposes:

What version of hwloc are you using?

2.6/current git default

Which operating system and hardware are you running on?

Windows 11

Details of the problem

With GCC or Clang or Intel oneAPI "icx", errors as in next section result from:

cmake -B build -S contrib/windows-cmake

cmake --build build

GCC / Clang

Error for GCC and Clang are nearly identical:

[14/66] Building C object CMakeFiles/hwloc-gather-cpuid.dir/utils/hwloc/hwloc-gather-cpuid.c.obj
In file included from utils/hwloc/hwloc-gather-cpuid.c:15:
contrib/windows-cmake/../../include/private/cpuid-x86.h:57:3: warning: implicit declaration of function '__cpuidex' is invalid in C99 [-Wimplicit-function-declaration]
  __cpuidex(regs, *eax, *ecx);
  ^
1 warning generated.
[50/66] Building C object CMakeFiles/libhwloc.dir/hwloc/topology-x86.c.obj
FAILED: CMakeFiles/libhwloc.dir/hwloc/topology-x86.c.obj
C:\msys64\mingw64\bin\clang.exe -D_CRT_SECURE_NO_WARNINGS -Icontrib/windows-cmake/../../include -Icontrib/windows-cmake/../../hwloc -Ibuild/include -O3 -DNDEBUG -MD -MT CMakeFiles/libhwloc.dir/hwloc/topology-x86.c.obj -MF CMakeFiles\libhwloc.dir\hwloc\topology-x86.c.obj.d -o CMakeFiles/libhwloc.dir/hwloc/topology-x86.c.obj -c hwloc/topology-x86.c
In file included from hwloc/topology-x86.c:25:
contrib/windows-cmake/../../include/private/cpuid-x86.h:57:3: warning: implicit declaration of function '__cpuidex' is invalid in C99 [-Wimplicit-function-declaration]
  __cpuidex(regs, *eax, *ecx);
  ^
hwloc/topology-x86.c:1704:3: error: use of undeclared identifier 'DIR'
  DIR *dir;
  ^
hwloc/topology-x86.c:1704:8: error: use of undeclared identifier 'dir'; did you mean 'div'?
  DIR *dir;
       ^~~
       div
C:/msys64/mingw64/x86_64-w64-mingw32/include/stdlib.h:446:17: note: 'div' declared here
  div_t __cdecl div(int _Numerator,int _Denominator);
                ^
hwloc/topology-x86.c:1709:3: error: use of undeclared identifier 'dir'
  dir = opendir(src_cpuiddump_path);
  ^
hwloc/topology-x86.c:1709:9: warning: implicit declaration of function 'opendir' is invalid in C99 [-Wimplicit-function-declaration]
  dir = opendir(src_cpuiddump_path);
        ^
hwloc/topology-x86.c:1710:8: error: use of undeclared identifier 'dir'; did you mean 'div'?
  if (!dir)
       ^~~
       div
C:/msys64/mingw64/x86_64-w64-mingw32/include/stdlib.h:446:17: note: 'div' declared here
  div_t __cdecl div(int _Numerator,int _Denominator);
                ^
hwloc/topology-x86.c:1710:8: warning: address of function 'div' will always evaluate to 'true' [-Wpointer-bool-conversion]
  if (!dir)
      ~^~~
hwloc/topology-x86.c:1710:8: note: prefix with the address-of operator to silence this warning
  if (!dir)
       ^
       &
hwloc/topology-x86.c:1734:20: warning: implicit declaration of function 'readdir' is invalid in C99 [-Wimplicit-function-declaration]
  while ((dirent = readdir(dir)) != NULL) {
                   ^
hwloc/topology-x86.c:1734:28: error: use of undeclared identifier 'dir'
  while ((dirent = readdir(dir)) != NULL) {
                           ^
hwloc/topology-x86.c:1735:24: error: incomplete definition of type 'struct dirent'
    if (!strncmp(dirent->d_name, "pu", 2)) {
                 ~~~~~~^
hwloc/topology-x86.c:1703:10: note: forward declaration of 'struct dirent'
  struct dirent *dirent;
         ^
hwloc/topology-x86.c:1737:41: error: incomplete definition of type 'struct dirent'
      unsigned long idx = strtoul(dirent->d_name+2, &end, 10);
                                  ~~~~~~^
hwloc/topology-x86.c:1703:10: note: forward declaration of 'struct dirent'
  struct dirent *dirent;
         ^
hwloc/topology-x86.c:1742:9: error: incomplete definition of type 'struct dirent'
                dirent->d_name, src_cpuiddump_path);
                ~~~~~~^
hwloc/topology-x86.c:1703:10: note: forward declaration of 'struct dirent'
  struct dirent *dirent;
         ^
hwloc/topology-x86.c:1745:3: warning: implicit declaration of function 'closedir' is invalid in C99 [-Wimplicit-function-declaration]
  closedir(dir);
  ^
hwloc/topology-x86.c:1745:12: error: use of undeclared identifier 'dir'; did you mean 'div'?
  closedir(dir);
           ^~~
           div
C:/msys64/mingw64/x86_64-w64-mingw32/include/stdlib.h:446:17: note: 'div' declared here
  div_t __cdecl div(int _Numerator,int _Denominator);
                ^
hwloc/topology-x86.c:1763:12: error: use of undeclared identifier 'dir'; did you mean 'div'?
  closedir(dir);
           ^~~
           div
C:/msys64/mingw64/x86_64-w64-mingw32/include/stdlib.h:446:17: note: 'div' declared here
  div_t __cdecl div(int _Numerator,int _Denominator);
                ^
5 warnings and 10 errors generated.
[53/66] Building C object CMakeFiles/libhwloc.dir/hwloc/topology-windows.c.obj
hwloc/topology-windows.c:1420:29: warning: incompatible pointer types passing 'unsigned int *' to parameter of type 'LPDWORD' (aka 'unsigned long *') [-Wincompatible-pointer-types]
  GetComputerName(hostname, &hostname_size);
                            ^~~~~~~~~~~~~~
C:/msys64/mingw64/x86_64-w64-mingw32/include/winbase.h:2677:71: note: passing argument to parameter 'nSize' here
  WINBASEAPI WINBOOL WINAPI GetComputerNameA (LPSTR lpBuffer, LPDWORD nSize);

Intel LLVM oneAPI

Intel oneAPI LLVM "icx" replaces the legacy "icl". Error at executable link like:

[56/66] Linking C executable hwloc-info.exe
FAILED: hwloc-info.exe
cmd.exe /C "cd . && C:\msys64\mingw64\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\hwloc-info.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100203~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100203~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin\intel64\xilink.exe /nologo CMakeFiles\hwloc-info.dir\C_\Users\micha\code_other\hwloc\utils\hwloc\hwloc-info.c.obj  /out:hwloc-info.exe /implib:hwloc-info.lib /pdb:hwloc-info.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  libhwloc.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin\intel64\xilink.exe /nologo CMakeFiles\hwloc-info.dir\C_\Users\micha\code_other\hwloc\utils\hwloc\hwloc-info.c.obj /out:hwloc-info.exe /implib:hwloc-info.lib /pdb:hwloc-info.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console libhwloc.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\hwloc-info.dir/intermediate.manifest CMakeFiles\hwloc-info.dir/manifest.res" failed (exit code 1120) with the following output:
libhwloc.lib(topology-x86.c.obj) : error LNK2019: unresolved external symbol __cpuidex referenced in function hwloc_x86_cpuid
hwloc-info.exe : fatal error LNK1120: 1 unresolved externals
@bgoglin
Copy link
Contributor

bgoglin commented Nov 2, 2021

Hello. The CMake support inherits its config from the MSVC solution, hence it assumes the compiler is MSVC instead of detecting things. That's why HWLOC_HAVE_MSVC_CPUIDEX is defined in contrib/windows/private_config.h and things fail here. You may try to #undef that line to see if the non-MSVC cpuid code works, and then we'll need some CMake stuff to enable disable it depending on the compiler.

@bgoglin bgoglin changed the title CMake: MSYS2/MinGW GCC,Clang (and Intel LLVM oneAPI) build error CMake: non-MSVC builds fail because MSVC CPUIDEX is used instead of x86 asm Nov 2, 2021
bgoglin added a commit that referenced this issue Nov 26, 2021
WIndows CMake: work with non-MSVC compilers too

This was tested with GCC, Clang, and Intel oneAPI on Windows.
Fixes #492

Adds numerous tests as in Autotools-based builds.

This is also the foundation for using CMake on any platform instead of autotools.

Avoids the constant full rebuilding by using configure_file() instead of explicit file()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants