make mongo-cxx-driver找不到包含

时间:2016-09-14 12:25:31

标签: c++ mongodb c++11 mongo-cxx-driver

我一直在尝试在OSX 10.10上为C ++ 11编译mongo-cxx-driver,但是我遇到了一些麻烦。 libbson和mongo-c-driver都已成功构建和安装,库到/ usr / local / lib,以及/usr/local/include/libbson-1.0和/usr/local/include/libmongoc-1.0的头文件分别。 我从mongo-cxx-driver / build目录成功运行了cmake,这是shell的整个输出:

~/code/cpp/mongo-cxx-driver/build  ((r3.0.1)) $> cmake -DLIBBSON_DIR=/usr/local/include/libbson-1.0 -DLIBMONGOC_DIR=/usr/local/include/libmongoc-1.0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/user/code/cpp/mongo-cxx-driver

当我在mongo-cxx-driver目录中运行make form时,出现以下错误:

...
[  4%] Building CXX object src/bsoncxx/CMakeFiles/bsoncxx.dir/array/view.cpp.o
/Users/user/code/cpp/mongo-cxx-driver/src/bsoncxx/array/view.cpp:21:10: fatal error: 'bson.h' file not
  found
#include <bson.h>
         ^
1 error generated.

显然编译器无法找到那些包含但是为什么?是不是在cmake命令行中设置了LIBBSON_DIR和LIBMONGOC_DIR?

编辑: 我使用cmake从他们的git源代码构建了C驱动程序和libbson;使; sudo make install。 今天我从头开始创建mongo-cxx驱动程序,记录所有问题。 输出后生成的mongo-cxx-driver / build中的cmake:

~/code/cpp/mongo-cxx-driver/build  (master) $> cmake ..
-- The CXX compiler identification is AppleClang 7.3.0.7030031
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- No build type selected, default is Release
-- The C compiler identification is AppleClang 7.3.0.7030031
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at cmake/FindLibBSON.cmake:38 (message):
  Don't know how to find libbson; please set LIBBSON_DIR to the prefix
   directory with which libbson was configured.
Call Stack (most recent call first):
   src/bsoncxx/CMakeLists.txt:67 (find_package)


-- Configuring incomplete, errors occurred!
See also "/Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/CMakeOutput.log".

/mongo-cxx-driver/build/CMakeFiles/CMakeOutput.log中来自cmake的日志包含(仅显示C ++ 11相关的严重性行):

The system is: Darwin - 15.6.0 - x86_64
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ 
Build flags: 
Id flags: 

The output was:
0


Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"

The CXX compiler identification is AppleClang, found in "/Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/3.6.2/CompilerIdCXX/a.out"

Determining if the CXX compiler works passed with the following output:
Change Dir: /Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_1ae1a/fast"
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_1ae1a.dir/build.make CMakeFiles/cmTC_1ae1a.dir/build
Building CXX object CMakeFiles/cmTC_1ae1a.dir/testCXXCompiler.cxx.o
/Library/Developer/CommandLineTools/usr/bin/c++      -o CMakeFiles/cmTC_1ae1a.dir/testCXXCompiler.cxx.o -c /Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_1ae1a
/usr/local/Cellar/cmake/3.6.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_1ae1a.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/c++     -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/cmTC_1ae1a.dir/testCXXCompiler.cxx.o  -o cmTC_1ae1a  


