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

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.

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.

As Neil pointed out, sgx_create_enclave couldn't find the dll when the program was being run from within Visual Studio's debugger. It worked fine when I directly ran the executable in the "Debug" folder.
So a simple trick to make it work in both settings is to do the following:
#define ENCLAVE_FILE _T("../Debug/Enclave.signed.dll")

According to this : https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/623738
If you are using the Local SGX Debugger, Please make sure change the "current working directory" pointing to $(OutDir) instead of $(ProjectDir).
Configuration Properties --> Debugging --> Working Directory --> $(OutDir).

Error is basically means it could not locate your .dll file.
Do dir /a/s to find Enclave.signed.dll then change the name appropriately.
When you create enclave it will generate signed.dll file. If your enclave name is Enclave12 then the DLL name is Enclave12.signed.dll. You fix this then you should be good to go.

Related

opencv_world341d.dll was not found error

I am trying to run OpenCV on Visual Studios 2017. I built the libraries and bin with CMake, so far it is working good. However, when I try to run the code it says this:
This is the error code message that shows when I launch the "local windows debugger":
For some reason, it says that it can't find the DLL. I already assign the Aditional Dependencies in properties also I linked the "Included Directories" and "Included Libraries" to openCV in Visual Studios, the project is set to run in x64, and there are no errors on the programming it's just that error of DLL that shows.
The DLL can be found in a separate folder made by the compiler in a bin folder. However, it still says it can't be found.
This is the locations of the DLL files:
Is there a solution for this?
I tried to add pictures I'm new in the forum it doesn't let me post them yet. I am not sure if the ones I upload will show.
This is the code I tried to run and bring the error message. The same happen with any other code.
I will add more images that may help to understand what I did so far and thanks in advance for the help.
This are the Visual Studios C/C++ Directories:
This is the Linked section in Visual Studios properties:
This is the environment PATH from Environment Variables:
This is all I did so far in the process to install OpenCV in Visual Studios.
#include "stdafx.h"
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
int main() {
cv::Mat image;
std::cout << "This image is" << image.rows << "X" << image.cols << std::endl;
image = cv::imread("puppy.bmp");
if (image.empty()) {
}
cv::Mat result;
cv::flip(image, result, 1);
cv::waitKey(0);
return 0;
}
For me, restart to Visual Studio solved the problem, I guess that's because when I added the OpenCV to Environment Variable the Visual Studio was open
Just copy opencv_world341d.dll to the x64 debug folder, and run it.
I also restart my computer after I add it to PATH. So the solution is just restart your computer when you add to PATH for the first time
I've also faced this issue and solved it simply by adding the OpenCV bin path to the environment variable.

Struggling with libssh on Windows

