I have an application that link against another library that uses GRPC. If I use make
I can link it using pkg-config --libs protobuf grpc++ grpc
and it works. But I am upgrading to cmake
(in addition to vcpkg
) and now when I try to link my app against that library. When I do that, I get myriad linking errors
In function `absl::lts_20220623::MutexLock::MutexLock(absl::lts_20220623::Mutex*)':
[build] (.text._ZN4absl12lts_202206239MutexLockC2EPNS0_5MutexE[_ZN4absl12lts_202206239MutexLockC5EPNS0_5MutexE]+0x26): undefined reference to `absl::lts_20220623::Mutex::Lock()'
I can make that go away by adding the flags to the target_link_libraries
like so
target_include_directories(
....
/workspace/third_party/centos/grpc_1480/lib
....
)
target_link_libraries(kv-validation_lib PRIVATE fmt::fmt
libkv.a
libkvproto.a
yaml-cpp
-lpthread
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF}
stdc++fs
<pkg-config --libs protobuf grpc++ grpc GOES HERE AND FIXES IT>
)
But obviously, that's more like a hack. So, my question is how do I tell cmake to link against libraries that exists in a give location. Is there a FLAG that I can pass it to ${_ABSL}
? Should I be using some cmake function to use the pkgconfig files? How?
If you can't tell, I a new to cmake. Thanks!
I tried using some flags like ${ABSL} but that didn't work. Looked at: How to link app against a library that depends on another library? What is the proper way to use `pkg-config` from `cmake`? Using a C++17 library against a C++11 application