Page 1 of 3

Visual Studio linker download

Posted: Wed Apr 24, 2024 1:34 pm
by fryquez
As the Visual Studio linker can't be redistributed, here is a download solution.
Copy the respected vc folder into Compilers directory of your PureBasic 6.10 installation.

Code: Select all

EnableExplicit

UseZipPacker()

Procedure UnPackDelete(sVSIX.s, sOut.s)
  
  Protected sPattern.s = "*/cvtres.exe;*/link.exe;*/mspdb140.dll;*/mspdbcore.dll;*/msvcp140.dll" +
                    ";*/msvcp140_atomic_wait.dll;*/pgodb140.dll;*/tbbmalloc.dll" +
                    ";*/vcruntime140.dll;*/vcruntime140_1.dll;*/mspdbcore.dll"
    
  Protected iCount, hPack = OpenPack(#PB_Any, sVSIX)
  If hPack
    If ExaminePack(hPack)
      While NextPackEntry(hPack)        
        If PathMatchSpec_(PackEntryName(hPack), @sPattern)
          If UncompressPackFile(hPack, sOut + GetFilePart(PackEntryName(hPack)), PackEntryName(hPack)) <> -1
            iCount + 1
          EndIf
        EndIf
      Wend
    EndIf
    ClosePack(hPack)
  EndIf
  
  DeleteFile(sVSIX)
  
  ProcedureReturn iCount
  
EndProcedure

Procedure DownLoad_VcLinker(sDir.s = "")
  
  Protected sTempDir.s = GetTemporaryDirectory()
  
  If sDir = ""
    Protected sDesktop.s = Space(#MAX_PATH), pidl
    If SHGetSpecialFolderLocation_ (0, #CSIDL_DESKTOP, @pidl) = #NOERROR
      SHGetPathFromIDList_(pidl, @sDesktop)
      CoTaskMemFree_(pidl)
      sDir = sDesktop
    EndIf    
  EndIf
  
  If Right(sDir, 1) <> "\" : sDir + "\" : EndIf
  
  sDir + "VC_Linker\"
  Protected sOut_64.s, sOut_86.s, iCount
  sOut_64 = sDir + "x64\vc\" 
  sOut_86 = sDir + "x86\vc\"
  SHCreateDirectory_(0, @sOut_64)
  SHCreateDirectory_(0, @sOut_86)
  
  Debug "Loading 1 / 4"
  ReceiveHTTPFile("https://download.visualstudio.microsoft.com/" +
                  "download/pr/76697fd9-5c84-4e10-9209-374cb27a9f53/" +
                  "e35eb4be1c72d8419f5a1fa7d59e11a5aecfc4b96e0e0e7e67b0aa59ad4b52b9/" + 
                  "Microsoft.VC.14.39.17.9.Tools.HostX64.TargetX64.base.vsix",
                  sTempDir + "Tools.HostX64.vsix")
  
  Debug "Loading 2 / 4"
  ReceiveHTTPFile("https://download.visualstudio.microsoft.com/" +
                  "download/pr/ec3eaa61-e46b-4bc9-8f37-6de6009fd3f6/" +
                  "1b928af049010451b5ec600fbaf873905b289c6936f3ccbbec4951d79b264e4d/" +
                  "Microsoft.VC.14.39.17.9.Premium.Tools.HostX64.TargetX64.base.vsix", 
                  sTempDir + "Premium.Tools.HostX64.vsix")
  
  Debug "Loading 3 / 4"
  ReceiveHTTPFile("https://download.visualstudio.microsoft.com/"+ 
                  "download/pr/76697fd9-5c84-4e10-9209-374cb27a9f53/" +
                  "1267083ebf94f6bf042385146161c65805517d137a3b065dc57b1148f6b7d99b/" +
                  "Microsoft.VC.14.39.17.9.Tools.HostX86.TargetX86.base.vsix",
                  sTempDir + "Tools.HostX86.vsix")
  
  Debug "Loading 4 / 4"
  ReceiveHTTPFile("https://download.visualstudio.microsoft.com/"+
                  "download/pr/ec3eaa61-e46b-4bc9-8f37-6de6009fd3f6/" +
                  "6b79e89351b89132c6be407357349f4cbcd8e717f16a46503c1a23b655e9fa62/" +
                  "Microsoft.VC.14.39.17.9.Premium.Tools.HostX86.TargetX86.base.vsix", 
                  sTempDir + "Premium.Tools.HostX86.vsix")
  
  iCount = UnPackDelete(sTempDir + "Tools.HostX64.vsix", sOut_64)
  iCount + UnPackDelete(sTempDir + "Premium.Tools.HostX64.vsix", sOut_64)
  
  iCount + UnPackDelete(sTempDir + "Tools.HostX86.vsix", sOut_86)
  iCount + UnPackDelete(sTempDir + "Premium.Tools.HostX86.vsix", sOut_86)
  
  Protected flags = #PB_MessageRequester_Error
  If iCount = 19
    flags = #PB_MessageRequester_Info
  EndIf
  MessageRequester("Download finished", Str(iCount) + " from 19 files received!", flags)
  ShellExecute_(0, 0, @sDir, 0, 0, #SW_SHOWDEFAULT)
  
EndProcedure

DownLoad_VcLinker()

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 4:25 pm
by skywalk
Well done! Thanks for this utility. 8)

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 4:41 pm
by Fred
Warning about the license if you are doing commercial programs with it, even MSBuild needs a visual studio professional edition license.

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 4:54 pm
by Quin
Thanks so much, this works like a charm! Now I can properly use this better linker. It truly is better, it shrank one of my executables from 5.7 to 5.0 MB, with about 4 MB of data inside the binary :o
Interestingly, though, the binary size is very close to no different when UPX-ing a PB program compiled with VC vs one compiled with GCC :idea:

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 5:14 pm
by jacdelad
I downloaded the linker, but what do I do now?

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 5:16 pm
by Quin
jacdelad wrote: Wed Apr 24, 2024 5:14 pm I downloaded the linker, but what do I do now?
fryquez wrote: Wed Apr 24, 2024 1:34 pm Copy the respected vc folder into Compilers directory of your PureBasic 6.10 installation.
After you copy it, PB will just start using it when you compile.

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 5:22 pm
by jacdelad
So, this replaces the original c-compiler with the new one? Sorry, if this question is dumb, but I don't do much outside PB, a bit Python, a bit Perl and outdated Delphi. Never touched all this c-things in any way.

Edit: I just realized there's already a vc-folder. I was looking at an old version of PB.

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 5:43 pm
by Fred
Quin wrote: Wed Apr 24, 2024 4:54 pm Thanks so much, this works like a charm! Now I can properly use this better linker. It truly is better, it shrank one of my executables from 5.7 to 5.0 MB, with about 4 MB of data inside the binary :o
Interestingly, though, the binary size is very close to no different when UPX-ing a PB program compiled with VC vs one compiled with GCC :idea:
It doesn't replace GCC but polink.

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 5:46 pm
by Quin
Ah, I knew not having coffee would bite me today :oops:

Re: Visual Studio linker download

Posted: Wed Apr 24, 2024 5:48 pm
by Quin
jacdelad wrote: Wed Apr 24, 2024 5:22 pm Edit: I just realized there's already a vc-folder. I was looking at an old version of PB.
That's because early versions of 6.10 shipped the VC linker directly instead of polink. Now it's optional, because as you can probably see the VC linker is hardly self-contained :(
Install PB in a fresh folder and Compilers\VC won't be there, add the folder this tool downloads.

Re: Visual Studio linker download

Posted: Thu Apr 25, 2024 3:25 pm
by ChrisR
Thanks a lot, the Visual Studio linker works perfectly and allows to obtain exes with a reduced size, intermediate between PB 6.04 and 6.10.
Too bad the license doesn't allow to integrate them into packages.
Isn't there a way to offer an option to download it during inno setup installation and install it if it's not already there ?

Re: Visual Studio linker download

Posted: Thu Apr 25, 2024 3:36 pm
by Fred
I'm also sorry we can't use this linker by default, but I won't offer an official way to install it as the user needs to be aware of the VS license if he wants to distribute its programs.

Re: Visual Studio linker download

Posted: Thu Apr 25, 2024 4:17 pm
by skywalk

Re: Visual Studio linker download

Posted: Thu Apr 25, 2024 4:25 pm
by Fred
From what I understand, Community Edition is OK to use by individual developer (not a company). I always suck at licenses understanding, so that's my 2cts

Re: Visual Studio linker download

Posted: Thu Apr 25, 2024 4:26 pm
by chi
@Fred: Why don't you use LLVM instead? It's open source and both clang and lld-link work great with PB.