adrianstone55 / SymbolSort

A Utility for Measuring C++ Code Bloat
http://gameangst.com/?p=320
Apache License 2.0
117 stars 17 forks source link

Build instructions don't seem to work #4

Closed randomascii closed 7 years ago

randomascii commented 7 years ago

I tried building SymbolSort, with VC++ 2015, and I couldn't get it to work. All possible ways of adding msdia140.dll as a reference seemed to have no effect. This may be due to my lack of recent experience with driving COM from C#.

However, with some poking around I found a method. I don't know if it is the one-true method or if I was doing something wrong previously. Here is what I found - I think it would be good to get this or something equivalent added to the instructions.

First, I needed to add a reference to msdia140.dll. I found some ideas here: http://stackoverflow.com/questions/697541/how-do-i-use-the-ms-dia-sdk-from-c

which I turned in to these steps:

"%VS140COMNTOOLS%....\VC\vcvarsall.bat" amd64 set DIASDK=%VS140COMNTOOLS%....\DIA SDK midl /I "%DIASDK%\include" "%DIASDK%\idl\dia2.idl" /tlb dia2.tlb tlbimp dia2.tlb

This created dia2lib.dll which I added as a reference. I did this by right-clicking on References, selecting Add Reference, clicking Browse, finding the file, then clicking okay.

Building then gave these two errors:

1>SymbolSort.cs(1164,7,1164,21): error CS1752: Interop type 'DiaSourceClass' cannot be embedded. Use the applicable interface instead. 1>SymbolSort.cs(1164,38,1164,52): error CS1752: Interop type 'DiaSourceClass' cannot be embedded. Use the applicable interface instead.

After some quick research I found this article http://stackoverflow.com/questions/2483659/interop-type-cannot-be-embedded which told me to select dia2lib from the references in the project, view properties, and change Embed Interop Types to False. This worked.

So, this worked for me. Maybe some combination of a batch file and solution/project file could be added to simplify this process? I'm not sure. Mostly I wanted to get my instructions/observations up here so I don't have to figure this out again.

adrianstone55 commented 7 years ago

Here are my minimal instructions for creating a project for SymbolSort with VS2015.

  1. Create a new C# Console Application using File->New Project.
  2. Replace the default Program.cs with SymbolSort.cs
  3. Right-click the "References" node in the Solution explorer and "Add References..."
  4. In the Reference Manager dialog click the "Browse..." button and select your msdia dll. For example C:\Program Files (x86)\Microsoft Visual Studio 14.0\DIA SDK\bin\amd64\msdia140.dll
  5. Either select Dia2Lib under references and change the "Embed Interop Types" to False or go to project properties and change the "Target framework" to 3.5.
randomascii commented 7 years ago

Yep, those are the steps I saw and followed. After browsing to that exact DLL and clicking OK I get:

A reference to 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\DIA SDK\bin\amd64\msdia140.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

I have a pretty standard install of VS 2015 Professional on Windows 10, FWIW.

adrianstone55 commented 7 years ago

It is possible the DLL has to be registered. I honestly have no idea. Try running regsvr32 "C:\Program Files (x86)\Microsoft Visual Studio 14.0\DIA SDK\bin\amd64\msdia140.dll" from an elevated command prompt before attempting to add the DLL as a reference in Visual Studio.

randomascii commented 7 years ago

Yep, that's all it was. Thanks Microsoft!

It seems passing strange to me that my C++ programs can use DIA2 without difficulty, but my C# program can't even build. Maybe it's a matter of a different DLL being registered, but if that's the case then why did nothing show up in the list of available COM objects. It all seems rather broken.

But, nothing that can't be fixed with documentation. Pull request to follow...

adrianstone55 commented 7 years ago

If only the writers of error messages cared as much about them as the readers.