在Cygwin中针对psapi的G ++链接

问题描述 投票:0回答:1

我有一个C ++项目,我曾经用Visual C ++构建。在我使用的项目中:

#pragma comment(lib, "psapi")

为了连接psapi

但是,G ++似乎不支持这种语法。根据我的理解,你必须传递带有库名称的-l标志才能链接到它。

我试过-lpsapi.lib-lpsapi。 但是gcc无法找到它。 所以我搜索了我能找到的地方,显然它在/lib/w32api/libpsapi.a。所以我尝试了-llibpsapi.a-llibpsapi,但它仍然无法找到它。 所以我尝试使用-L标志添加路径,就像-L/lib/w32api一样,但它仍然找不到它。 然后我尝试添加两个环境变量而不是-L标志:

export LIBRARY_PATH=/lib/w32api
export LD_LIBRARY_PATH=/lib/w32api

但它仍然无法正常工作。

错误消息是:

/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -llibpsapi
collect2: error: ld returned 1 exit status

我的最后一次尝试是:

g++ -llibpsapi -o Example.exe Stuff.cpp Example.cpp -static

如果我完全离开-l标志,那么我得到这些错误btw:

/tmp/cctDMx8f.o:Stuff.cpp:(.text+0x139): undefined reference to `EnumProcessModules'
/tmp/cctDMx8f.o:Stuff.cpp:(.text+0x139): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `EnumProcessModules'
/tmp/cctDMx8f.o:Stuff.cpp:(.text+0x181): undefined reference to `EnumProcessModules'
/tmp/cctDMx8f.o:Stuff.cpp:(.text+0x181): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `EnumProcessModules'
/tmp/cctDMx8f.o:Stuff.cpp:(.text+0x1db): undefined reference to `GetModuleBaseNameA'
/tmp/cctDMx8f.o:Stuff.cpp:(.text+0x1db): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `GetModuleBaseNameA'
collect2: error: ld returned 1 exit status
c++ gcc g++ cygwin static-libraries
1个回答
0
投票

我想到了。首先,我必须使用-lpsapi,第二个重要的部分是我没有在-o标志之前插入它。以下工作正常:

g++ -o Example.exe Stuff.cpp Example.cpp -static -lpsapi
© www.soinside.com 2019 - 2024. All rights reserved.