DECLSPEC_IMPORT make all curl_cv_func_recv_test Failed when building in windows · Issue #4764 · curl/curl · GitHub
Skip to content You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert DECLSPEC_IMPORT make all curl_cv_func_recv_test Failed when building in windows #4764 New issue Copy link New issue Copy link Closed Closed DECLSPEC_IMPORT make all curl_cv_func_recv_test Failed when building in windows #4764 Copy link Labels build cmake Description Ron2014 opened on Dec 27, 2019 Issue body actions When I built curl in my project, I found all the recv_test/send_test failed.
But I can build successfully in curl-curl-7-67-0.git. So I message something in OtherTests.cmake and CheckCSourceCompiles.cmake to check what's the different between these two project. And I found this: -- Performing Test curl_cv_func_recv_test ====== CMAKE_BINARY_DIR = E:/TestCode/curl-curl-7_67_0/build ====== CMAKE_FILES_DIRECTORY = /CMakeFiles ====== CMAKE_REQUIRED_DEFINITIONS = -D_WINSOCKAPI_= -DSECURITY_WIN32 ====== CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS = ====== CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES = LINK_LIBRARIES;ws2_32 ====== MACRO_CHECK_FUNCTION_DEFINITIONS = -Dcurl_cv_func_recv_test ====== CHECK_C_SOURCE_COMPILES_ADD_INCLUDES = -DINCLUDE_DIRECTORIES:STRING=E:/TestCode/curl-curl-7_67_0/include ====== COMPILE_DEFINITIONS = ====== CMAKE_FLAGS = ====== _FAIL_REGEX = ====== OUTPUT = Change Dir: E:/TestCode/curl-curl-7_67_0/build/CMakeFiles/CMakeTmp Run Build Command(s):D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe cmTC_8df82.vcxproj /p:Configuration=Debug /p:Platform=Win32 /p:VisualStudioVersion=15.0 /v:m && Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework Copyright (C) Microsoft Corporation.
All rights reserved. Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27034 for x86 Copyright (C) Microsoft Corporation. All rights reserved. cl /c /I"E:\TestCode\curl-curl-7_67_0\include" /Zi /W3 /WX- /diagnostics:classic /Od /Ob0 /Oy- /D WIN32 /D _WINDOWS /D curl_cv_func_recv_test /D _WINSOCKAPI_= /D SECURITY_WIN32 /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_8df82.dir\Debug\\" /Fd"cmTC_8df82.dir\Debug\cmTC_8df82.pdb" /Gd /TC /analyze- /errorReport:queue "E:\TestCode\curl-curl-7_67_0\build\CMakeFiles\CMakeTmp\src.c" src.c E:\TestCode\curl-curl-7_67_0\build\CMakeFiles\CMakeTmp\src.c(10): warning C4273: 'recv': inconsistent dll linkage [E:\TestCode\curl-curl-7_67_0\build\CMakeFiles\CMakeTmp\cmTC_8df82.vcxproj] D:\Windows Kits\10\Include\10.0.17763.0\um\winsock2.h(2002): note: see previous definition of 'recv' cmTC_8df82.vcxproj -> E:\TestCode\curl-curl-7_67_0\build\CMakeFiles\CMakeTmp\Debug\cmTC_8df82.lib -- Performing Test curl_cv_func_recv_test - Success -- Tested: int recv(SOCKET, char *, int, int) in curl-curl-7-67-0.git, recv can be tested successfully but with an warning, and in my project, treat warning as error, so all recv test failed.
To fix this waning, I check the WinSock2.h and found that function recv/send have WINSOCK_API_LINKAGE description like this: #if INCL_WINSOCK_API_PROTOTYPES WINSOCK_API_LINKAGE int WSAAPI recv( _In_ SOCKET s, _Out_writes_bytes_to_(len, return) __out_data_source(NETWORK) char FAR * buf, _In_ int len, _In_ int flags ); #endif /* INCL_WINSOCK_API_PROTOTYPES */ and then I found WINSOCK_API_LINKAGE == DECLSPEC_IMPORT == __declspec (dllimport) BUT, we don't need anything in front of the function recv/send, RIGHT? so I change OtherTests.cmake to: macro(add_header_include check header) if(${check}) set(_source_epilogue "${_source_epilogue}\n#define DECLSPEC_IMPORT\n#include <${header}>") endif() endmacro() build again and no warning.
SO I recommend this change. Did anybody deal with the same problem? Activity jay commented on Dec 28, 2019 jay on Dec 28, 2019 Member More actions I don't have that problem. This computer has an old version of Visual Studio but I used a recent cmake, cmake-3.15.5-win64-x64.msi. Try from scratch. mkdir X:\j\curl\cmake\cmake cd /d X:\j\curl\cmake\cmake set PATH=X:\j\curl\cmake\cmake\src\Debug;X:\j\curl\cmake\cmake\lib\Debug;X:\j\curl\cmake\openssl\bin;%PATH% cmake ..\..\curl -G "Visual Studio 10" -DCMAKE_USE_OPENSSL=ON -DOPENSSL_ROOT_DIR=X:\j\curl\cmake\openssl -DBUILD_TESTING=OFF -DCURL_ZLIB=OFF -DENABLE_THREADED_RESOLVER=ON -DCMAKE_INSTALL_PREFIX:PATH=X:\j\curl\cmake\curl-install-dir -- Performing Test curl_cv_recv -- Performing Test curl_cv_recv - Success -- Performing Test curl_cv_func_recv_test -- Performing Test curl_cv_func_recv_test - Success -- Tested: int recv(SOCKET, char *, int, int) -- Performing Test curl_cv_send -- Performing Test curl_cv_send - Success -- Performing Test curl_cv_func_send_test -- Performing Test curl_cv_func_send_test - Success -- Tested: int send(SOCKET, const char *, int, int) jay added cmake on Dec 28, 2019 Ron2014 commented on Dec 28, 2019 Ron2014 on Dec 28, 2019 Author More actions I don't have that problem.
This computer has an old version of Visual Studio but I used a recent cmake, cmake-3.15.5-win64-x64.msi. Try from scratch. mkdir X:\j\curl\cmake\cmake cd /d X:\j\curl\cmake\cmake set PATH=X:\j\curl\cmake\cmake\src\Debug;X:\j\curl\cmake\cmake\lib\Debug;X:\j\curl\cmake\openssl\bin;%PATH% cmake ..\..\curl -G "Visual Studio 10" -DCMAKE_USE_OPENSSL=ON -DOPENSSL_ROOT_DIR=X:\j\curl\cmake\openssl -DBUILD_TESTING=OFF -DCURL_ZLIB=OFF -DENABLE_THREADED_RESOLVER=ON -DCMAKE_INSTALL_PREFIX:PATH=X:\j\curl\cmake\curl-install-dir -- Performing Test curl_cv_recv -- Performing Test curl_cv_recv - Success -- Performing Test curl_cv_func_recv_test -- Performing Test curl_cv_func_recv_test - Success -- Tested: int recv(SOCKET, char *, int, int) -- Performing Test curl_cv_send -- Performing Test curl_cv_send - Success -- Performing Test curl_cv_func_send_test -- Performing Test curl_cv_func_send_test - Success -- Tested: int send(SOCKET, const char *, int, int) Let me explain it.
I treat warning as error in my project. That the key. Which means I use /WX in MSVC like this: set(CMAKE_C_FLAGS "/MP /WX /TC /errorReport:queue /DWIN32") What made me test recv failed is the warning C4273. Generally, the warning isn't printed. Why I can get this warning printed, like this----- ====== OUTPUT = Change Dir: E:/TestCode/curl-curl-7_67_0/build/CMakeFiles/CMakeTmp Run Build Command(s):D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe cmTC_8df82.vcxproj /p:Configuration=Debug /p:Platform=Win32 /p:VisualStudioVersion=15.0 /v:m && Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework Copyright (C) Microsoft Corporation.
All rights reserved. Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27034 for x86 Copyright (C) Microsoft Corporation. All rights reserved. cl /c /I"E:\TestCode\curl-curl-7_67_0\include" /Zi /W3 /WX- /diagnostics:classic /Od /Ob0 /Oy- /D WIN32 /D _WINDOWS /D curl_cv_func_recv_test /D _WINSOCKAPI_= /D SECURITY_WIN32 /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_8df82.dir\Debug\\" /Fd"cmTC_8df82.dir\Debug\cmTC_8df82.pdb" /Gd /TC /analyze- /errorReport:queue "E:\TestCode\curl-curl-7_67_0\build\CMakeFiles\CMakeTmp\src.c" src.c E:\TestCode\curl-curl-7_67_0\build\CMakeFiles\CMakeTmp\src.c(10): warning C4273: 'recv': inconsistent dll linkage [E:\TestCode\curl-curl-7_67_0\build\CMakeFiles\CMakeTmp\cmTC_8df82.vcxproj] D:\Windows Kits\10\Include\10.0.17763.0\um\winsock2.h(2002): note: see previous definition of 'recv' cmTC_8df82.vcxproj -> E:\TestCode\curl-curl-7_67_0\build\CMakeFiles\CMakeTmp\Debug\cmTC_8df82.lib Because I used Everything to find the file CheckCSourceCompiles.cmake in my cmake installation path which defined macro check_c_source_compiles you used in OtherTests.cmake. like include(CheckCSourceCompiles) .
I added a message here and see the content of ${O
The rest of this page is on the live site.