c++windowssgxenclave

Error Loading Enclave: Couldn't open file with CreateFile()


I'm trying to write a simple SGX project for a start. So I have this main host application routine that I've pretty much copied from Lars Richter's blog:

#define ENCLAVE_FILE _T("Enclave.signed.dll")
#include <tchar.h>
#include <cstdio>
#include "sgx_urts.h"
#include "Enclave_u.h"

int main()
{
    sgx_enclave_id_t   eid;
    sgx_status_t       ret = SGX_SUCCESS;
    sgx_launch_token_t token = { 0 };
    int updated = 0;

    ret = sgx_create_enclave(ENCLAVE_FILE, SGX_DEBUG_FLAG, &token, &updated, &eid, NULL);

    if (ret != SGX_SUCCESS) {
        printf("\nApp: error %#x, failed to create enclave.\n", ret);
    }


    scanf("\n");

    return 0;
}

It compiles fine (I'm using the Intel C++ 17.0 compiler with Visual Studio 2015) but it doesn't load the enclave. I get the following error message:

[sgx_create_enclavew ..\urts\win\urts.cpp:195] Couldn't open file with CreateFile()

App: error 0x200f, failed to create enclave.

Solution

  • Go to app_test_save project setting. Under Debugging, change working directory to $(SolutionDir)Debug. This answer assumes that both projects app_test_save and enclave_test_save belong to the same solution.