Skip to content

GUIDE | How to Compile

ChthonVII edited this page Dec 11, 2020 · 1 revision

There are a bunch of guides on the web for compiling the C&C Remastered dll's, but I've yet to see one that's both correct and complete. So here we go:

Download:

Download Visual Studio 2019 Community

Download Windows 8.1 SDK (top page)

Install:

Install Visual Studio 2019 Community with the following components:

  • Desktop Development with C++
  • MSVC v141 – VS 2017 C++ x64/x86 build tools
  • C++ ATL for v141 build tools (x86 & x64)
  • C++ MFC for v141 build tools (x64 & x64)
  • Windows Universal CRT SDK (Without this you will get "Cannot open include file: 'ctype.h': No such file or directory" when you try to compile.)

Install Windows 8.1 SDK (You can uncheck other components besides the SDK itself).

Build

  • Open the CnCRemastered.sln file with Visual Studio.
  • If Visual Studio prompts to retarget the Windows SDK and VC++ versions, then say NO. You have nothing to gain by retargeting, and it will cause headaches.
  • Right-click the TiberianDawn or RedAlert project. If you've previously compiled this project, select "clean," then "build." Otherwise just "build."

Troubleshooting

  • Visual Studio install fails -- Disable antivirus and firewall software, then try again with run as admin.

  • Visual Studio can't find its own binaries to do the compile -- Add msbuild location to your path (default is %PROGRAMFILES(X86)%\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin)

  • COM error when trying to open the solution/project -- run the following as admin:

    regsvr32 %SystemRoot%\System32\msxml3.dll

    regsvr32 %SystemRoot%\SysWOW64\msxml3.dll

  • You retargeted to VC++ 2019 and Windows 10 SDK, even though I told you not too, and now you've got a compile error.

    • The proper solution is to change back to VC++ 2017 and Windows 8.1 SDK.
    • If you insist on retargeting, defining WINDOWS_IGNORE_PACKING_MISMATCH in the preprocessor definitions should make things work.
    • Some guides suggest instead change the struct member alignment to "default." Do not do this; it will cause crash bugs.
    • To better explain what's going on here: The first C&C was released in 1995, when a high-end PC had 64 megabytes of RAM, and an average PC had 4 or 8. Accordingly, Westwood packed their structs with 1-byte alignment. This was space efficient (no bytes wasted for padding), and time inefficient (to access a struct member the CPU has to spend extra cycles shifting and masking and possibly make two reads/writes if it straddled a word boundry), and the only sane choice for that era's hardware. Flash forward to today, RAM is much more plentiful (I've got 64 gigabytes!) and the Windows 10 SDK has been redesigned so that internally it always uses and expects 8-byte struct alignment, and will poop a compile error if you try to use any other alignment. You've got three options for dealing with this: (1) The correct solution, again, is to use the Windows 8.1 SDK. This guarantees you'll get the same struct packing Petroglyph got, and you can just stop worrying about struct packing issues. (2) You can set WINDOWS_IGNORE_PACKING_MISMATCH, which just ignores the error and packs your structs with the 1-byte alignment set in your .vcxproj files. This is OK so long as none of your structs ever interact with those SDK functions that expect 8-byte alignment. If that happens, you'll get memory corruption and probably crash. Fortunately, it looks like this doesn't occur anywhere in the dll code Petroglyph released. (3) You can change the struct member alignment in your project file to "default," which means "8-byte alignment." This makes Windows 10 SDK happy, but it means your structs won't get packed the way Westwood intended. At minimum, this would cause save-game incompatibility. Unfortunately, however, user experience suggests that there are functions in the C&C code (or possibly the remastered client) that expect 1-byte alignment, so you'll end up with memory corruption and crashes. So don't do this. See generally The Lost Art of Structure Packing and Microsoft's explanation of struct packing in Visual Studio.
Clone this wiki locally