error: undefined reference to `__imp_WSAStartup'
-
@wwwsharq see cmake command target_link_libraries() to link to ws2_32
-
@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()
-
@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.
-
There is no need to search for this lib. Simply add it to target_link_libraries call
-
This post is deleted!
-
@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-Ehrlicher
current cmakecmake_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.
-
@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. -
@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. -
@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...
-
@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...
-
@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")
-
@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....
-
@JonB said in error: undefined reference to `__imp_WSAStartup':
They are not just an MSVC thing
The pragma is proprietary MSVC crap
-
@Christian-Ehrlicher I know. I was inviting @Ketan__Patel__0011 to consider his answer for the OP with MinGW in this light.
-
@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 fileLIBS += -lWs2_32 LIBS += -lMswsock LIBS += -lAdvApi32