yum install mongo-c-driver
sudo yum install cmake openssl-devel cyrus-sasl-devel
$ wget https://github.com/mongodb/mongo-c-driver/releases/download/ 1.17.0 / mongo-c-driver-1.17.0.tar.gz
$ tar xzf mongo-c-driver-1.17.0.tar.gz
$ cd mongo-c-driver-1.17.0
$ mkdir cmake-build
$ cd cmake-build
$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF建議使用該選項(xiàng),請參閱初始化和清除。
另一個(gè)有用的cmake選項(xiàng)是-DCMAKE_BUILD_TYPE=Release針對發(fā)行版優(yōu)化的構(gòu)建和-DCMAKE_BUILD_TYPE=Debug調(diào)試的構(gòu)建。
有關(guān)所有配置選項(xiàng)的列表,請運(yùn)行。cmake -L ..
如果cmake成功完成,您將看到大量的輸出描述您的構(gòu)建配置。輸出的最后一行應(yīng)如下所示:
-構(gòu)建文件已寫入:/home/user/mongo-c-driver-1.17.0/cmake-build
如果您的系統(tǒng)尚未安裝libbson,則mongo-c-driver包含libbson的副本。該配置將檢測是否未安裝libbson并使用捆綁的libbson。
此外,可以通過設(shè)置以下-DENABLE_MONGOC=OFF選項(xiàng)來僅構(gòu)建libbson :
$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_MONGOC=OFF ..
構(gòu)建:
cmake --build .
$ sudo cmake --build . --target install
安裝Sphinx pip install -U Sphinx ,然后:
$ cmake -DENABLE_MAN_PAGES=ON -DENABLE_HTML_DOCS=ON ..
$ cmake --build . --target mongoc-doc
要僅構(gòu)建libbson文檔:
$ cmake -DENABLE_MAN_PAGES=ON -DENABLE_HTML_DOCS=ON ..
$ cmake --build . --target bson-doc
該-DENABLE_MAN_PAGES=ON并且-DENABLE_HTML_DOCS=ON還可以添加從發(fā)行tar包或混帳,使得文檔的同時(shí)其它部件內(nèi)置選項(xiàng),以正常體形。
卸載已安裝組件: sudo /usr/local/share/mongo-c-driver/uninstall.sh
gcc -o hello_mongoc hello_mongoc.c -I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0 -lmongoc-1.0 -lbson-1.0
./hello_mongoc
{ "ok" : 1.000000 }
=========================================================================================================
libmongoc安裝包含CMake配置文件包,因此您可以使用CMake的find_package命令導(dǎo)入libmongoc的CMake目標(biāo)并鏈接到libmongoc(作為共享庫):
的CMakeLists.txt
# Specify the minimum version you require.
find_package (mongoc-1.0 1.7 REQUIRED)
# The "hello_mongoc.c" sample program is shared among four tests.
add_executable (hello_mongoc ../../hello_mongoc.c)
target_link_libraries (hello_mongoc PRIVATE mongo::mongoc_shared)
您還可以將libmongoc用作靜態(tài)庫:使用mongo::mongoc_staticCMake目標(biāo):
# Specify the minimum version you require.
find_package (mongoc-1.0 1.7 REQUIRED)
# The "hello_mongoc.c" sample program is shared among four tests.
add_executable (hello_mongoc ../../hello_mongoc.c)
target_link_libraries (hello_mongoc PRIVATE mongo::mongoc_static)
pkg-
如果您不使用CMake,請?jiān)诿钚猩鲜褂胮kg-config設(shè)置標(biāo)頭和庫路徑:
gcc -o hello_mongoc hello_mongoc.c $(pkg-config --libs --cflags libmongoc-1.0)
或靜態(tài)鏈接到libmongoc:
gcc -o hello_mongoc hello_mongoc.c $(pkg-config --libs --cflags libmongoc-static-1.0)
指定標(biāo)題并手動(dòng)包含路徑
如果您不使用CMake或pkg-config,則可以手動(dòng)管理路徑和庫。
$ gcc -o hello_mongoc hello_mongoc.c \
-I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0 \
-lmongoc-1.0 -lbson-1.0
$ ./hello_mongoc
{ "ok" : 1.000000 }
浙公網(wǎng)安備 33010602011771號(hào)