The problem
I'm trying to build a project in Visual Studio 2015 on Win10 that makes use of libssh, but I'm having no luck getting it to work. I feel like I'm losing my mind here. I'm either completely blanking out or missing something incredibly obvious.
I've tried using the installer libssh-0.7.2-msvc.exe from the files section at https://red.libssh.org/projects/libssh/files. I then linked it to a test C++ project in VS2015. Using the sample code I'm able to compile it:
#include <iostream>
#define LIBSSH_STATIC
#include <libssh/libssh.h>
int main() {
std::cout << "Starting libssh test" << std::endl;
ssh_session my_ssh_session = ssh_new();
if (my_ssh_session == NULL) {
std::cout << "Failed to initialize" << std::endl;
}
ssh_free(my_ssh_session);
return 0;
}
(Note: I've tried both #define LIBSSH_STATIC and #define LIBSSH_STATIC 1 based on posts I've seen from my initial search for answers. I've even tried adding it to the preprocessor definitions in project properties.)
I can only compile it if my project is set to 32-bit, but I can't run the resulting executable. Doing so results in an error: "The code execution cannot proceed because ssh.dll was not found. Reinstalling the program may fix this problem." I'm statically linking ssh.lib, though, so I'm not sure why I'm even getting that error.
So I tried compiling libssh myself as 64-bit. It took some more tinkering than I expected (I had some issues with zlib, which eventually I just omitted since it's optional). I can compile my project as a 64-bit executable successfully, but once again, I can't actually run it. I get the same error about ssh.dll being missing.
For the sake of trying it, I removed the LIBSSH_STATIC define and tried to link just to the DLL. Copying the ssh.dll from the libssh distribution into my program folder and trying to run it, I get the error: "The application was unable to start correctly (0xc000007b). Click OK to close the application."
I'm not sure what I'm missing here, but I'm sure it's dumb and I'm overthinking it.
Project settings (all configurations, all platforms)
libssh is installed to G:\Libraries\libssh_0.7.2 on my machine.
Configuration Properties > VC++ Directories > Include Directories
G:\Libraries\libssh_0.7.2\include;$(IncludePath)
Configuration Properties > VC++ Directories > Library Directories
G:\Libraries\libssh_0.7.2\lib;$(LibraryPath)
Configuration Properties > Linker > Input > Additional Dependencies
ssh.lib;%(AdditionalDependencies)
libssh path summary
libssh_0.7.2
bin
ssh.dll
include
libssh
callbacks.h
legacy.h
libssh.h
libsshpp.hpp
server.h
sftp.h
ssh2.h
lib
ssh.lib
Install vkpkg
⊞ Win+X and open the powershell
Input vckpg install libssh:x64-windows
Integrate into Visual Studio: vcpkg integrate install
Then you can include <libssh.h> in Visual Studio.

How to open input file, C++ on visual studio community 2015?

Does anyone know why the file isn't opening? I also tried just putting "infile.txt" and placing it in the folder of the program and also the debug folder but the ways I used to check for open error both triggered meaning that it could not open. I know I can hard code the location but I don't want to.
I heard you should do stringobj.c_str() but I don't know if that's accurate?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
string fileloc = "infile.txt";
infile.open(fileloc);
if (!infile)
{
cout << "open fail 1" << endl;
}
bool fail = infile.fail();
if (fail)
{
cout << "open fail 2";
}
return 0;
}
Note that the directory structure (at least for VS2013) is
<base>
- Solution Directory
- Debug
- Release
- Project Directory
- Debug
- Release
The program by default runs in the project directory (even though it is built to the solution/debug directory).
If you accepted the default naming convention when starting your project, you should be putting your file in the "Projects\ConsoleApplication1\ConsoleApplication1" directory, not "Projects\ConsoleApplication1"
Check your working directory in Project Settings -> Debugging. Make your file available there.
First, the documentation for the signature of
std::ifstream::open( const char * filename, ios_base::openmode mode=ios_base::in)
does indicate it requires a const char *, exactly what std::string::c_str() provides. However, there is an overload for open which accepts a const str &, which means it works the same way for both on most implementations.
Otherwise, what you're grappling with is known as the current working directory (or cwd). Apparently you're not sure where THAT directory is. It may be different while you run the debugger on Visual Studio than it is when you run your program from the command line, and it may be different in various IDE's.
I'm not sure why you want to ensure your program only opens a file by name in the current directory, and not give the full path, but...
You may want to inquire what the current working directory is, so you can solve the mystery wherever you try this. In my Visual Studio 2015, the directory ends up being the directory ABOVE debug, but that depends entirely on how your project is configured, and we can't see that out here.
So, try:
std::string cwd = getcwd( NULL, 0 );
This requires a header <direct.h> on Windows in Visual Studio, but it will give you the directory you're trying to figure out.
with
string fileloc = "infile.txt";
if you put infile.txt in the same folder of the cpp file, it should be fine.
btw I delete your first line
#include "stdafx.h"
I use cygwin console, may have minor diff
For my issue - i was stuck at loading image by opencv - i was wrong to place directory with jpg in the root of the C++ project
WRONG:
CORRECT:

Microsoft Visual Studios 2012 Can't open "python33.lib"

I'm using the Boost libraries in MicroSoft Visual Studios 2012 for a C++ program that is going to have Python embedded into it. The problem is when I try to Build Solution [F7]; I get this ::
Error 1 error LNK1104: cannot open file 'python33.lib' C:\Users\usr\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\LINK
The problem is, I have no idea what this is, means, or any clue of how to fix it.
I have already tried to move my python folder into my Desktop, as it was originally in the C:\, I thought maybe it was a permissions error, but that didn't do anything.
Here is my code from a tutorial that I was reading in preparation for the porject::
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <boost/lambda/lambda.hpp>
#include <boost/python.hpp>
using namespace boost::python;
int main( int argc, char ** argv ) {
try {
Py_Initialize();
object main_module((
handle<>(borrowed(PyImport_AddModule("__main__")))));
object main_namespace = main_module.attr("__dict__");
handle<> ignored(( PyRun_String( "print \"Hello, World\"",
Py_file_input,
main_namespace.ptr(),
main_namespace.ptr() ) ));
} catch( error_already_set ) {
PyErr_Print();
}
}
--Visual Studios 2012
--Windows 7 x64
--Python 3.3.2
--Boost libraries
--Python Embedded C++ program
--Link to tutorial page:: http://wiki.python.org/moin/boost.python/EmbeddingPython
Thanks for all the help David.
For anyone else who runs into this problem, here's what you need to do.
Right click on the Project name (ConsoleApplication1, ect) and under C/C++ general insure that your additional include directories include youe python include, Lib, and libs folders. As well as the boost root and the boost lib(32/64) folder.
Under the linker menu, in the input sub catagory, for additional dependencies, you'll need to add this into there.
C:\Python33\libs\python33.lib
C:\boost_1_54\lib32-msvc-11.0\boost_python-vc110-mt-gd-1_54.lib
Or whatever your install directory is. As well as any other required files.
Once that's done your project should build.
Once you're ready to run it you'll need to copy whatever .dll files are needed into the folder where the executable is built.

MS Visual C++ 2008 Express cannot find path

I'm trying to do something basic
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
After using F7 I get
1>mt.exe : general error c10100b1: Failed to load file "..\Debug\helloworld.exe". The system cannot find the path specified.
So it cant find the file that it'll eventually create?
What gives?
mt.exe is the manifest tool. The manifest tool shouldnt run if there is a build error. I dont think you will see mt.exe run if there is a build error. Go to your solution file, under the manifest tab, check if the path's in the settings are not hard coded to some wrong path.
#include <.iostream.>
Did your build really succeed? The above line looks suspicious - I'd have expected to see (note the missing periods):
#include <iostream>