2 Replies - 12482 Views - Last Post: 07 July 2009 - 12:33 AM Rate Topic: -----

#1 abhijit_mohanta   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-December 06

compile error [Linker error] undefined reference to `EnumProcessModu

Posted 06 July 2009 - 10:20 AM

I am getting the compilation error while coiling following code


#include <windows.h>
#include <TlHelp32.h>
#include <iostream.h>
#include <psapi.h>
#pragma comment(lib, "psapi")
#pragma comment(lib, "TlHelp32")




DWORD ListModules(DWORD  dwProcessId);


int main(int argc,const char* argv[])
{
ListModules((DWORD)argv[1]);  
return 0;
}

DWORD ListModules(DWORD  dwProcessId)
{
        char DllName[MAX_PATH] = {NULL};
        HANDLE hProc;
        DWORD Needed = NULL;
        HMODULE hMod[1024];


        cout << "listing modules of "  << endl;

       

        hProc = OpenProcess(PROCESS_ALL_ACCESS, false, dwProcessId);
       
        EnumProcessModules(hProc, hMod, sizeof(hMod), &Needed);
     
        for (int i=0;i<(Needed / sizeof(HMODULE)); i++ )
                {                       
                        if(GetModuleFileNameEx(hProc, hMod[i], DllName, sizeof(DllName)/sizeof(char)))
                        {
                                cout << DllName << endl;
                        }
                }
        CloseHandle(hProc);
        return NULL;
}



error
[Linker error] undefined reference to `[email protected]'
[Linker error] undefined reference to `[email protected]'

How do I resolve it.

Thanks in advance

*** MOD EDIT: Added code tags. Please :code: ***

Is This A Good Question/Topic? 0
  • +

Replies To: compile error [Linker error] undefined reference to `EnumProcessModu

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: compile error [Linker error] undefined reference to `EnumProcessModu

Posted 06 July 2009 - 05:29 PM

You don't say what is the OS, but going to the MSDN page for GetModuleFileNameEx, and scrolling down to the requirements, we see the following Library requirement:

Quote

Kernel32.lib on Windows 7 and Windows Server 2008 R2, Psapi.lib on Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000


Now, it looks like you're trying to link psapi through the #pragma at the top
#pragma comment(lib, "psapi")

so I'm going to guess that the #pragma is not working, probably because it's not valid for your compiler. I believe that may only work with Visual Studio, and while you've not told us the environment, I would guess you're using Dev-C++ from the [Linker Error] message. You need to add the .lib files in the Dev-C++ IDE linker options.
Was This Post Helpful? 0
  • +
  • -

#3 abhijit_mohanta   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-December 06

Re: compile error [Linker error] undefined reference to `EnumProcessModu

Posted 07 July 2009 - 12:33 AM

I found the psapi.h file in the following link http://www.codase.co...mp;off=877+888+ and put it in include directory of VC++ now getting new errors

I am trying now in VC++ 6 IDE but getting a new error .

Compiling...
process.cpp
d:\program files\microsoft visual studio\vc98\include\psapi.h(89) : warning C4005: 'GetModuleFileName' : macro redefinition
d:\program files\microsoft visual studio\vc98\include\winbase.h(4221) : see previous definition of 'GetModuleFileName'
E:\languages\vc++\process\process\process.cpp(38) : warning C4018: '<' : signed/unsigned mismatch
E:\languages\vc++\process\process\process.cpp(40) : error C2065: 'GetModuleFileNameEx' : undeclared identifier
Error executing cl.exe.
process.obj - 1 error(s), 2 warning(s)

I have included windows.h but still getting the error error C2065: 'GetModuleFileNameEx' : undeclared identifier




Seems psapi.h and lib files are not found.I am not able to find them.Can u please tell me where I can get the files
I am using XP sp2.

This post has been edited by abhijit_mohanta: 07 July 2009 - 12:47 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1