libsgx_capable.so: 无法打开共享对象文件: 没有那个文件或目录
libsgx_capable.so: cannot open shared object file: No such file or directory
我正在尝试 运行 以下代码以在我的机器中启用 SGX(BIOS:软件控制):
//enable_device.c
#include "stdio.h"
#include "sgx_capable.h"
#include "sgx_eid.h"
#include "sgx_urts.h"
#include "sgx_error.h"
int main(void) {
sgx_device_status_t sgx_device_status;
sgx_status_t ret;
ret = sgx_cap_enable_device(&sgx_device_status);
if(ret == SGX_SUCCESS) {
switch(sgx_device_status) {
case SGX_ENABLED:
printf("The platform is enabled for Intel SGX.\n$
break;
case SGX_DISABLED_REBOOT_REQUIRED:
printf("This platform is disabled for Intel SGX.$
break;
case SGX_DISABLED_MANUAL_ENABLE:
printf("The platform is disabled for Intel SGX b$
break;
// case SGX_DISABLED_HYPERV_ENABLED:
// printf("The detected version of Windows* 10 is i$
// break;
case SGX_DISABLED_LEGACY_OS:
printf("The operating system does not support UE$
break;
case SGX_DISABLED_UNSUPPORTED_CPU:
printf("Intel SGX is not supported by this proce$
break;
case SGX_DISABLED:
printf("This platform is disabled for Intel SGX.$
break;
default:
printf("UNKNOWN RESPONSE\n");
}
} else {
switch(ret) {
case SGX_ERROR_INVALID_PARAMETER:
printf("The sgx_device_status pointer is invalid$
break;
case SGX_ERROR_NO_PRIVILEGE:
printf("The application does not have the requir$
break;
// case SGX_ERROR_HYPERV_ENABLED:
// printf("The detected version of Windows* 10 is i$
// break;
default:
printf("An unexpected error is detected.\n");
}
}
return 0;
}
这是我正在使用的 Makefile:
######### SGX TOOLS ######################
SGX_SDK := /usr/local/lib/intel/sgxsdk
SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
######## App Settings ########
App_C_Files := enable_device.c
App_C_Flags := -fPIC -Wno-attributes -IInclude -IApp -I$(SGX_SDK)/include
App_Cpp_Flags := $(App_C_Flags) -std=c++11
App_Link_Flags := -L$(SGX_LIBRARY_PATH) -lsgx_capable
App_C_Objects := $(App_C_Files:.c=.o)
App_Name := app
.PHONY: all run
all: $(App_Name)
run: all
######## App Objects ########
enable_device.o: enable_device.c
@$(CC) $(App_C_Flags) -c $< -o $@
$(App_Name): enable_device.o
@$(CC) $^ -o $@ $(App_Link_Flags)
.PHONY: clean
clean:
@rm -f $(App_Name) $(App_C_Objects)
当我运行申请时,我收到这条信息:
The application does not have the required privileges to read an EFI variable. Run the application with the administrator privileges to enable the Intel SGX device status.
然后,我 运行 sudo ./app
并收到以下错误:
./app: error while loading shared libraries: libsgx_capable.so: cannot open shared object file: No such file or directory
奇怪的是编译时没有找到这个库:
$ldd app
linux-vdso.so.1 (0x00007ffe065bc000)
libsgx_capable.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f15a060d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f15a0c01000)
然后,我使用:
export LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/
我再次 运行 和相同的错误消息 returns。谁能告诉我缺少什么?
The strange thing is that this library is not being found when compiling.
是编译时(实际上是链接时)发现的。否则
app
的链接将失败并且不存在。 ldd app
输出:
libsgx_capable.so => not found
显示 linker 找到 libsgx_capable.so
,并正式写入 NEEDED
它在 app
的 .dynamic
部分中的条目,其中 ldd
- 调用
运行time loader - 尝试解析为实际文件,但无法解析,因为
loader 现在无法在它始终查找的任何目录中找到 libsgx_capable.so
:
LD_LIBRARY_PATH
个目录
-
/etc/ld.so.conf
中列出的 ldconfig
个缓存目录
- 可信目录
/lib
和 /usr/lib
那是因为 /usr/local/lib/intel/sgxsdk/lib64/
不是目录 2 或
3 并且在您 运行 ldd app
.
时不是目录 1 之一
你说 app
需要 root 权限,而你 运行 用 sudo ./app
,
但即使你执行:
$ export LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/
$ sudo ./app
你还会遇到:
./app: error while loading shared libraries: libsgx_capable.so: cannot open shared object file: No such file or directory
发生这种情况是因为 sudo
命令在默认情况下不传递它所在的环境
被调用到它作为 root 执行的命令。参见:
$ cat main.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char const *foobar = getenv("FOOBAR");
printf("FOOBAR=[%s]\n",foobar ? foobar : "<null>");
return 0;
}
$ gcc -Wall -o prog main.c
$ export FOOBAR=foobar
$ ./prog
FOOBAR=[foobar]
$ sudo ./prog
FOOBAR=[<null>]
要通过 sudo
传输环境设置,您可以将它们作为参数传递
到 sudo
:
$ sudo FOOBAR=barfoo ./prog
FOOBAR=[barfoo]
$ echo $FOOBAR
foobar
或者您可以将选项 -E
赋予 sudo
:
$ sudo -E ./prog
FOOBAR=[foobar]
所以要么:
$ sudo LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/ ./app
或:
$ export LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/
$ sudo -E ./app
会起作用。但是,您可能更愿意不依赖于 LD_LIBRARY_PATH
让 app
在 运行 时加载 libsgx_capable.so
。在这种情况下,您可以将其放入
ldconfig
缓存 运行ning:
$ sudo ldconfig /usr/local/lib/intel/sgxsdk/lib64/
这将在 /usr/local/lib/intel/sgxsdk/lib64/
中缓存任何共享库
对于装载机。
或者,如果您希望保留发行版定义的 ldconfig
缓存,
你可以改变:
App_Link_Flags := -L$(SGX_LIBRARY_PATH) -lsgx_capable
至:
App_Link_Flags := -L$(SGX_LIBRARY_PATH) -lsgx_capable -Wl,-rpath=$(SGX_LIBRARY_PATH)
在你的 makefile 中。这将使链接器添加一个 RUNPATH
条目到 .dynamic
app
中的部分提示加载程序搜索 /usr/local/lib/intel/sgxsdk/lib64/
对于目录 1 之后和目录 2 和 3.
之前所需的库
我正在尝试 运行 以下代码以在我的机器中启用 SGX(BIOS:软件控制):
//enable_device.c
#include "stdio.h"
#include "sgx_capable.h"
#include "sgx_eid.h"
#include "sgx_urts.h"
#include "sgx_error.h"
int main(void) {
sgx_device_status_t sgx_device_status;
sgx_status_t ret;
ret = sgx_cap_enable_device(&sgx_device_status);
if(ret == SGX_SUCCESS) {
switch(sgx_device_status) {
case SGX_ENABLED:
printf("The platform is enabled for Intel SGX.\n$
break;
case SGX_DISABLED_REBOOT_REQUIRED:
printf("This platform is disabled for Intel SGX.$
break;
case SGX_DISABLED_MANUAL_ENABLE:
printf("The platform is disabled for Intel SGX b$
break;
// case SGX_DISABLED_HYPERV_ENABLED:
// printf("The detected version of Windows* 10 is i$
// break;
case SGX_DISABLED_LEGACY_OS:
printf("The operating system does not support UE$
break;
case SGX_DISABLED_UNSUPPORTED_CPU:
printf("Intel SGX is not supported by this proce$
break;
case SGX_DISABLED:
printf("This platform is disabled for Intel SGX.$
break;
default:
printf("UNKNOWN RESPONSE\n");
}
} else {
switch(ret) {
case SGX_ERROR_INVALID_PARAMETER:
printf("The sgx_device_status pointer is invalid$
break;
case SGX_ERROR_NO_PRIVILEGE:
printf("The application does not have the requir$
break;
// case SGX_ERROR_HYPERV_ENABLED:
// printf("The detected version of Windows* 10 is i$
// break;
default:
printf("An unexpected error is detected.\n");
}
}
return 0;
}
这是我正在使用的 Makefile:
######### SGX TOOLS ######################
SGX_SDK := /usr/local/lib/intel/sgxsdk
SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
######## App Settings ########
App_C_Files := enable_device.c
App_C_Flags := -fPIC -Wno-attributes -IInclude -IApp -I$(SGX_SDK)/include
App_Cpp_Flags := $(App_C_Flags) -std=c++11
App_Link_Flags := -L$(SGX_LIBRARY_PATH) -lsgx_capable
App_C_Objects := $(App_C_Files:.c=.o)
App_Name := app
.PHONY: all run
all: $(App_Name)
run: all
######## App Objects ########
enable_device.o: enable_device.c
@$(CC) $(App_C_Flags) -c $< -o $@
$(App_Name): enable_device.o
@$(CC) $^ -o $@ $(App_Link_Flags)
.PHONY: clean
clean:
@rm -f $(App_Name) $(App_C_Objects)
当我运行申请时,我收到这条信息:
The application does not have the required privileges to read an EFI variable. Run the application with the administrator privileges to enable the Intel SGX device status.
然后,我 运行 sudo ./app
并收到以下错误:
./app: error while loading shared libraries: libsgx_capable.so: cannot open shared object file: No such file or directory
奇怪的是编译时没有找到这个库:
$ldd app
linux-vdso.so.1 (0x00007ffe065bc000)
libsgx_capable.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f15a060d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f15a0c01000)
然后,我使用:
export LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/
我再次 运行 和相同的错误消息 returns。谁能告诉我缺少什么?
The strange thing is that this library is not being found when compiling.
是编译时(实际上是链接时)发现的。否则
app
的链接将失败并且不存在。 ldd app
输出:
libsgx_capable.so => not found
显示 linker 找到 libsgx_capable.so
,并正式写入 NEEDED
它在 app
的 .dynamic
部分中的条目,其中 ldd
- 调用
运行time loader - 尝试解析为实际文件,但无法解析,因为
loader 现在无法在它始终查找的任何目录中找到 libsgx_capable.so
:
LD_LIBRARY_PATH
个目录-
/etc/ld.so.conf
中列出的 - 可信目录
/lib
和/usr/lib
ldconfig
个缓存目录
那是因为 /usr/local/lib/intel/sgxsdk/lib64/
不是目录 2 或
3 并且在您 运行 ldd app
.
你说 app
需要 root 权限,而你 运行 用 sudo ./app
,
但即使你执行:
$ export LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/
$ sudo ./app
你还会遇到:
./app: error while loading shared libraries: libsgx_capable.so: cannot open shared object file: No such file or directory
发生这种情况是因为 sudo
命令在默认情况下不传递它所在的环境
被调用到它作为 root 执行的命令。参见:
$ cat main.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char const *foobar = getenv("FOOBAR");
printf("FOOBAR=[%s]\n",foobar ? foobar : "<null>");
return 0;
}
$ gcc -Wall -o prog main.c
$ export FOOBAR=foobar
$ ./prog
FOOBAR=[foobar]
$ sudo ./prog
FOOBAR=[<null>]
要通过 sudo
传输环境设置,您可以将它们作为参数传递
到 sudo
:
$ sudo FOOBAR=barfoo ./prog
FOOBAR=[barfoo]
$ echo $FOOBAR
foobar
或者您可以将选项 -E
赋予 sudo
:
$ sudo -E ./prog
FOOBAR=[foobar]
所以要么:
$ sudo LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/ ./app
或:
$ export LD_LIBRARY_PATH=/usr/local/lib/intel/sgxsdk/lib64/
$ sudo -E ./app
会起作用。但是,您可能更愿意不依赖于 LD_LIBRARY_PATH
让 app
在 运行 时加载 libsgx_capable.so
。在这种情况下,您可以将其放入
ldconfig
缓存 运行ning:
$ sudo ldconfig /usr/local/lib/intel/sgxsdk/lib64/
这将在 /usr/local/lib/intel/sgxsdk/lib64/
中缓存任何共享库
对于装载机。
或者,如果您希望保留发行版定义的 ldconfig
缓存,
你可以改变:
App_Link_Flags := -L$(SGX_LIBRARY_PATH) -lsgx_capable
至:
App_Link_Flags := -L$(SGX_LIBRARY_PATH) -lsgx_capable -Wl,-rpath=$(SGX_LIBRARY_PATH)
在你的 makefile 中。这将使链接器添加一个 RUNPATH
条目到 .dynamic
app
中的部分提示加载程序搜索 /usr/local/lib/intel/sgxsdk/lib64/
对于目录 1 之后和目录 2 和 3.