0

I know next to nothing about C++, except that I have a missing to take someone else's C++ library and wrap it for use by C#. I found a few posts about how to do it, and I'm making my way there, bit by bit. But I've hit a wall at this point.

According to this post I'm supposed to create a new managed C++ project. This I have done, and I added a reference to the project I'm supposed to be wrapping. So my code looks like this:

#include "stdafx.h"
#include "DrmWrapper.h"
#include "../OtherLibrary/drm/adept/src/adept_provider.h"

DrmWrapper::DrmWrapper(dpdrm::DRMProcessorClient * client, dpdev::Device * device)
{
    adept::DRMProviderImpl * provider = new adept::DRMProviderImpl();
    drm_processor_ = provider->createDRMProcessor(client, device);
}

unsigned DrmWrapper::initSignInWorkflow(unsigned workflows, const dp::String& authProvider, const dp::String& username,
    const dp::String& password)
{
    return drm_processor_->initSignInWorkflow(workflows, authProvider, username, password);
}

All looks good. But when I try compile my wrapper project, I get an error:

d:\src\drm-wrapper\OtherLibrary\drm\adept\src\adept_provider.h(26): fatal error C1083: Cannot open include file: 'dp_all.h': No such file or directory

Eh...whut? I'm not trying to compile the adept library. That already built fine by itself. I just want to compile my own wrapper project. And the dp_all.h file does exist, in the same folder as adept_provider.h.

Clearly there's some paradigm shift I'm not making from C# to C++; it seems like the code is being rebuilt as if the referenced project's source file were in my project folder.

What's the secret switch to get this working?

Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
  • You should add `../OtherLibrary/drm/adept/src` as one of the places where your project looks for header files. And you should change `#include "../OtherLibrary/drm/adept/src/adept_provider.h"` to `#include "adept_provider.h"`. What's happening is that the compiler is looking for `dp_all.h` relative to your project not to the other project. Compilation is not totally separate in C++, headers files are shared between projects and are recompiled in each project where they are used. – john Sep 05 '18 at 09:57
  • @john Is that in the Property Pages, "Additional #using directories"? I've added it there, but it gives me a compiler error if I just do `#include "adept_provider.h"`: `No such file or directory` – Shaul Behr Sep 05 '18 at 10:08
  • No, I don't have a copy of Visual Studio handy right now, but it's something like C++/General/Additional Include Directories – john Sep 05 '18 at 10:10
  • I've just checked Project/Properties/Configuration Properties/C++/General/Additional Include Directories, just above Additional #using Directories as it happens. – john Sep 05 '18 at 10:15
  • @john Yep, that's it. Thanks! Please convert your comments into an answer I can accept. – Shaul Behr Sep 05 '18 at 10:16

1 Answers1

2

You should add ../OtherLibrary/drm/adept/src as one of the places where your project looks for header files (in C++/General/Additional Include Directories).

You should change #include "../OtherLibrary/drm/adept/src/adept_provider.h" to #include "adept_provider.h".

What's happening is that the compiler is looking for dp_all.h relative to your project not to the other project. Compilation is not totally separate in C++, headers files are shared between projects and are recompiled in each project where they are used.

john
  • 85,011
  • 4
  • 57
  • 81