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?
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:
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:
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:
build again and no warning. SO I recommend this change.
Did anybody deal with the same problem?