我正在尝试在 Docker 容器中安装 mongocxx 驱动程序,第一步是使用包管理器安装 mongo-c 驱动程序。我精简的 Dockerfile:
FROM phusion/baseimage:latest
RUN apt-get install -y libmongoc-1.0-0
Run Code Online (Sandbox Code Playgroud)
在这一步之后,我应该准备好按照这里的说明安装 cxx 驱动程序:https : //mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/
RUN git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1
WORKDIR /mongo-cxx-driver/build
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
RUN make EP_mnmlstc_core
RUN make && make install
Run Code Online (Sandbox Code Playgroud)
这一直持续到 cmake 步骤失败,无法找到 libbson 包
Step 17/25 : RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
---> Running in ba6033b680bb
-- The CXX compiler identification is GNU 5.4.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working …Run Code Online (Sandbox Code Playgroud) 当尝试验证固定长度字符串数组在编译时是否已排序时,使用 时会出现奇怪的行为strncmp。
如果验证函数引用全局数组,则 N 的所有值似乎都有效。
#include <cstring>
#define N 8 // vary values of N
const char STRINGS[][N] = {"a", "b", "c"};
constexpr bool is_sorted_global() {
for (int i = 0; i < sizeof(STRINGS) / N - 1; i++) {
if (strncmp(STRINGS[i], STRINGS[i + 1], N) > 0) {
return false;
}
}
return true;
}
int main()
{
// always works for any N
static_assert(is_sorted_global(), "list is not sorted");
}
Run Code Online (Sandbox Code Playgroud)
但是,如果使用函数模板,则只有 N 小于或等于 8 的值才有效。
template<const char …Run Code Online (Sandbox Code Playgroud)