gpt4 book ai didi

c - Win64下获取用户名

转载 作者:行者123 更新时间:2023-11-30 18:07:48 29 4
gpt4 key购买 nike

我正在尝试在 MINGW/64 下使用 Intel icl 编译器编译 C 程序。该程序使用以下代码:

#include <Userenv.h>
HANDLE process;
HANLDE token;
GetUserProfileDirectory(process, TOKEN_QUERY, &ptoken)

我正在使用以下编译命令:

$ icl -g -DMINGW32 -DTESTMAIN user.c -o user -UserEnv.Lib

我正在链接 Microsoft SDK 中的 UserEnv.Lib。

英特尔(R) C++ 英特尔(R) 64 编译器 XE,适用于在英特尔(R) 64 上运行的应用程序,版本 Microsoft(R) 增量链接器版本 9.00.21022.08 -输出:用户.exe 用户.obj

user.obj : error LNK2019: unresolved external symbol __imp_GetUserProfileDirectoryA referenced in function main

知道如何解决这个问题吗?

解决方案:
解决方案是使用

/link/c/Program\Files/Microsoft\SDKs/Windows/v6.0A/Lib/x64/UserEnv.Lib/c/Program\Files/Microsoft\SDKs/Windows/v6.0A/Lib/x64/

<小时/>

我将 Microsoft SDK(x64、6.0)中的 UserEnv.lib 文件复制到当前工作目录中,并使用

编译程序

$ icl test.c -DMINGW32 ./UserEnv.Lib

LNK2019:函数 main test.obj 中引用了无法解析的外部符号 __imp_GetUserNameA:错误 LNK2019:函数 main test.obj 中引用了无法解析的外部符号 __imp_OpenProcessToken:错误 LNK2019:无法解析的外部符号 -

我仍然收到未解析的符号。

奥拉夫

最佳答案

您需要将userenv.lib添加到您的输入库中,链接器才能看到GetUserProfileDirectory() .

编辑:自从我接触英特尔编译器以来已经有一段时间了,但是 IIRC 你应该使用 /link 来引入链接器选项:

$ icl test.c -DMINGW32 /link ./UserEnv.Lib

关于c - Win64下获取用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4232365/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com