Detecting CXX compiler ABI info compiled with the following output:
Change Dir: /Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_34702/fast"
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_34702.dir/build.make CMakeFiles/cmTC_34702.dir/build
Building CXX object CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o
/Library/Developer/CommandLineTools/usr/bin/c++      -o CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o -c /usr/local/Cellar/cmake/3.6.2/share/cmake/Modules/CMakeCXXCompilerABI.cpp
Linking CXX executable cmTC_34702
/usr/local/Cellar/cmake/3.6.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_34702.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/c++     -Wl,-search_paths_first -Wl,-headerpad_max_install_names  -v -Wl,-v CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o  -o cmTC_34702   
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o cmTC_34702 -search_paths_first -headerpad_max_install_names -v CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o -lc++ -lSystem /Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a
@(#)PROGRAM:ld  PROJECT:ld64-264.3.102
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
    /usr/lib
    /usr/local/lib
Framework search paths:
    /Library/Frameworks/
    /System/Library/Frameworks/


Parsed CXX implicit link information from above output:
  link line regex: [^( *|.*[/\])(ld|([^/\]+-)?ld|collect2)[^/\]*( |$)]
  ignore line: [Change Dir: /Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/CMakeTmp]
  ignore line: []
  ignore line: [Run Build Command:"/usr/bin/make" "cmTC_34702/fast"]
  ignore line: [/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_34702.dir/build.make CMakeFiles/cmTC_34702.dir/build]
  ignore line: [Building CXX object CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o]
  ignore line: [/Library/Developer/CommandLineTools/usr/bin/c++      -o CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o -c /usr/local/Cellar/cmake/3.6.2/share/cmake/Modules/CMakeCXXCompilerABI.cpp]
  ignore line: [Linking CXX executable cmTC_34702]
  ignore line: [/usr/local/Cellar/cmake/3.6.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_34702.dir/link.txt --verbose=1]
  ignore line: [/Library/Developer/CommandLineTools/usr/bin/c++     -Wl,-search_paths_first -Wl,-headerpad_max_install_names  -v -Wl,-v CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o  -o cmTC_34702   ]
  ignore line: [Apple LLVM version 7.3.0 (clang-703.0.31)]
  ignore line: [Target: x86_64-apple-darwin15.6.0]
  ignore line: [Thread model: posix]
  ignore line: [InstalledDir: /Library/Developer/CommandLineTools/usr/bin]
  link line: [ "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o cmTC_34702 -search_paths_first -headerpad_max_install_names -v CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o -lc++ -lSystem /Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a]
    arg [/Library/Developer/CommandLineTools/usr/bin/ld] ==> ignore
    arg [-demangle] ==> ignore
    arg [-dynamic] ==> ignore
    arg [-arch] ==> ignore
    arg [x86_64] ==> ignore
    arg [-macosx_version_min] ==> ignore
    arg [10.11.0] ==> ignore
    arg [-o] ==> ignore
    arg [cmTC_34702] ==> ignore
    arg [-search_paths_first] ==> ignore
    arg [-headerpad_max_install_names] ==> ignore
    arg [-v] ==> ignore
    arg [CMakeFiles/cmTC_34702.dir/CMakeCXXCompilerABI.cpp.o] ==> ignore
    arg [-lc++] ==> lib [c++]
    arg [-lSystem] ==> lib [System]
    arg [/Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a] ==> lib [/Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a]
  Library search paths: [;/usr/lib;/usr/local/lib]
  Framework search paths: [;/Library/Frameworks/;/System/Library/Frameworks/]
  remove lib [System]
  collapse lib [/Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a] ==> [/Library/Developer/CommandLineTools/usr/lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a]
  collapse library dir [/usr/lib] ==> [/usr/lib]
  collapse library dir [/usr/local/lib] ==> [/usr/local/lib]
  collapse framework dir [/Library/Frameworks/] ==> [/Library/Frameworks]
  collapse framework dir [/System/Library/Frameworks/] ==> [/System/Library/Frameworks]
  implicit libs: [c++;/Library/Developer/CommandLineTools/usr/lib/clang/7.3.0/lib/darwin/libclang_rt.osx.a]
  implicit dirs: [/usr/lib;/usr/local/lib]
  implicit fwks: [/Library/Frameworks;/System/Library/Frameworks]

Detecting CXX [-std=c++11] compiler features compiled with the following output:
Change Dir: /Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_a8d63/fast"
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_a8d63.dir/build.make CMakeFiles/cmTC_a8d63.dir/build
Building CXX object CMakeFiles/cmTC_a8d63.dir/feature_tests.cxx.o
/Library/Developer/CommandLineTools/usr/bin/c++     -std=c++11 -o CMakeFiles/cmTC_a8d63.dir/feature_tests.cxx.o -c /Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/feature_tests.cxx
Linking CXX executable cmTC_a8d63
/usr/local/Cellar/cmake/3.6.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a8d63.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/c++     -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/cmTC_a8d63.dir/feature_tests.cxx.o  -o cmTC_a8d63  


    Feature record: CXX_FEATURE:0cxx_aggregate_default_initializers
    ...
    Feature record: CXX_FEATURE:1cxx_variadic_templates

Detecting C [-std=c11] compiler features compiled with the following output:
Change Dir: /Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_9a269/fast"
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_9a269.dir/build.make CMakeFiles/cmTC_9a269.dir/build
Building C object CMakeFiles/cmTC_9a269.dir/feature_tests.c.o
/Library/Developer/CommandLineTools/usr/bin/cc    -std=c11 -o CMakeFiles/cmTC_9a269.dir/feature_tests.c.o   -c /Users/user/code/cpp/mongo-cxx-driver/build/CMakeFiles/feature_tests.c
Linking C executable cmTC_9a269
/usr/local/Cellar/cmake/3.6.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9a269.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/cc    -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/cmTC_9a269.dir/feature_tests.c.o  -o cmTC_9a269  


    Feature record: C_FEATURE:1c_function_prototypes
    Feature record: C_FEATURE:1c_restrict
    Feature record: C_FEATURE:1c_static_assert
    Feature record: C_FEATURE:1c_variadic_macros

(如果需要其他线路,我很乐意发送它们)。 ls / usr / local / lib / pkgconfig显示以下内容:

lcms2.pc        libbson-1.0.pc      libmongoc-1.0.pc    libmongoc-ssl-1.0.pc    libtiff-4.pc        mysqlclient.pc

1 个答案:

答案 0 :(得分:1)

发现问题。 @acm要求显示我试图做的pkg-config --cflags --libs libmongoc-1.0 libbson-1.0的输出:

~/code/cpp/mongo-cxx-driver/build  (master) $> pkg-config --cflags --libs libmongoc-1.0 libbson-1.0
-bash: pkg-config: command not found

显然没有安装pkg-config。稍后通过自制软件快速安装,我运行同一行并得到:

~/code/cpp/mongo-cxx-driver/build  (master) $> pkg-config --cflags --libs libmongoc-1.0 libbson-1.0
-I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0 -L/usr/local/lib -lmongoc-1.0 -lbson-1.0

之后,cmake运行得很好,并且也做了。

感谢您的帮助: - )