I am writing a program that requires me to include psabi.h. However, if I simply do #include <Psabi.h>
I get the following error:
*path*\cch351oc.o:sourcefile1.cpp:(.text+0x7f): undefined reference to 'EnumProcessModules@16'
*path*\cch351oc.o:sourcefile1.cpp:(.text+0xd5): undefined reference to 'GetModuleFileNameExA@16'
In some solutions, I see the line #pragma comment(lib, "psabi.lib")
but this does not seem to do anything when compiling with g++.
I have tried the following lines in compiling:
g++ -L"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib" -lpsabi.lib sourcefile1.cpp
g++ -L"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\psabi.lib" sourcefile1.cpp
and also taking away the quotations and replacing the spaces with underscore. These all return:
c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../../mingw32/bin/ld.exe: cannot find -lpsabi.lib
collect2.exe: error: ld returned 1 exit status
For such a small error this is getting quite boring! Any help would be greatly appreciated.
Cheers.
EDIT: while What is an undefined reference/unresolved external symbol error and how do I fix it? identifies the same problem I have (though not specifically with psabi), it does not solve my issue - it does not tell me what to actually write on the command line.
EDIT: I have changed the functions in sourcefile1.cpp from EnumProcessModules to k32EnumprocessModules and GetModuleFileNameEx to K32GetModuleFileNameEx. I have tried the command lines:
g++ -DSAPI_VERSION=2 sourcefile1.cpp
g++ -DSAPI_VERSION=2 -lkernel32 sourcefile1.cpp
g++ -DSAPI_VERSION=2 -lkernel32.lib sourcefile1.cpp
g++ -DSAPI_VERSION=2 -L"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib" -lkernel32.lib sourcefile1.cpp
g++ -DSAPI_VERSION=2 -L"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\Kernel32.lib" sourcefile1.cpp
but all of them give the following error:
sourcefile1.cpp: In function 'long int getBaseAddress(const char*)':
sourcefile1.cpp:52:86: error: 'K32EnumProcessModules' was not declared in this scope
if (K32EnumProcessModules(processHandle, moduleList, sizeof(moduleList), &sizeNeeded))
^
sourcefile1.cpp:66:87: error: 'K32GetModuleFileNameEx' was not declared in this scope
if (K32GetModuleFileNameEx(processHandle, moduleList[i], modulePath, modulePathSize) != 0)
^
Reverting back to the original function calls (EnumProcessModules and GetModuleFileNameEx instead of K32EnumProcessModules and K32GetModuleFileNameEx) gives the same errors as before.
FINAL EDIT: g++ sourcefile1.cpp -lpsapi does indeed work on other computers. Seems the problem was a combination of originally not dropping the ".lib" as MvG pointed out, but also some problem in the installation files of mingw somewhere.