Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Link Problem with Kernel32.lib, Psapi.lib, etc.
QtWS25 Last Chance

Link Problem with Kernel32.lib, Psapi.lib, etc.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 10.2k Views
  • 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.
  • Q Offline
    Q Offline
    QDanny01001
    wrote on last edited by
    #1

    Hey Guys,

    I am running into an odd problem. Usually I peruse the forums so that I can figure out how to do things, this time I can't figure it out.

    I was running a Console in C (opened by a GUI in Qt) via a process with startDetached so that the Console window would appear (this way the user can enter in input, etc.)

    I eventually figured out that using startDetached relinquishes any form of control in Qt over the Console window. So I cannot see when it closes! (I need to see when it closes so that I can load its output into the GUI)

    So then I decided to use the Windows API to try and see if the Console was running (I just keep checking and checking in an infinite loop, in theory it stinks but it should work). I think I got the API code right:

    @bool isRunning(std::string pName)
    {
    unsigned long aProcesses[1024], cbNeeded, cProcesses;
    if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
    return true;

        cProcesses = cbNeeded / sizeof(unsigned long);
        for(unsigned int i = 0; i < cProcesses; i++)
        {
                if(aProcesses[i] == 0)
                        continue;
    
                HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, aProcesses[i]);
                WCHAR buffer[50];
                GetModuleBaseName(hProcess, 0, buffer, 50);
                CloseHandle(hProcess);
    
                //convert from wide char to narrow char array
                    char charray[50];
                    char DefChar = ' ';
                    WideCharToMultiByte(CP_ACP,0,buffer,-1, charray,50,&DefChar, NULL);
    
                    //A std:string  using the char* constructor.
                    std::string newbuf(charray);
    
                //std::string newbuf = static_cast<std::string>(buffer);
                if(pName == newbuf)
                        return true;
        }
        return false;
    

    }@

    However, when I link the library in QtCreator by going to qmake and adding += C:\path... \psapi.lib or \Kernel32.lib, I get the following error...

    c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\Kernel32.lib:1: error: Parse Error ('!<arch>')

    I have absolutely no idea why this is happening. If you guys could give me some help I would appreciate it greatly! Maybe there is a solution that does not require me to use Windows API...

    Thanks,
    Dan

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on last edited by
      #2

      Does your .pro look like this?

      @
      win32:LIBS += -luser32
      win32:LIBS += -lpsapi
      win32:LIBS += -lkernel32
      @

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        QDanny01001
        wrote on last edited by
        #3

        Thanks for the response.

        No. I don't have those in my .pro at all.

        I tried adding them...
        @FORMS += mxcolwindow.ui

        win32:LIBS += -luser32
        win32:LIBS += -lpsapi
        win32:LIBS += -lkernel32@

        It still doesn't compile.

        Also, if I remove my previous reference to the Kernel32.lib, it still does not compile.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          [quote author="QDanny01001" date="1337797930"]However, when I link the library in QtCreator by going to qmake and adding += C:\path... \psapi.lib or \Kernel32.lib, I get the following error...

          c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\Kernel32.lib:1: error: Parse Error ('!<arch>') [/quote]

          Looks like the compiler doesn't recognize the library format. What compiler are you using? MSVC or MinGW/GCC?

          If it's MinGW/GCC, then static libraries (including "import" libraries) should have a .a extension.

          Also you will find "libkernel32.a" and friends in MinGW/GCC's "lib" folder. No need for the Microsoft Platform SDK.

          And in case you are using MSVC, are you sure that "x64" is the correct choice?

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            QDanny01001
            wrote on last edited by
            #5

            bq. Looks like the compiler doesn’t recognize the library format. What compiler are you using? MSVC or MinGW/GCC?
            If it’s MinGW/GCC, then static libraries (including “import” libraries) should have a .a extension.
            Also you will find “libkernel32.a” and friends in MinGW/GCC’s “lib” folder. No need for the Microsoft Platform SDK.
            And in case you are using MSVC, are you sure that “x64” is the correct choice?

            I have tried multiple libraries besides "x64" etc. I think there are three located in the program files\visual studio folder. They all gave the same error.

            I did try using (from memory..) libpsapi.a to link to as well because I saw a suggestion somewhere to link to that library in Qt for Api's. It didn't work. I will try the "libkernel32.a" though, I haven't tried it, so hopefully it will work.

            I hope it isn't a compiler issue. I am using QtCreator. I have never tried compiling in MSVC, but if all else fails I may have to give it a try.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MuldeR
              wrote on last edited by
              #6

              I have to admit that I usually use VisualStudio.

              But from what I know, the QtCreator uses MinGW/GCC. Preferably the version that is bundled with Qt SDK.

              I assume you use MinGW/GCC, which means linking the .lib's intended for MSVC is the problem.

              Please try linking against libkernel32.a, libpsapi.a and so on from your MinGW installations "lib" folder.

              Do note that the GCC parameter "-lfoo" is sufficient to link in the library "libfoo.a". So you'd use "-lkernel32".

              There should be no need to add the path to the .a file, because GCC looks into its "lib" folder by default.

              My OpenSource software at: http://muldersoft.com/

              Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

              Go visit the coop: http://youtu.be/Jay...

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                QDanny01001
                wrote on last edited by
                #7

                Still gives the same errors.

                Looks like it is time to do this in MSVC...

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved