Search code examples
powershellgccmsys2dev-null

Portable check for library


A project I am trying to compile has this command:

cc -xc++ -o/dev/null -lc++ -shared

However I am using PowerShell, which has no notion of /dev/null:

PS C:\> cc -xc++ -o/dev/null -lc++ -shared
C:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../
x86_64-w64-mingw32/bin/ld.exe: cannot open output file /dev/null.exe: No such
file or directory

I tried using -o$null, but it just creates a file $null.exe. I also tried this:

PS C:\> cc -xc++ -o $null -lc++ -shared
cc.exe: fatal error: no input files

Is PowerShell able to handle this use case? Alternatively, it seems the purpose of the test is to just check if libc++ exists. Is another way available to do that?


Solution

  • It appears the issue is specific to GCC. If I get Clang, the same command works with nul:

    cc -xc++ -onul -lc++ -shared
    

    but if I try the same thing with GCC, I get this:

    C:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../
    x86_64-w64-mingw32/bin/ld.exe: nul.exe: final close failed: file truncated
    

    I have posted bug 97574.