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

Build of tests fails with ClangCl 15.0.0 compiler frontend for Visual Studio (Windows build) #546

Closed
emmenlau opened this issue Sep 16, 2022 · 4 comments

Comments

@emmenlau
Copy link

emmenlau commented Sep 16, 2022

What version of hwloc are you using?

I'm using hwloc 2.8.0 compiled from upstream sources (this official github repo).

Which operating system and hardware are you running on?

Compiling on Microsoft Windows 11 with the ClangCl x64 compiler frontend from LLVM 15.0.0 with Visual Studio 17.3.3 (current latest). The build uses the contributed cmake file. I'm using cmake 3.24.2 (current latest).

Details of the problem

The build of the tests fails on ClangCl, with the following problem:

FAILED: tests/hwloc/CMakeFiles/hwloc_backends.dir/hwloc_backends.c.obj
C:\BDA\ci\LLVM-15.0.0\bin\clang-cl.exe   -DHWLOC_DEBUG=1 -IC:\BDA\Src\hwloc\contrib\windows-cmake\..\..\include -IC:\data\usr-tmp-C10Sk32c193331629c1500\Debug\hwloc\include /D_ITERATOR_DEBUG_LEVEL=0     /DWINVER=0x0A00 /D_WIN32_WINNT=0x0A00 /DDEBUG     /D_CRT_SECURE_NO_DEPRECATE /D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS  -march=skylake /MDd /Z7  /DWIN32 /D_WINDOWS /Zi /Ob0 /Od /RTC1 -MDd /showIncludes /Fotests\hwloc\CMakeFiles\hwloc_backends.dir\hwloc_backends.c.obj /Fdtests\hwloc\CMakeFiles\hwloc_backends.dir\ -c -- C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c
C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c(25,3): error: call to undeclared function 'mktemp'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  mktemp(name);
  ^
C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c(25,3): note: did you mean 'mkstemp'?
C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c(23,19): note: 'mkstemp' declared here
static inline int mkstemp(char *name)
                  ^
C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c(26,10): error: call to undeclared function 'open'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  return open(name, O_RDWR|O_CREAT, S_IRWXU);
         ^
C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c(26,10): note: did you mean 'fopen'?
C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\stdio.h(213,28): note: 'fopen' declared here
    _ACRTIMP FILE* __cdecl fopen(
                           ^
C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c(184,5): warning: 'unlink' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _unlink. See online help for details. [-Wdeprecated-declarations]
    unlink(xmlfile);
    ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\stdio.h(385,9): note: 'unlink' has been explicitly marked deprecated here
        _CRT_NONSTDC_DEPRECATE(_unlink)
        ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\corecrt.h(428,50): note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
        #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT(             \
                                                 ^
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\vcruntime.h(345,47): note: expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
                                              ^
C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c(185,5): error: call to undeclared function 'close'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    close(xmlfilefd);
    ^
C:\BDA\Src\hwloc\tests\hwloc\hwloc_backends.c(185,5): note: did you mean 'fclose'?
C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\stdio.h(152,26): note: 'fclose' declared here
    _ACRTIMP int __cdecl fclose(
                         ^
1 warning and 3 errors generated.

It looks as if LLVM deprecated those methods, or maybe just an include is missing? But I could not quickly find which include that may be. Microsoft recommends using the methods with underscore (like _open) instead, so maybe that could help?

@bgoglin
Copy link
Contributor

bgoglin commented Sep 16, 2022

Hello
We already use _open in some cases but it's hard to understand when to enable this or not. pci-common.c has this that we could duplicate in hwloc_backends.c and should work in your case:

#if defined(HWLOC_WIN_SYS) && !defined(__CYGWIN__)
#include <io.h>
#define open _open
#define read _read
#define close _close

I don't know about mktemp() yet, but there's a _mktemp as well. Maybe this #if code and add mktemp->_mktemp?

@emmenlau
Copy link
Author

Yes, this sounds very reasonable. I have to admit that I'm also not too deep into POSIX and related methods, so it's very well possible that there would be other alternatives. But what you propose there should work with Visual Studio with or without ClangCl frontend, so it would certainly solve my problem.

@bgoglin
Copy link
Contributor

bgoglin commented Sep 19, 2022

At least it doesn't break our CI. Can you try the patch at bgoglin@0de22a5 or or a tarball from https://ci.inria.fr/hwloc/view/all/job/bgoglin/491/ ?

@emmenlau
Copy link
Author

Awesome, yes this resolves the build issue! Thanks a lot!

bgoglin added a commit that referenced this issue Oct 7, 2022
hwloc_backends.c needs some open/read/close/mktemp redirection
to _foo. Copy what we did in pci-common.c and add mktemp.

Thanks to Mario Emmenlauer for the report.

Fixes #546

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
(cherry picked from commit 0de22a5)
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