cmake引用abseil库
目录
描述
abseil的官方很清晰, 也支持cmake, 照着文档编写一个例子,很快就遇到问题 undefined reference to absl::str_format_internal
环境
-
git提交
编写helloword
- 下载
cd third_party
# 我测试的master分支,最后提交时间是2024-02-28
git clone https://github.com/abseil/abseil-cpp.git
- 修改cmake
set(ABSL_PROPAGATE_CXX_STD ON)
add_subdirectory(./third_party/abseil-cpp)
# 注意此处链接了str_format, 不是strings被编译成了单独库
target_link_libraries(untitled absl::str_format)
- 测试代码
#include <iostream>
#include "absl/strings/str_format.h"
using namespace std;
int main() {
string server_address = absl::StrFormat("0.0.0.0:%d", 8000);
cout <<server_address<<endl;
return 0;
}