问题
I'd like to link my application with a prebuilt gRPC 1.30.
The directory structure that I want:
- project root
- external
+ gRPC
- src
... my source code here ...
I've built gRPC:
git clone --recurse-submodules -b v1.30.0 https://github.com/grpc/grpc
cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX="D:/grpc" -A x64 ..
cmake --build . --target install --config Release
The final structure of files produced in D:/grpc
is weird... the topmost cmake folder contains protobuf-config.cmake and the grpc's one is in D:/grpc/lib/cmake/grpc. But I don't really care as long as it works.
This is in my project's CMakeLists.txt.
set(CMAKE_PREFIX_PATH ${EXTERNAL_DIRECTORY}
${EXTERNAL_DIRECTORY}/grpc/
${EXTERNAL_DIRECTORY}/grpc/cmake/
${CMAKE_PREFIX_PATH})
find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
add_executable(test main.cpp)
target_link_libraries(test PRIVATE grpc::grpc++)
And finally, this is the error that I'm getting when I try to build it:
Target "test" links to target "Threads::Threads" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
I'm stuck here.
回答1:
I simply added:
find_package(Threads REQUIRED)
来源:https://stackoverflow.com/questions/62562627/prebuilding-grpc-and-find-package