Intel® Software Guard Extensions (Intel® SGX)
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.

LINK 2019 Error When Trying to use sgx_read_rand

Giovanni_Plascencia
943 Views

Hello, I am a student researcher new to SGX, which is used in my project. I need to create a random number using sgx_read_rand. When I try to I receive the error LNK2019    unresolved external symbol _sgx_read_rand referenced in function _main. I have added #include<sgx_trts.h>. I have also tried adding sgx_trts.lib into the additional dependencies, but I still get the same error. I am using Visual Studio 2015. Any help is appreciated.

0 Kudos
1 Solution
JesusG_Intel
Moderator
800 Views

Hello Giovanni,


You need to create an enclave call (ecall) that your untrusted app can call. The SGX101 enclave_example is a simple tutorial on creating an enclave with a single ecall and ocall, which is based on the SampleEnclave in the SGX SDK. You should be able to easily modify this code for your purposes.


Refer to the section Enclave Development Basics in the Intel SGX SDK Developer Reference Guide for Windows for complete details on ecalls, ocalls, and other topics you should know when developing SGX applications.


Sincerely,

Jesus G.

Intel Customer Support


View solution in original post

12 Replies
JesusG_Intel
Moderator
928 Views

Hello Giovanni,


Can you run any of the SGX SDK samples successfully? Try compiling and running SampleEnclave.


If you can run SampleEnclave successfully, then ensure your project settings match the project settings from SampleEnclave.


I was able to use sgx_read_rand by adding #include <sgx_trts.h> and no other modifications.


Sincerely,

Jesus G.

Intel Customer Support


Giovanni_Plascencia
915 Views

I should have mentioned that I ran it in simulation mode. Yes I can run the SampleEnclave, in simulation mode. How can I make sure that the project settings match the project settings of the SamepleEnclave. Could it be that sgx_read_rand does not work in simulation mode?

JesusG_Intel
Moderator
909 Views

Hello Giovanny,


I confirmed that sgx_read_rand works in Simulation mode.


Refer to Unable to Build a Custom Intel® Software Guard Extensions (Intel® SGX) Application in Visual Studio* to configure the correct settings for your project.


Sincerely,

Jesus G.

Intel Customer Support


Giovanni_Plascencia
890 Views

Hello, I tried those options and they didn't work for me. I am now using the sample enclave as my base and it runs, but when I try to use sgx_read_rand I still get

Error LNK2019 unresolved external symbol _sgx_read_rand referenced in function _main 
as well as
Error LNK1120 1 unresolved externals 


JesusG_Intel
Moderator
879 Views

Hello Giovanni,


If you are using the SampleEnclave in Simulation mode, added #include <sgx_trts.h> and you still get the linker error, then the only other variable I see is the version of Visual Studio you are using. The SGX SDK was validated with Visual Studio 2019 and Visual Studio 2015 is not supported. Try updating to Visual Studio 2019 and re-run your tests.


Sincerely,

Jesus G.

Intel Customer Support


JesusG_Intel
Moderator
858 Views

Hello Giovanni,


Do you still need help with this issue?


Sincerely,

Jesus G.

Intel Customer Support


Giovanni_Plascencia
850 Views

Hello, Yes I do. I have upgraded to Visual Studio 2019. I am still getting the same error 
LNK2019 Unresolved external symbol_sgx_read_rand referenced in function _main


JesusG_Intel
Moderator
846 Views

Hello Giovanni,

 

Below are screenshots of my dev environment that may help you. I just noticed you wrote that you are getting that error from function _main. Are you trying to use sgx_read_rand in the untrusted app or the enclave? It cannot be used in the main app, it must be called from within the enclave because it is a trusted function.

 

This is the code I added to SampleEnclave/Enclave/Enclave.cpp:

 

#include "sgx_trts.h"

....

unsigned char rand_num[4] = "AAA";

sgx_status_t rand_ret = sgx_read_rand(rand_num, sizeof(rand_num));

if (rand_ret == SGX_SUCCESS) printf("Rand Success\n");

 

Loaded DLLs:

sgx_sim_libs.PNG

 

Enclave Project Properties:

sim_link_general.PNGsim_link_input.PNG

 

 

Sincerely,

Jesus G.

Intel Customer Support

 

JesusG_Intel
Moderator
820 Views

Hello Giovanni,


Do you still need help with this issue?


Sincerely,

Jesus G.

Intel Customer Support


Giovanni_Plascencia
806 Views

Thank you so much. I was trying to use sgx_read_rand in the applications main. I placed it in the printf function of the SampleEnclave Enclave.cpp and it reported Rand Success. I am now having trouble figuring out how to create my own function in the Enclave.cpp that will return the random number once called from the applications main. 

What I am asking is, how do I create a function in the enclave.cpp that I can call from the application main. I have not figured it out with the documentation that I have read so far. Could you help me with this?

JesusG_Intel
Moderator
801 Views

Hello Giovanni,


You need to create an enclave call (ecall) that your untrusted app can call. The SGX101 enclave_example is a simple tutorial on creating an enclave with a single ecall and ocall, which is based on the SampleEnclave in the SGX SDK. You should be able to easily modify this code for your purposes.


Refer to the section Enclave Development Basics in the Intel SGX SDK Developer Reference Guide for Windows for complete details on ecalls, ocalls, and other topics you should know when developing SGX applications.


Sincerely,

Jesus G.

Intel Customer Support


JesusG_Intel
Moderator
766 Views

This thread has been marked as answered and Intel will no longer monitor this thread. If you want a response from Intel in a follow-up question, please open a new thread.


Reply