Visual Studio linker download

Windows specific forum
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Visual Studio linker download

Post 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()
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Visual Studio linker download

Post by skywalk »

Well done! Thanks for this utility. 8)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Visual Studio linker download

Post by Fred »

Warning about the license if you are doing commercial programs with it, even MSBuild needs a visual studio professional edition license.
Last edited by Fred on Wed Apr 24, 2024 5:40 pm, edited 1 time in total.
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Visual Studio linker download

Post 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:
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Visual Studio linker download

Post by jacdelad »

I downloaded the linker, but what do I do now?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Visual Studio linker download

Post 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.
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Visual Studio linker download

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Visual Studio linker download

Post 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.
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Visual Studio linker download

Post by Quin »

Ah, I knew not having coffee would bite me today :oops:
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Visual Studio linker download

Post 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.
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Visual Studio linker download

Post 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 ?
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Visual Studio linker download

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Visual Studio linker download

Post by skywalk »

The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Visual Studio linker download

Post 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
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Visual Studio linker download

Post by chi »

@Fred: Why don't you use LLVM instead? It's open source and both clang and lld-link work great with PB.
Et cetera is my worst enemy
Post Reply