msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.24k stars 1.21k forks source link

Any luck with create_symlink or create_directory_symlink on Windows 11? #10644

Open rimmartin opened 2 years ago

rimmartin commented 2 years ago

Been attempting to use "g++.exe (Rev5, Built by MSYS2 project) 11.2.0" to build a program using https://en.cppreference.com/w/cpp/filesystem/create_symlink and create_directory_symlink. Anyone use these successfully? I can get powershell 7 commands to make a symlink

New-Item -Path cpp_modules/zlib -ItemType SymbolicLink -Target $Env:UserProfile/.cnpm/cpp_modules/zlib

I've set developer mode for a try. Installed gpedit.msc and set the Computer Configuration → Windows Settings → Security Settings → Local Policies → User Rights Assignment → Create symbolic links

for user and admin.

But the program continues to hit

filesystem error: cannot create directory symlink: Unknown error [c:/Users/Roger\.cnpm\cpp_modules\brigand] [.\cpp_modules\brigand]

also tried the code example at https://en.cppreference.com/w/cpp/filesystem/create_symlink

What windows policy could be blocking?

I've set -DSYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE=2 for compiles to see if it has a good effect but nada.

rimmartin commented 2 years ago

Currently calling the winbase CreateSymbolicLinkW makes the symlink but create_directory_symlink doesn't. SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE is set to 0x02

#ifdef __WIN32__
                    CreateSymbolicLinkW(localLinkPath.c_str(), localPath.c_str(), SYMBOLIC_LINK_FLAG_DIRECTORY|SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE);
#else
                    try{
                        std::filesystem::create_directory_symlink(localPath, localLinkPath);
                    }
                    catch(std::filesystem::filesystem_error& ex){
                        std::throw_with_nested( std::runtime_error("Couldn't create symbolic link " + localLinkPath.string()) );
                    }
#endif

Cloned gcc and will look deeper