Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Link Error: Please help me out

Link Error: Please help me out

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++debuggingquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lsanil
    wrote on last edited by
    #1

    Hi, I am getting link error when I complied a program from Microsoft SDK that used PSAPI. I could not figure out whats going on and I tried using unicode and ANSI flags in link settings. No luck. Can someone help me out please? Here is the code #include #include #include void PrintProcessNameAndID( DWORD processID ) { char szProcessName[MAX_PATH] = "unknown"; // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if (NULL != hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ); } else return; } else return; // Print the process name and identifier. printf( "%s (Process ID: %u)\n", szProcessName, processID ); CloseHandle( hProcess ); } void main( ) { // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) PrintProcessNameAndID( aProcesses[i] ); } Link Errors: Linking... ProcessInfo.obj : error LNK2001: unresolved external symbol _GetModuleBaseNameA@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcessModules@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcesses@12 Debug/ProcessInfo.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. ProcessInfo.exe - 4 error(s), 0 warning(s) I am using Windows 2000 Professional SP4 and VC++ 6.0 with SP5. I got this sample from Platform SDK under PSAPI. Please help me out. I am lost. Thanks in Advance, Anil:confused:

    J K 2 Replies Last reply
    0
    • L lsanil

      Hi, I am getting link error when I complied a program from Microsoft SDK that used PSAPI. I could not figure out whats going on and I tried using unicode and ANSI flags in link settings. No luck. Can someone help me out please? Here is the code #include #include #include void PrintProcessNameAndID( DWORD processID ) { char szProcessName[MAX_PATH] = "unknown"; // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if (NULL != hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ); } else return; } else return; // Print the process name and identifier. printf( "%s (Process ID: %u)\n", szProcessName, processID ); CloseHandle( hProcess ); } void main( ) { // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) PrintProcessNameAndID( aProcesses[i] ); } Link Errors: Linking... ProcessInfo.obj : error LNK2001: unresolved external symbol _GetModuleBaseNameA@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcessModules@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcesses@12 Debug/ProcessInfo.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. ProcessInfo.exe - 4 error(s), 0 warning(s) I am using Windows 2000 Professional SP4 and VC++ 6.0 with SP5. I got this sample from Platform SDK under PSAPI. Please help me out. I am lost. Thanks in Advance, Anil:confused:

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      Are you linking with psapi.lib? Add the following statement to your cpp file.

      #pragma comment(lib,"psapi.lib")

      John

      L 1 Reply Last reply
      0
      • L lsanil

        Hi, I am getting link error when I complied a program from Microsoft SDK that used PSAPI. I could not figure out whats going on and I tried using unicode and ANSI flags in link settings. No luck. Can someone help me out please? Here is the code #include #include #include void PrintProcessNameAndID( DWORD processID ) { char szProcessName[MAX_PATH] = "unknown"; // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if (NULL != hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ); } else return; } else return; // Print the process name and identifier. printf( "%s (Process ID: %u)\n", szProcessName, processID ); CloseHandle( hProcess ); } void main( ) { // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) PrintProcessNameAndID( aProcesses[i] ); } Link Errors: Linking... ProcessInfo.obj : error LNK2001: unresolved external symbol _GetModuleBaseNameA@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcessModules@16 ProcessInfo.obj : error LNK2001: unresolved external symbol _EnumProcesses@12 Debug/ProcessInfo.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. ProcessInfo.exe - 4 error(s), 0 warning(s) I am using Windows 2000 Professional SP4 and VC++ 6.0 with SP5. I got this sample from Platform SDK under PSAPI. Please help me out. I am lost. Thanks in Advance, Anil:confused:

        K Offline
        K Offline
        Keith D
        wrote on last edited by
        #3

        you need to link with psapi.lib. add it in the link settings.

        1 Reply Last reply
        0
        • J John M Drescher

          Are you linking with psapi.lib? Add the following statement to your cpp file.

          #pragma comment(lib,"psapi.lib")

          John

          L Offline
          L Offline
          lsanil
          wrote on last edited by
          #4

          Hi John, Thank you very much:). It worked. Anil

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups