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. error: undefined reference to `__imp_WSAStartup'
Forum Updated to NodeBB v4.3 + New Features

error: undefined reference to `__imp_WSAStartup'

Scheduled Pinned Locked Moved Unsolved General and Desktop
winsockwindows10qt 6.6
29 Posts 7 Posters 6.8k 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.
  • W wwwsharq

    @JonB hey, thank you for your response i have recently started to learn qt so i don't yet know it as well as i know winsock, can you specify what kind of like i should add to cmake (that's what i got from your comment at least) and/or how i would go about substituting this in qt?

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #4

    @wwwsharq
    I don't use Qt for Windows nor do I use cmake, so you will need someone else for that.

    However, the most pertinent question, especially if you are a newcomer to Qt, is why are you wanting using the Windows SDK and winsock? Qt is platform-independent, so in general you don't need or want to use Windows-specific calls in your code, certainly when Qt provides QTcpSocket etc.?

    1 Reply Last reply
    0
    • W wwwsharq

      i am not sure why this doesn't quite work in qt, i am trying to use the windows sdk
      and for some reason i get this error

      #include <sstream>
      #include <filesystem>

      #ifdef _WIN32
      #include "winsock2.h"
      #include <windows.h>
      #endif

      #include <QScrollBar>
      #include <QSettings>
      #include "mainwindow.h"
      #include "ui_mainwindow.h"

      //there's a bunch of other includes that don't matter for this i think btw

        #include "ws2tcpip.h"
       #include "stdio.h"
       using namespace std;
       using namespace stn;
       #pragma comment(lib, "Ws2_32.lib")
      
      
      
      
        MainWindow::MainWindow(QWidget *parent)
         : QMainWindow(parent)
         , ui(new Ui::MainWindow)
         , dev(this)
      {
        ui->setupUi(this);
      
      setFixedSize(size());           // prevent resizing
      
      setControlsState();
      
      ui->pushButtonSave->setEnabled(false);
      
      timerId = startTimer(1000);
      
      // Asynchronous initialization. Continued asynchronously in MainWindow::event, then in asyncInit.
      // QEvent must be allocated on the heap, released by receiver.
      QCoreApplication::postEvent(
          this,                                   // receiver
          new QEvent(QEvent::User));}
       MainWindow::~MainWindow()
      {
         delete ui;
      
      killTimer(timerId);}
      const ApplicationSettings* MainWindow::getSettings() const
      {
      return &settings;
      }
      

      // Asynchronous initialization.
      // Constructor - event - asyncInit.
      void MainWindow::asyncInit()
      {
      #ifdef _WIN32
      // Windows: Program working with SIXTeen SDK is responsible to initialize Windows sockets.

      WSADATA wsa_data;
      
      if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
      {
          postLogString("WSAStartup failed");
          ui->pushButtonConnect->setEnabled(false);
      }
      

      #endif

      //thank you in advance

      Ronel_qtmasterR Offline
      Ronel_qtmasterR Offline
      Ronel_qtmaster
      wrote on last edited by
      #5

      @wwwsharq you might consider to use a plain c++ or c project with Qt instead of trying projects with Qt Widgets

      Christian EhrlicherC 1 Reply Last reply
      0
      • Ronel_qtmasterR Ronel_qtmaster

        @wwwsharq you might consider to use a plain c++ or c project with Qt instead of trying projects with Qt Widgets

        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @Ronel_qtmaster please stop posting useless stuff. What has your answer to do with the problem?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • W wwwsharq

          @JonB hey, thank you for your response i have recently started to learn qt so i don't yet know it as well as i know winsock, can you specify what kind of like i should add to cmake (that's what i got from your comment at least) and/or how i would go about substituting this in qt?

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #7

          @wwwsharq see cmake command target_link_libraries() to link to ws2_32

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          W 1 Reply Last reply
          3
          • Christian EhrlicherC Christian Ehrlicher

            @wwwsharq see cmake command target_link_libraries() to link to ws2_32

            W Offline
            W Offline
            wwwsharq
            wrote on last edited by wwwsharq
            #8

            @Christian-Ehrlicher I have tried but it only has given me more errors, i

            it gives me this error now:

            CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
            Please set them or make sure they are set and tested correctly in the CMake files:
            ws2_32_LIBRARY_PATH
            

            do you know what lines i'd have to add? honestly i've messed with the cmake file alot an i've had no luck

            cmake_minimum_required(VERSION 3.5)
            
            project(eccoci VERSION 0.1 LANGUAGES CXX)
            
            set(CMAKE_AUTOUIC ON)
            set(CMAKE_AUTOMOC ON)
            set(CMAKE_AUTORCC ON)
            
            set(CMAKE_CXX_STANDARD 17)
            set(CMAKE_CXX_STANDARD_REQUIRED ON)
            
            
            find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
            find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
            
            set(PROJECT_SOURCES
                    main.cpp
            // stuff
            )
            
            if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
                qt_add_executable(eccoci
                    MANUAL_FINALIZATION
                    ${PROJECT_SOURCES}
                    main.cpp
                   /* and bunch of stuff*/
            
            )
            # Define target properties for Android with Qt 6 as:
            #    set_property(TARGET eccoci APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
            #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
            # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
            else()
                if(ANDROID)
                    add_library(eccoci SHARED
                        ${PROJECT_SOURCES}
                    )
            # Define properties for Android with Qt 5 after find_package() calls as:
            #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
                else()
                    add_executable(eccoci
                        ${PROJECT_SOURCES}
                    )
                endif()
            endif()
            
            target_link_libraries(eccoci PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
            # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
            # If you are developing for iOS or macOS you should consider setting an
            # explicit, fixed bundle identifier manually though.
            find_library(ws2_32_LIBRARY_PATH ws2_32)
            add_executable(Executive ${exec_src})
            target_link_libraries(Executive ${ws2_32_LIBRARY_PATH})
            if(${QT_VERSION} VERSION_LESS 6.1.0)
              set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.eccoci)
            endif()
            set_target_properties(eccoci PROPERTIES
                ${BUNDLE_ID_OPTION}
                MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
                MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
                MACOSX_BUNDLE TRUE
                WIN32_EXECUTABLE TRUE
            )
            
            include(GNUInstallDirs)
            install(TARGETS eccoci
                BUNDLE DESTINATION .
                LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
            )
            
            if(QT_VERSION_MAJOR EQUAL 6)
                qt_finalize_executable(eccoci)
            endif()
            
            
            1 Reply Last reply
            0
            • W Offline
              W Offline
              wwwsharq
              wrote on last edited by
              #9

              @wwwsharq let me be fully clear the full compilation errror is this

              
              15:58:36: Running steps for project eccoci...
              15:58:36: Starting: "C:\Program Files\CMake\bin\cmake.exe" --build C:/Users/User/Documents/build-eccoci-Desktop_Qt_6_6_2_MinGW_64_bit-Debug --target all
              [0/1 ?/sec] Re-running CMake...
              -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
              -- Configuring done (0.4s)
              CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
              Please set them or make sure they are set and tested correctly in the CMake files:
              ws2_32_LIBRARY_PATH
                  linked by target "Executive" in directory C:/Users/User/Documents/eccoci
              
              -- Generating done (0.1s)
              CMake Generate step failed.  Build files cannot be regenerated correctly.
              FAILED: build.ninja 
              "C:\Program Files\CMake\bin\cmake.exe" --regenerate-during-build -SC:\Users\User\Documents\eccoci -BC:\Users\User\Documents\build-eccoci-Desktop_Qt_6_6_2_MinGW_64_bit-Debug
              ninja: error: rebuilding 'build.ninja': subcommand failed
              15:58:37: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1.
              Error while building/deploying project eccoci (kit: Desktop Qt 6.6.2 MinGW 64-bit)
              When executing step "Build"
              15:58:37: Elapsed time: 00:01.
              
              
              kshegunovK 1 Reply Last reply
              0
              • W wwwsharq

                @wwwsharq let me be fully clear the full compilation errror is this

                
                15:58:36: Running steps for project eccoci...
                15:58:36: Starting: "C:\Program Files\CMake\bin\cmake.exe" --build C:/Users/User/Documents/build-eccoci-Desktop_Qt_6_6_2_MinGW_64_bit-Debug --target all
                [0/1 ?/sec] Re-running CMake...
                -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
                -- Configuring done (0.4s)
                CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
                Please set them or make sure they are set and tested correctly in the CMake files:
                ws2_32_LIBRARY_PATH
                    linked by target "Executive" in directory C:/Users/User/Documents/eccoci
                
                -- Generating done (0.1s)
                CMake Generate step failed.  Build files cannot be regenerated correctly.
                FAILED: build.ninja 
                "C:\Program Files\CMake\bin\cmake.exe" --regenerate-during-build -SC:\Users\User\Documents\eccoci -BC:\Users\User\Documents\build-eccoci-Desktop_Qt_6_6_2_MinGW_64_bit-Debug
                ninja: error: rebuilding 'build.ninja': subcommand failed
                15:58:37: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1.
                Error while building/deploying project eccoci (kit: Desktop Qt 6.6.2 MinGW 64-bit)
                When executing step "Build"
                15:58:37: Elapsed time: 00:01.
                
                
                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #10

                This is a cmake configuration error. Either you don't have WindowsSDK installed or it doesn't provide a cmake module for what you requested, or you have not pointed to cmake to find said module.

                Read and abide by the Qt Code of Conduct

                Christian EhrlicherC 1 Reply Last reply
                2
                • kshegunovK kshegunov

                  This is a cmake configuration error. Either you don't have WindowsSDK installed or it doesn't provide a cmake module for what you requested, or you have not pointed to cmake to find said module.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  There is no need to search for this lib. Simply add it to target_link_libraries call

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  W 2 Replies Last reply
                  3
                  • Christian EhrlicherC Christian Ehrlicher

                    There is no need to search for this lib. Simply add it to target_link_libraries call

                    W Offline
                    W Offline
                    wwwsharq
                    wrote on last edited by
                    #12
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      There is no need to search for this lib. Simply add it to target_link_libraries call

                      W Offline
                      W Offline
                      wwwsharq
                      wrote on last edited by
                      #13

                      @Christian-Ehrlicher hello do you have a tutorial or site you would reccomend to learn what you just said that isn't the cmake website? i have not understood evrything there and saying add target_link_libraries call doesn't tell me much i have added that line plenty of times without any luck, just more errors

                      target_link_libraries(eccoci PRIVATE ws2_32)
                      

                      and the like i've tried already

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • W wwwsharq

                        @Christian-Ehrlicher hello do you have a tutorial or site you would reccomend to learn what you just said that isn't the cmake website? i have not understood evrything there and saying add target_link_libraries call doesn't tell me much i have added that line plenty of times without any luck, just more errors

                        target_link_libraries(eccoci PRIVATE ws2_32)
                        

                        and the like i've tried already

                        Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @wwwsharq said in error: undefined reference to `__imp_WSAStartup':

                        just more errors

                        What errors?

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        W 1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @wwwsharq said in error: undefined reference to `__imp_WSAStartup':

                          just more errors

                          What errors?

                          W Offline
                          W Offline
                          wwwsharq
                          wrote on last edited by wwwsharq
                          #15

                          @Christian-Ehrlicher
                          current cmake

                          cmake_minimum_required(VERSION 3.5)
                          
                          project(eccoci VERSION 0.1 LANGUAGES CXX)
                          
                          set(CMAKE_AUTOUIC ON)
                          set(CMAKE_AUTOMOC ON)
                          set(CMAKE_AUTORCC ON)
                          
                          set(CMAKE_CXX_STANDARD 17)
                          set(CMAKE_CXX_STANDARD_REQUIRED ON)
                          
                          
                          find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
                          find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
                          
                          set(PROJECT_SOURCES
                                 main.cpp
                                 mainwindow.cpp
                                 mainwindow.h
                                 mainwindow.ui
                                 acqparamdialog.cpp
                                 advancedparamdialog.cpp
                                 device.cpp
                                 display.cpp
                                 settingsdialog.cpp
                                 utilities.cpp
                          )
                          
                          if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
                             qt_add_executable(eccoci
                                 MANUAL_FINALIZATION
                                 ${PROJECT_SOURCES}
                                 main.cpp
                                 definitions.h
                                 stn_def.h
                                 stn_calibration.h
                                 app_settings.h
                                 device.h
                                 stn_device.h
                                 display.h display.cpp
                                 display.ui
                                 settingsdialog.h settingsdialog.cpp
                                 settingsdialog.ui
                                 utilities.h utilities.cpp
                                 auto_fclose.h
                                 stn_print.h
                                 custom_events.h
                                 acqparamdialog.h acqparamdialog.cpp
                                 acqparamdialog.ui
                                 advancedparamdialog.h advancedparamdialog.cpp
                                 advancedparamdialog.ui
                                 ui_mainwindow.h
                                 device.cpp
                                 ui_display.h
                                 ui_advancedparamdialog.h
                                 ui_acqparamdialog.h
                          
                          
                             )
                          # Define target properties for Android with Qt 6 as:
                          #    set_property(TARGET eccoci APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
                          #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
                          # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
                          else()
                             if(ANDROID)
                                 add_library(eccoci SHARED
                                     ${PROJECT_SOURCES}
                                 )
                          # Define properties for Android with Qt 5 after find_package() calls as:
                          #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
                             else()
                                 add_executable(eccoci
                                     ${PROJECT_SOURCES}
                                 )
                             endif()
                          endif()
                          
                          target_link_libraries(eccoci PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
                          
                          target_link_libraries(eccoci PUBLIC ws2_32)
                          
                          # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
                          # If you are developing for iOS or macOS you should consider setting an
                          # explicit, fixed bundle identifier manually though.
                          # find_library(ws2_32_LIBRARY_PATH ws2_32)
                          add_library(ws2_32)
                          add_executable(Executive ${exec_src})
                          #target_link_libraries(Executive ${ws2_32_LIBRARY_PATH})
                          if(${QT_VERSION} VERSION_LESS 6.1.0)
                           set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.eccoci)
                          endif()
                          set_target_properties(eccoci PROPERTIES
                             ${BUNDLE_ID_OPTION}
                             MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
                             MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
                             MACOSX_BUNDLE TRUE
                             WIN32_EXECUTABLE TRUE
                          )
                          
                          include(GNUInstallDirs)
                          install(TARGETS eccoci
                             BUNDLE DESTINATION .
                             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
                          )
                          
                          if(QT_VERSION_MAJOR EQUAL 6)
                             qt_finalize_executable(eccoci)
                          endif()
                          
                          

                          error i get:

                          -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
                          -- Configuring done (0.4s)
                          -- Generating done (0.0s)
                          -- Build files have been written to: C:/Users/User/Documents/build-eccoci-Desktop_Qt_6_6_2_MinGW_64_bit-Debug
                          [1/12 8.6/sec] Automatic MOC and UIC for target Executive
                          [2/11 14.8/sec] Automatic MOC and UIC for target ws2_32
                          [3/9 13.6/sec] Linking CXX executable Executive.exe
                          FAILED: Executive.exe 
                          C:\Windows\system32\cmd.exe /C "cd . && C:\Qt\Tools\mingw1120_64\bin\g++.exe -DQT_QML_DEBUG -g  CMakeFiles/Executive.dir/Executive_autogen/mocs_compilation.cpp.obj -o Executive.exe -Wl,--out-implib,libExecutive.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
                          C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
                          collect2.exe: error: ld returned 1 exit status
                          [4/9 13.0/sec] Automatic MOC and UIC for target eccoci
                          ninja: build stopped: subcommand failed.
                          15:16:15: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1.
                          Error while building/deploying project eccoci (kit: Desktop Qt 6.6.2 MinGW 64-bit)
                          When executing step "Build"
                          15:16:15: Elapsed time: 00:01.
                          
                          Christian EhrlicherC 1 Reply Last reply
                          0
                          • W wwwsharq

                            @Christian-Ehrlicher
                            current cmake

                            cmake_minimum_required(VERSION 3.5)
                            
                            project(eccoci VERSION 0.1 LANGUAGES CXX)
                            
                            set(CMAKE_AUTOUIC ON)
                            set(CMAKE_AUTOMOC ON)
                            set(CMAKE_AUTORCC ON)
                            
                            set(CMAKE_CXX_STANDARD 17)
                            set(CMAKE_CXX_STANDARD_REQUIRED ON)
                            
                            
                            find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
                            find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
                            
                            set(PROJECT_SOURCES
                                   main.cpp
                                   mainwindow.cpp
                                   mainwindow.h
                                   mainwindow.ui
                                   acqparamdialog.cpp
                                   advancedparamdialog.cpp
                                   device.cpp
                                   display.cpp
                                   settingsdialog.cpp
                                   utilities.cpp
                            )
                            
                            if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
                               qt_add_executable(eccoci
                                   MANUAL_FINALIZATION
                                   ${PROJECT_SOURCES}
                                   main.cpp
                                   definitions.h
                                   stn_def.h
                                   stn_calibration.h
                                   app_settings.h
                                   device.h
                                   stn_device.h
                                   display.h display.cpp
                                   display.ui
                                   settingsdialog.h settingsdialog.cpp
                                   settingsdialog.ui
                                   utilities.h utilities.cpp
                                   auto_fclose.h
                                   stn_print.h
                                   custom_events.h
                                   acqparamdialog.h acqparamdialog.cpp
                                   acqparamdialog.ui
                                   advancedparamdialog.h advancedparamdialog.cpp
                                   advancedparamdialog.ui
                                   ui_mainwindow.h
                                   device.cpp
                                   ui_display.h
                                   ui_advancedparamdialog.h
                                   ui_acqparamdialog.h
                            
                            
                               )
                            # Define target properties for Android with Qt 6 as:
                            #    set_property(TARGET eccoci APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
                            #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
                            # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
                            else()
                               if(ANDROID)
                                   add_library(eccoci SHARED
                                       ${PROJECT_SOURCES}
                                   )
                            # Define properties for Android with Qt 5 after find_package() calls as:
                            #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
                               else()
                                   add_executable(eccoci
                                       ${PROJECT_SOURCES}
                                   )
                               endif()
                            endif()
                            
                            target_link_libraries(eccoci PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
                            
                            target_link_libraries(eccoci PUBLIC ws2_32)
                            
                            # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
                            # If you are developing for iOS or macOS you should consider setting an
                            # explicit, fixed bundle identifier manually though.
                            # find_library(ws2_32_LIBRARY_PATH ws2_32)
                            add_library(ws2_32)
                            add_executable(Executive ${exec_src})
                            #target_link_libraries(Executive ${ws2_32_LIBRARY_PATH})
                            if(${QT_VERSION} VERSION_LESS 6.1.0)
                             set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.eccoci)
                            endif()
                            set_target_properties(eccoci PROPERTIES
                               ${BUNDLE_ID_OPTION}
                               MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
                               MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
                               MACOSX_BUNDLE TRUE
                               WIN32_EXECUTABLE TRUE
                            )
                            
                            include(GNUInstallDirs)
                            install(TARGETS eccoci
                               BUNDLE DESTINATION .
                               LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                               RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
                            )
                            
                            if(QT_VERSION_MAJOR EQUAL 6)
                               qt_finalize_executable(eccoci)
                            endif()
                            
                            

                            error i get:

                            -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
                            -- Configuring done (0.4s)
                            -- Generating done (0.0s)
                            -- Build files have been written to: C:/Users/User/Documents/build-eccoci-Desktop_Qt_6_6_2_MinGW_64_bit-Debug
                            [1/12 8.6/sec] Automatic MOC and UIC for target Executive
                            [2/11 14.8/sec] Automatic MOC and UIC for target ws2_32
                            [3/9 13.6/sec] Linking CXX executable Executive.exe
                            FAILED: Executive.exe 
                            C:\Windows\system32\cmd.exe /C "cd . && C:\Qt\Tools\mingw1120_64\bin\g++.exe -DQT_QML_DEBUG -g  CMakeFiles/Executive.dir/Executive_autogen/mocs_compilation.cpp.obj -o Executive.exe -Wl,--out-implib,libExecutive.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
                            C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
                            collect2.exe: error: ld returned 1 exit status
                            [4/9 13.0/sec] Automatic MOC and UIC for target eccoci
                            ninja: build stopped: subcommand failed.
                            15:16:15: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1.
                            Error while building/deploying project eccoci (kit: Desktop Qt 6.6.2 MinGW 64-bit)
                            When executing step "Build"
                            15:16:15: Elapsed time: 00:01.
                            
                            Christian EhrlicherC Online
                            Christian EhrlicherC Online
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #16

                            @wwwsharq said in error: undefined reference to `__imp_WSAStartup':

                            target_link_libraries(eccoci PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

                            add_executable(Executive ${exec_src})

                            You create a library but don't link it to your executable.
                            Also you link the QtWidgets library private to your library which is wrong (as you expose QtWidgets stuff in your library to it's users). So either properly link public or link your executable also to QtWidgets.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            1
                            • S Offline
                              S Offline
                              SamiV123
                              wrote on last edited by
                              #17

                              If you're using visual studio (and cl) by far the easiest way is to

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

                              the less you need to mess with CMake or (build files in general) the better.

                              Christian EhrlicherC 1 Reply Last reply
                              0
                              • S SamiV123

                                If you're using visual studio (and cl) by far the easiest way is to

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

                                the less you need to mess with CMake or (build files in general) the better.

                                Christian EhrlicherC Online
                                Christian EhrlicherC Online
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #18

                                @SamiV123 said in error: undefined reference to `__imp_WSAStartup':

                                the less you need to mess with CMake or (build files in general) the better.

                                Using some non-standard stuff instead standarized scripting is for sure much better.
                                If you would have read the post from above you would see that the OP is using MinGW which does not support this crap.

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

                                S 1 Reply Last reply
                                0
                                • Christian EhrlicherC Christian Ehrlicher

                                  @SamiV123 said in error: undefined reference to `__imp_WSAStartup':

                                  the less you need to mess with CMake or (build files in general) the better.

                                  Using some non-standard stuff instead standarized scripting is for sure much better.
                                  If you would have read the post from above you would see that the OP is using MinGW which does not support this crap.

                                  S Offline
                                  S Offline
                                  SamiV123
                                  wrote on last edited by
                                  #19

                                  @Christian-Ehrlicher said in error: undefined reference to `__imp_WSAStartup':

                                  @SamiV123 said in error: undefined reference to `__imp_WSAStartup':

                                  the less you need to mess with CMake or (build files in general) the better.

                                  Using some non-standard stuff instead standarized scripting is for sure much better.
                                  If you would have read the post from above you would see that the OP is using MinGW which does not support this crap.

                                  Nothing standard about "scripting" (which I believe you use to refer to CMake) . But yeah, some of us prefer to have things the easy way and some don't...

                                  Christian EhrlicherC 1 Reply Last reply
                                  0
                                  • S SamiV123

                                    @Christian-Ehrlicher said in error: undefined reference to `__imp_WSAStartup':

                                    @SamiV123 said in error: undefined reference to `__imp_WSAStartup':

                                    the less you need to mess with CMake or (build files in general) the better.

                                    Using some non-standard stuff instead standarized scripting is for sure much better.
                                    If you would have read the post from above you would see that the OP is using MinGW which does not support this crap.

                                    Nothing standard about "scripting" (which I believe you use to refer to CMake) . But yeah, some of us prefer to have things the easy way and some don't...

                                    Christian EhrlicherC Online
                                    Christian EhrlicherC Online
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #20

                                    @SamiV123 said in error: undefined reference to `__imp_WSAStartup':

                                    But yeah, some of us prefer to have things the easy way and some don't...

                                    Your idea will simply not work for the OP...

                                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                    Visit the Qt Academy at https://academy.qt.io/catalog

                                    1 Reply Last reply
                                    0
                                    • W wwwsharq

                                      i am not sure why this doesn't quite work in qt, i am trying to use the windows sdk
                                      and for some reason i get this error

                                      #include <sstream>
                                      #include <filesystem>

                                      #ifdef _WIN32
                                      #include "winsock2.h"
                                      #include <windows.h>
                                      #endif

                                      #include <QScrollBar>
                                      #include <QSettings>
                                      #include "mainwindow.h"
                                      #include "ui_mainwindow.h"

                                      //there's a bunch of other includes that don't matter for this i think btw

                                        #include "ws2tcpip.h"
                                       #include "stdio.h"
                                       using namespace std;
                                       using namespace stn;
                                       #pragma comment(lib, "Ws2_32.lib")
                                      
                                      
                                      
                                      
                                        MainWindow::MainWindow(QWidget *parent)
                                         : QMainWindow(parent)
                                         , ui(new Ui::MainWindow)
                                         , dev(this)
                                      {
                                        ui->setupUi(this);
                                      
                                      setFixedSize(size());           // prevent resizing
                                      
                                      setControlsState();
                                      
                                      ui->pushButtonSave->setEnabled(false);
                                      
                                      timerId = startTimer(1000);
                                      
                                      // Asynchronous initialization. Continued asynchronously in MainWindow::event, then in asyncInit.
                                      // QEvent must be allocated on the heap, released by receiver.
                                      QCoreApplication::postEvent(
                                          this,                                   // receiver
                                          new QEvent(QEvent::User));}
                                       MainWindow::~MainWindow()
                                      {
                                         delete ui;
                                      
                                      killTimer(timerId);}
                                      const ApplicationSettings* MainWindow::getSettings() const
                                      {
                                      return &settings;
                                      }
                                      

                                      // Asynchronous initialization.
                                      // Constructor - event - asyncInit.
                                      void MainWindow::asyncInit()
                                      {
                                      #ifdef _WIN32
                                      // Windows: Program working with SIXTeen SDK is responsible to initialize Windows sockets.

                                      WSADATA wsa_data;
                                      
                                      if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
                                      {
                                          postLogString("WSAStartup failed");
                                          ui->pushButtonConnect->setEnabled(false);
                                      }
                                      

                                      #endif

                                      //thank you in advance

                                      Ketan__Patel__0011K Offline
                                      Ketan__Patel__0011K Offline
                                      Ketan__Patel__0011
                                      wrote on last edited by
                                      #21

                                      @wwwsharq for this error there are so many resone and i personally faced many problems
                                      You should try to rearrange your header files.

                                      Try the following way which is i used.

                                      #define WIN32_LEAN_AND_MEAN
                                      #include <windows.h>
                                      #include <WinSock2.h>
                                      #include <WS2tcpip.h>
                                      #include <NetCon.h>
                                      
                                      #pragma comment (lib, "Ws2_32.lib")
                                      #pragma comment (lib, "Mswsock.lib")
                                      #pragma comment (lib, "AdvApi32.lib")
                                      
                                      JonBJ 1 Reply Last reply
                                      0
                                      • Ketan__Patel__0011K Ketan__Patel__0011

                                        @wwwsharq for this error there are so many resone and i personally faced many problems
                                        You should try to rearrange your header files.

                                        Try the following way which is i used.

                                        #define WIN32_LEAN_AND_MEAN
                                        #include <windows.h>
                                        #include <WinSock2.h>
                                        #include <WS2tcpip.h>
                                        #include <NetCon.h>
                                        
                                        #pragma comment (lib, "Ws2_32.lib")
                                        #pragma comment (lib, "Mswsock.lib")
                                        #pragma comment (lib, "AdvApi32.lib")
                                        
                                        JonBJ Online
                                        JonBJ Online
                                        JonB
                                        wrote on last edited by JonB
                                        #22

                                        @Ketan__Patel__0011
                                        Have you verified these #pragma comment (lib, ... statements work from MinGW? They are not just an MSVC thing?

                                        Maybe your re-ordering of the headers will help, I don't know, but I don't see how this will solve MinGW not knowing to link with Ws2_32, which seems to be the error message.

                                        Same sort of thing as @SamiV123 above. Don't forget the OP actually already has

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

                                        in his original code question, and it's still not linking....

                                        Christian EhrlicherC 1 Reply Last reply
                                        0
                                        • JonBJ JonB

                                          @Ketan__Patel__0011
                                          Have you verified these #pragma comment (lib, ... statements work from MinGW? They are not just an MSVC thing?

                                          Maybe your re-ordering of the headers will help, I don't know, but I don't see how this will solve MinGW not knowing to link with Ws2_32, which seems to be the error message.

                                          Same sort of thing as @SamiV123 above. Don't forget the OP actually already has

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

                                          in his original code question, and it's still not linking....

                                          Christian EhrlicherC Online
                                          Christian EhrlicherC Online
                                          Christian Ehrlicher
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #23

                                          @JonB said in error: undefined reference to `__imp_WSAStartup':

                                          They are not just an MSVC thing

                                          The pragma is proprietary MSVC crap

                                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                          Visit the Qt Academy at https://academy.qt.io/catalog

                                          JonBJ 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