libmkl 学习笔记
1.libkml下载地址为:
https://github.com/libkml/libkml/releases
这里下载1.3.0版本
2.编译与安装
mkdir build
cd build
cmake ..
make
make install
如果想生成动态库,需要将CMakeLists.txt中第20行
option(BUILD_SHARED_LIBS "Build shared libs." ON)
改成
option(BUILD_SHARED_LIBS "Build shared libs." OFF)
3.测试程序
新建一个test.cpp,代码如下:
// parsekml.cc
// This program parses a KML Placemark from a memory buffer and prints
// the value of the <name> element on standard output.
#include <iostream>
#include <string>
#include "kml/dom.h" // The KML DOM header.
int main() {
// Parse KML from a memory buffer.
std::string errors;
kmldom::ElementPtr element = kmldom::Parse(
"<kml>"
"<Placemark>"
"<name>hi</name>"
"<Point>"
"<coordinates>1,2,3</coordinates>"
"</Point>"
"</Placemark>"
"</kml>",
&errors);
// Convert the type of the root element of the parse.
const kmldom::KmlPtr kml = kmldom::AsKml(element);
const kmldom::PlacemarkPtr placemark =
kmldom::AsPlacemark(kml->get_feature());
// Access the value of the <name> element.
std::cout << "The Placemark name is: " << placemark->get_name()
<< std::endl;
}
与test.cpp同目录,新建一个CMakeLists.txt,内容如下:
cmake_minimum_required (VERSION 3.0)
set(PROJECT_NAME libkmltest)
project (${PROJECT_NAME})
set (CPACK_PACKAGE_NAME ${PROJECT_NAME})
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "")
# same as gcc -I
include_directories(
"/usr/local/include/"
)
link_directories("/usr/local/lib/")
# used for output
set (PUBLIC_H
# ${PROJECT_ROOT_PATH}/3rd_party/ros/xmlrpcpp/include/XmlRpcValue.h
)
# sources for create target
set (SRCS
test1.cpp
)
# compile
add_compile_options ($<$<BOOL:${HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS}>:-Wno-unnamed-type-template-args>)
add_executable (${PROJECT_NAME}
${SRCS}
)
target_link_libraries(${PROJECT_NAME} kmlbase kmlconvenience kmldom kmlengine kmlregionator kmlxsd)
然后执行如下代码:
mkdir build
cd build
cmake ..
make
再执行程序就可以看到测试结果
参考链接:
https://github.com/libkml/libkml/blob/wiki/QuickStart.md