我正在尝试使用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上运行的应用程序
    -out:user.exe
    user.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 / A



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

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

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

而且我仍然收到未解决的符号。

奥拉夫

最佳答案

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

编辑:自从我接触过Intel编译器已经有一段时间了,但是IIRC您应该使用/link来介绍链接器选项:

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

09-09 23:49
查看更多