I tried to build Qv2ray with CMake and Visual Studio on Windows and got the error:
CMake Error at cmake/backend.cmake:9 (message):
gRPC Not Found
Call Stack (most recent call first):
CMakeLists.txt:257 (include)
Check backend.cmake:
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin)
find_package(gRPC CONFIG QUIET)
# Debian, for example, cannot find gRPC in a proper way.
# This is used as a fallback searching method
if(NOT gRPC_FOUND)
if(WIN32)
message(FATAL_ERROR "gRPC Not Found")
else()
......
I've built gRPC and installed it to C:\gRPC. How can I let CMake find it? If I add
SET(gRPC_DIR "C:/gRPC/lib/cmake/grpc")
before find_package
, I got this error:
-- Could NOT find absl (missing: absl_DIR)
CMake Error at cmake/backend.cmake:9 (message):
gRPC Not Found
Call Stack (most recent call first):
CMakeLists.txt:257 (include)
If I also set absl_DIR, I got another error:
Performing C SOURCE FILE Test UV_LINT_NO_UNUSED_PARAMETER failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-ixqh17
Run Build Command(s):C:/ninja/ninja.exe cmTC_cc832 && [1/2] Building C object CMakeFiles\cmTC_cc832.dir\src.c.obj
FAILED: CMakeFiles/cmTC_cc832.dir/src.c.obj
"C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo -DUV_LINT_NO_UNUSED_PARAMETER /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 -Wno-unused-parameter /showIncludes /FoCMakeFiles\cmTC_cc832.dir\src.c.obj /FdCMakeFiles\cmTC_cc832.dir\ /FS -c C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-ixqh17\src.c
cl : Command line error D8021 : invalid numeric argument '/Wno-unused-parameter'
ninja: build stopped: subcommand failed.
Source file was:
int main(void) { return 0; }
Performing C SOURCE FILE Test UV_LINT_STRICT_PROTOTYPES failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-ckl2px
Run Build Command(s):C:/ninja/ninja.exe cmTC_54f78 && [1/2] Building C object CMakeFiles\cmTC_54f78.dir\src.c.obj
FAILED: CMakeFiles/cmTC_54f78.dir/src.c.obj
"C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo -DUV_LINT_STRICT_PROTOTYPES /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 -Wstrict-prototypes /showIncludes /FoCMakeFiles\cmTC_54f78.dir\src.c.obj /FdCMakeFiles\cmTC_54f78.dir\ /FS -c C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-ckl2px\src.c
cl : Command line error D8021 : invalid numeric argument '/Wstrict-prototypes'
ninja: build stopped: subcommand failed.
Source file was:
int main(void) { return 0; }
Performing C SOURCE FILE Test UV_LINT_EXTRA failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-oz29mu
Run Build Command(s):C:/ninja/ninja.exe cmTC_c075b && [1/2] Building C object CMakeFiles\cmTC_c075b.dir\src.c.obj
FAILED: CMakeFiles/cmTC_c075b.dir/src.c.obj
"C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo -DUV_LINT_EXTRA /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 -Wextra /showIncludes /FoCMakeFiles\cmTC_c075b.dir\src.c.obj /FdCMakeFiles\cmTC_c075b.dir\ /FS -c C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-oz29mu\src.c
cl : Command line error D8021 : invalid numeric argument '/Wextra'
ninja: build stopped: subcommand failed.
Source file was:
int main(void) { return 0; }
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-d5iufb
Run Build Command(s):C:/ninja/ninja.exe cmTC_b1e72 && [1/2] Building C object CMakeFiles\cmTC_b1e72.dir\src.c.obj
FAILED: CMakeFiles/cmTC_b1e72.dir/src.c.obj
"C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo -DCMAKE_HAVE_LIBC_PTHREAD /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\cmTC_b1e72.dir\src.c.obj /FdCMakeFiles\cmTC_b1e72.dir\ /FS -c C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-d5iufb\src.c
C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-d5iufb\src.c(1): fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory
ninja: build stopped: subcommand failed.
Source file was:
#include <pthread.h>
static void* test_func(void* data)
{
return data;
}
int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_cancel(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);
return 0;
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-cyjamz
Run Build Command(s):C:/ninja/ninja.exe cmTC_863f5 && [1/2] Building C object CMakeFiles\cmTC_863f5.dir\CheckFunctionExists.c.obj
[2/2] Linking C executable cmTC_863f5.exe
FAILED: cmTC_863f5.exe
cmd.exe /C "cd . && C:\CMake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_863f5.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- "C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe" /nologo CMakeFiles\cmTC_863f5.dir\CheckFunctionExists.c.obj /out:cmTC_863f5.exe /implib:cmTC_863f5.lib /pdb:cmTC_863f5.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console pthreads.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_863f5.dir\CheckFunctionExists.c.obj /out:cmTC_863f5.exe /implib:cmTC_863f5.lib /pdb:cmTC_863f5.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console pthreads.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_863f5.dir/intermediate.manifest CMakeFiles\cmTC_863f5.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'pthreads.lib'
ninja: build stopped: subcommand failed.
Determining if the function pthread_create exists in the pthread failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-ymkre8
Run Build Command(s):C:/ninja/ninja.exe cmTC_2ac36 && [1/2] Building C object CMakeFiles\cmTC_2ac36.dir\CheckFunctionExists.c.obj
[2/2] Linking C executable cmTC_2ac36.exe
FAILED: cmTC_2ac36.exe
cmd.exe /C "cd . && C:\CMake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_2ac36.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- "C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe" /nologo CMakeFiles\cmTC_2ac36.dir\CheckFunctionExists.c.obj /out:cmTC_2ac36.exe /implib:cmTC_2ac36.lib /pdb:cmTC_2ac36.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console pthread.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_2ac36.dir\CheckFunctionExists.c.obj /out:cmTC_2ac36.exe /implib:cmTC_2ac36.lib /pdb:cmTC_2ac36.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console pthread.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_2ac36.dir/intermediate.manifest CMakeFiles\cmTC_2ac36.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'pthread.lib'
ninja: build stopped: subcommand failed.
I downloaded pthread-win32, copied pthreadVC2.lib to pthread.lib and added the following line to CMakeLists.txt,
set (CMAKE_EXE_LINKER_FLAGS "/LIBPATH:\"C:\\pthreads-w32-2-9-1-release\\Pre-built.2\\lib\\x64\\\"")
then rebuilt but still got the error:
Performing C SOURCE FILE Test UV_LINT_NO_UNUSED_PARAMETER failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-wqbrhl
Run Build Command(s):C:/ninja/ninja.exe cmTC_7b6af && [1/2] Building C object CMakeFiles\cmTC_7b6af.dir\src.c.obj
FAILED: CMakeFiles/cmTC_7b6af.dir/src.c.obj
"C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo -DUV_LINT_NO_UNUSED_PARAMETER /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 -Wno-unused-parameter /showIncludes /FoCMakeFiles\cmTC_7b6af.dir\src.c.obj /FdCMakeFiles\cmTC_7b6af.dir\ /FS -c C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-wqbrhl\src.c
cl : Command line error D8021 : invalid numeric argument '/Wno-unused-parameter'
ninja: build stopped: subcommand failed.
Source file was:
int main(void) { return 0; }
Performing C SOURCE FILE Test UV_LINT_STRICT_PROTOTYPES failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-e8xc9e
Run Build Command(s):C:/ninja/ninja.exe cmTC_f19a7 && [1/2] Building C object CMakeFiles\cmTC_f19a7.dir\src.c.obj
FAILED: CMakeFiles/cmTC_f19a7.dir/src.c.obj
"C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo -DUV_LINT_STRICT_PROTOTYPES /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 -Wstrict-prototypes /showIncludes /FoCMakeFiles\cmTC_f19a7.dir\src.c.obj /FdCMakeFiles\cmTC_f19a7.dir\ /FS -c C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-e8xc9e\src.c
cl : Command line error D8021 : invalid numeric argument '/Wstrict-prototypes'
ninja: build stopped: subcommand failed.
Source file was:
int main(void) { return 0; }
Performing C SOURCE FILE Test UV_LINT_EXTRA failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-0dci1s
Run Build Command(s):C:/ninja/ninja.exe cmTC_33837 && [1/2] Building C object CMakeFiles\cmTC_33837.dir\src.c.obj
FAILED: CMakeFiles/cmTC_33837.dir/src.c.obj
"C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo -DUV_LINT_EXTRA /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 -Wextra /showIncludes /FoCMakeFiles\cmTC_33837.dir\src.c.obj /FdCMakeFiles\cmTC_33837.dir\ /FS -c C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-0dci1s\src.c
cl : Command line error D8021 : invalid numeric argument '/Wextra'
ninja: build stopped: subcommand failed.
Source file was:
int main(void) { return 0; }
Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-fxbu04
Run Build Command(s):C:/ninja/ninja.exe cmTC_79d11 && [1/2] Building C object CMakeFiles\cmTC_79d11.dir\src.c.obj
FAILED: CMakeFiles/cmTC_79d11.dir/src.c.obj
"C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo -DCMAKE_HAVE_LIBC_PTHREAD /DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\cmTC_79d11.dir\src.c.obj /FdCMakeFiles\cmTC_79d11.dir\ /FS -c C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-fxbu04\src.c
C:\v2ray\qv2ray\build\CMakeFiles\CMakeScratch\TryCompile-fxbu04\src.c(1): fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory
ninja: build stopped: subcommand failed.
Source file was:
#include <pthread.h>
static void* test_func(void* data)
{
return data;
}
int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_cancel(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);
return 0;
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-nnzju3
Run Build Command(s):C:/ninja/ninja.exe cmTC_1b1f1 && [1/2] Building C object CMakeFiles\cmTC_1b1f1.dir\CheckFunctionExists.c.obj
[2/2] Linking C executable cmTC_1b1f1.exe
FAILED: cmTC_1b1f1.exe
cmd.exe /C "cd . && C:\CMake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_1b1f1.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- "C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe" /nologo CMakeFiles\cmTC_1b1f1.dir\CheckFunctionExists.c.obj /out:cmTC_1b1f1.exe /implib:cmTC_1b1f1.lib /pdb:cmTC_1b1f1.pdb /version:0.0 /LIBPATH:"C:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\" /debug /INCREMENTAL /subsystem:console pthreads.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_1b1f1.dir\CheckFunctionExists.c.obj /out:cmTC_1b1f1.exe /implib:cmTC_1b1f1.lib /pdb:cmTC_1b1f1.pdb /version:0.0 /LIBPATH:C:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64" /debug /INCREMENTAL /subsystem:console pthreads.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:cmTC_1b1f1.exe.manifest" failed (exit code 1120) with the following output:
CheckFunctionExists.c.obj : error LNK2019: unresolved external symbol pthread_create referenced in function main
cmTC_1b1f1.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
Determining if the function pthread_create exists in the pthread failed with the following output:
Change Dir: C:/v2ray/qv2ray/build/CMakeFiles/CMakeScratch/TryCompile-4uqkdk
Run Build Command(s):C:/ninja/ninja.exe cmTC_12c03 && [1/2] Building C object CMakeFiles\cmTC_12c03.dir\CheckFunctionExists.c.obj
[2/2] Linking C executable cmTC_12c03.exe
FAILED: cmTC_12c03.exe
cmd.exe /C "cd . && C:\CMake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_12c03.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- "C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe" /nologo CMakeFiles\cmTC_12c03.dir\CheckFunctionExists.c.obj /out:cmTC_12c03.exe /implib:cmTC_12c03.lib /pdb:cmTC_12c03.pdb /version:0.0 /LIBPATH:"C:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\" /debug /INCREMENTAL /subsystem:console pthread.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_12c03.dir\CheckFunctionExists.c.obj /out:cmTC_12c03.exe /implib:cmTC_12c03.lib /pdb:cmTC_12c03.pdb /version:0.0 /LIBPATH:C:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64" /debug /INCREMENTAL /subsystem:console pthread.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:cmTC_12c03.exe.manifest" failed (exit code 1120) with the following output:
CheckFunctionExists.c.obj : error LNK2019: unresolved external symbol pthread_create referenced in function main
cmTC_12c03.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
The error messages in cmake build window are:
-- Found CURL: C:\curl-7.87.0-win64-mingw\lib (found version "7.87.0")
-- Found Protobuf: C:\protobuf-21.12\lib (found version "3.21.12")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
CMake Error at cmake/backend.cmake:16 (message):
gRPC Not Found
Call Stack (most recent call first):
CMakeLists.txt:257 (include)
-- Configuring incomplete, errors occurred!
See also "C:/v2ray/qv2ray/build/CMakeFiles/CMakeOutput.log".
See also "C:/v2ray/qv2ray/build/CMakeFiles/CMakeError.log".
Probably, absl_DIR and pthread are both required by gRPC. But I don't think this is the correct way to let CMake find gRPC since I can run the executables in C:\gRPC\bin\ without problem so gRPC should be able to find the components it depends automatically. What is the correct way to let CMake find gRPC?