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. Linker error

Linker error

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5linker errorsunresolved exte
6 Posts 3 Posters 2.4k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    Hey, I seem to get this linker error whenever i try to use anything from qt5, including it goes fine, but as soon as i call anything it bugs.

    I am using qt5 inside of a dll to handle http requests but it even happens when i just construct a QApplication. Someone mentioned it could be because I didn't link qt5 and visual studio, but i have no clue on how to solve this.
    error:

    1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall QApplication::QApplication(int &,char * *,int)" (__imp_??0QApplication@@QAE@AAHPAPADH@Z)
    1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ)
    1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (__imp_?exec@QApplication@@SAHXZ)
    

    code:

    int myLibraryExec() {
    	char* appName = (char*)"Project";
    	int argc = 1;
    	QApplication app(argc, &appName);
    	return app.exec();
    }
    
    int main() {
    	auto app = myLibraryExec();
    	std::cout << app << std::endl;
    	return 0;
    }
    

    Thanks in advance for the help!

    K 1 Reply Last reply
    0
    • ? A Former User

      Hey, I seem to get this linker error whenever i try to use anything from qt5, including it goes fine, but as soon as i call anything it bugs.

      I am using qt5 inside of a dll to handle http requests but it even happens when i just construct a QApplication. Someone mentioned it could be because I didn't link qt5 and visual studio, but i have no clue on how to solve this.
      error:

      1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall QApplication::QApplication(int &,char * *,int)" (__imp_??0QApplication@@QAE@AAHPAPADH@Z)
      1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ)
      1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (__imp_?exec@QApplication@@SAHXZ)
      

      code:

      int myLibraryExec() {
      	char* appName = (char*)"Project";
      	int argc = 1;
      	QApplication app(argc, &appName);
      	return app.exec();
      }
      
      int main() {
      	auto app = myLibraryExec();
      	std::cout << app << std::endl;
      	return 0;
      }
      

      Thanks in advance for the help!

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Mehodin

      Try this here:

      int myLibraryExec(int argc, char *argv[]) {
      	char* appName = (char*)"Project";
      	int argc = 1;
      	QApplication app(argc, argv);
      	return app.exec();
      }
      
      int main(int argc, char *argv[]) {
      	auto app = myLibraryExec( argc, argv );
      	std::cout << app << std::endl;
      	return 0;
      }
      

      You seem to confuse QApplication. The parameter list of main is really old back from C, which keeps a couple of surprizes.

      Check it out. Just typed brain to keyboard. Not tested and not compiled.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @koahnig

        gives me error saying
        1>c:\users\mehodin\documents\github\project\dllmain.cpp(26): error C2082: redefinition of formal parameter 'argc'

        and if i completely remove

        	char* appName = (char*)"Project";
        	int argc = 1;
        

        it gives same error as original post

        K 1 Reply Last reply
        0
        • ? A Former User

          @koahnig

          gives me error saying
          1>c:\users\mehodin\documents\github\project\dllmain.cpp(26): error C2082: redefinition of formal parameter 'argc'

          and if i completely remove

          	char* appName = (char*)"Project";
          	int argc = 1;
          

          it gives same error as original post

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Mehodin

          Sorry, my fault, try this:

          int myLibraryExec(int argc, char *argv[]) {
          	QApplication app(argc, argv);
          	return app.exec();
          }
          
          int main(int argc, char *argv[]) {
          	auto app = myLibraryExec( argc, argv );
          	std::cout << app << std::endl;
          	return 0;
          }
          

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          1
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @koahnig

            1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall QApplication::QApplication(int &,char * *,int)" (__imp_??0QApplication@@QAE@AAHPAPADH@Z)
            1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ)
            1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (__imp_?exec@QApplication@@SAHXZ)
            

            sadly didn't solve it. Since it's a dll, will it even pass argc and argv?

            int myLibraryExec(int argc, char *argv[]) {
            	QApplication app(argc, argv);
            	return app.exec();
            }
            
            int main(int argc, char *argv[]) {
            	auto app = myLibraryExec(argc, argv);
            	std::cout << app << std::endl;
            	return 0;
            }
            
            BOOL APIENTRY DllMain(HMODULE hModule,
            	DWORD  ul_reason_for_call,
            	LPVOID lpReserved
            )
            {
            	if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
            		hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)main, (LPVOID)hModule, 0, NULL);
            		if (hThread == NULL) {
            			return 0;
            		}
            	}
            	else if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
            	}
            	else if (ul_reason_for_call == DLL_PROCESS_DETACH) {
            	}
            	else if (ul_reason_for_call == DLL_THREAD_DETACH) {
            	}
            	return TRUE;
            }
            
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Might be a silly question but are you linking your .dll against Qt's widgets module ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2

              • Login

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