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 8.0k 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.
  • 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 Offline
      Christian EhrlicherC Offline
      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 Offline
          Christian EhrlicherC Offline
          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 Offline
              Christian EhrlicherC Offline
              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 Offline
                  JonBJ Offline
                  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 Offline
                    Christian EhrlicherC Offline
                    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
                    • Christian EhrlicherC Christian Ehrlicher

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

                      They are not just an MSVC thing

                      The pragma is proprietary MSVC crap

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #24

                      @Christian-Ehrlicher I know. I was inviting @Ketan__Patel__0011 to consider his answer for the OP with MinGW in this light.

                      Ketan__Patel__0011K 1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SamiV123
                        wrote on last edited by SamiV123
                        #25

                        Using MingW on Windows when MSVS is free (and is essentially the de-facto standard C++ tool for Windows) is just bonkers.

                        1 Reply Last reply
                        0
                        • JonBJ JonB

                          @Christian-Ehrlicher I know. I was inviting @Ketan__Patel__0011 to consider his answer for the OP with MinGW in this light.

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

                          @JonB Well i am using this conecpt in MSVC based Application and i also tried with MinGW Application and it's working very well.
                          But For MinGW you have to do one more thing.
                          just add below code in your .pro file

                          LIBS += -lWs2_32
                          LIBS += -lMswsock
                          LIBS += -lAdvApi32
                          
                          JonBJ 1 Reply Last reply
                          0
                          • Ketan__Patel__0011K Ketan__Patel__0011

                            @JonB Well i am using this conecpt in MSVC based Application and i also tried with MinGW Application and it's working very well.
                            But For MinGW you have to do one more thing.
                            just add below code in your .pro file

                            LIBS += -lWs2_32
                            LIBS += -lMswsock
                            LIBS += -lAdvApi32
                            
                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #27

                            @Ketan__Patel__0011
                            So for MinGW the #pragma comment (lib, "Ws2_32.lib") has no effect, that is why you have to add the -lWs2_32 etc. explicitly to get the link to happen. Which is just what we said --- the #pragma is for MSVC only.

                            If you read what the OP is asking you will see that are using cmake, not qmake, no .pro file. So your LIBS lines do not help them. And they are asking precisely what equivalent they have to do for cmake (which I do not know).

                            Ketan__Patel__0011K 1 Reply Last reply
                            1
                            • JonBJ JonB

                              @Ketan__Patel__0011
                              So for MinGW the #pragma comment (lib, "Ws2_32.lib") has no effect, that is why you have to add the -lWs2_32 etc. explicitly to get the link to happen. Which is just what we said --- the #pragma is for MSVC only.

                              If you read what the OP is asking you will see that are using cmake, not qmake, no .pro file. So your LIBS lines do not help them. And they are asking precisely what equivalent they have to do for cmake (which I do not know).

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

                              @JonB
                              So For CMake You can try the below code.

                              target_link_libraries(${CMAKE_PROJECT_NAME} Ws2_32)
                              target_link_libraries(${CMAKE_PROJECT_NAME} Mswsock)
                              target_link_libraries(${CMAKE_PROJECT_NAME} AdvApi32)
                              
                              Christian EhrlicherC 1 Reply Last reply
                              0
                              • Ketan__Patel__0011K Ketan__Patel__0011

                                @JonB
                                So For CMake You can try the below code.

                                target_link_libraries(${CMAKE_PROJECT_NAME} Ws2_32)
                                target_link_libraries(${CMAKE_PROJECT_NAME} Mswsock)
                                target_link_libraries(${CMAKE_PROJECT_NAME} AdvApi32)
                                
                                Christian EhrlicherC Offline
                                Christian EhrlicherC Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #29

                                @Ketan__Patel__0011 What are you discussing here? The op already used this three days ago...

                                target_link_libraries(eccoci PRIVATE 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

                                1 Reply Last reply
                                1

                                • Login

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