C/C++




Protobuf

# ubuntu install protobuf
sudo apt-get install  libprotobuf-dev
sudo apt-get install protobuf-compiler

#
g++ write.cpp addressbook.pb.cc  -o write `pkg-config --cflags --libs protobuf`
g++ read.cpp  addressbook.pb.cc  -o read  `pkg-config --cflags --libs protobuf`
SRC_DIR:=../../proto
DST_DIR:=.
all:
        protoc -I=${SRC_DIR} --cpp_out=${DST_DIR}    ${SRC_DIR}/gps_path_tracking.proto
        protoc -I=${SRC_DIR} --python_out=${DST_DIR} ${SRC_DIR}/gps_path_tracking.proto
# Qt .pro add this line
unix|win32: LIBS += -pthread -lprotobuf -pthread -lpthread

boost

sudo apt-get install libboost-all-dev

g++ test.cpp -lboost_system -lboost_filesystem

C/C++编译器的预定义宏

#include <stdio.h>


#define PT_MAKE_STR(x)      { #x, PT_MAKE_STR_ESC(x) }
#define PT_MAKE_STR_ESC(x)    #x


typedef struct
{
        const char *name;
        const char *value;
} MACRO_T;


/* Compilers */const MACRO_T g_compilers[ ] =
{
#ifdef __INTEL_COMPILER        /* Interl C++ */
        PT_MAKE_STR( __INTEL_COMPILER ),
#endif

#ifdef _MSC_VER                        /* Visual C++ */
        PT_MAKE_STR( _MSC_VER ),
#endif

#ifdef __GNUC__                        /* GCC */
        PT_MAKE_STR( __GNUC__ ),
#endif

#ifdef __DMC__                        /* DMC++ */
        PT_MAKE_STR( __DMC__ ),
#endif

#ifdef __ARMCC_VERSION        /* ARM C/C++ */
        PT_MAKE_STR( __ARMCC_VERSION ),
#endif
};


/* Operation system */const MACRO_T g_platforms[ ] =
{

#ifdef __i386__
        PT_MAKE_STR(__i386__),
#endif

#ifdef __x86_64__
        PT_MAKE_STR(__x86_64__),
#endif

#ifdef __AMD64__
        PT_MAKE_STR(__AMD64__),
#endif

#ifdef __amd64__
        PT_MAKE_STR(__amd64__),
#endif

#ifdef __ia64__
        PT_MAKE_STR(__ia64__),
#endif

#ifdef __alpha__
        PT_MAKE_STR(__alpha__),
#endif

#ifdef __arm__
        PT_MAKE_STR(__arm__),
#endif

#ifdef __sparc__
        PT_MAKE_STR(__sparc__),
#endif

#ifdef __arch64__
        PT_MAKE_STR(__arch64__),
#endif

#ifdef __aarch64__
        PT_MAKE_STR( __aarch64__ ),
#endif

#ifdef __powerpc__
        PT_MAKE_STR(__powerpc__),
#endif

#ifdef __powerpc64__
        PT_MAKE_STR(__powerpc64__),
#endif

#ifdef __ppc__
        PT_MAKE_STR(__ppc__),
#endif

#ifdef __ppc64__
        PT_MAKE_STR(__ppc64__),
#endif

#ifdef _WIN32                        /* Windows 32 or Windows 64 */
        PT_MAKE_STR( _WIN32 ),
#endif

#ifdef _WIN64                        /* Windows 64 */
        PT_MAKE_STR( _WIN64 ),
#endif

#ifdef __MINGW32__                /* Windows32 by mingw compiler */
        PT_MAKE_STR( __MINGW32__ ),
#endif

#ifdef __CYGWIN__                /* Cygwin */
        PT_MAKE_STR( __CYGWIN__ ),
#endif

#ifdef __linux__                /* linux */
        PT_MAKE_STR( __linux__ ),
#endif

#ifdef __FreeBSD__                /* FreeBSD */
        PT_MAKE_STR( __FreeBSD__ ),
#endif

#ifdef __NetBSD__                /* NetBSD */
        PT_MAKE_STR( __NetBSD__ ),
#endif

#ifdef __OpenBSD__                /* OpenBSD */
        PT_MAKE_STR( __OpenBSD__ ),
#endif

#ifdef __sun__                /* Sun OS */
        PT_MAKE_STR( __sun__ ),
#endif

#ifdef __MaxOSX__                /* MAC OS X */
        PT_MAKE_STR( __MaxOSX__ ),
#endif

#ifdef __unix__                        /* unix */
        PT_MAKE_STR( __unix__ ),
#endif
};


/* Other useful */const MACRO_T g_others[ ] =
{
#ifdef __DATE__
        PT_MAKE_STR( __DATE__ ),
#endif

#ifdef __TIME__
        PT_MAKE_STR( __TIME__ ),
#endif

#ifdef _BSD_SOURCE
        PT_MAKE_STR( _BSD_SOURCE ),
#endif

#ifdef _POSIX_SOURCE
        PT_MAKE_STR( _POSIX_SOURCE ),
#endif

#ifdef _XOPEN_SOURCE
        PT_MAKE_STR( _XOPEN_SOURCE ),
#endif

#ifdef _GNU_SOURCE
        PT_MAKE_STR( _GNU_SOURCE ),
#endif

#ifdef __GNUC_MINOR__
        PT_MAKE_STR( __GNUC_MINOR__ ),
#endif

#ifdef __VERSION__
        PT_MAKE_STR( __VERSION__ ),
#endif

#ifdef __unix
        PT_MAKE_STR( __unix ),
#endif

};



int main( int argc, char **argv )
{
        int i;

        printf( "/* Compiler definitions. */\n" );
        for( i = 0; i < sizeof( g_compilers ) / sizeof( g_compilers[ 0 ] ); ++i )
        {
                printf( "#define %s %s\n", g_compilers[ i ].name, g_compilers[ i ].value );
        }
        printf( "\n" );

        printf( "/* Platform definitions. */\n" );
        for( i = 0; i < sizeof( g_platforms ) / sizeof( g_platforms[ 0 ] ); ++i )
        {
                printf( "#define %s %s\n", g_platforms[ i ].name, g_platforms[ i ].value );
        }
        printf( "\n" );

        printf( "/* Other definitions. */\n" );
        for( i = 0; i < sizeof( g_others ) / sizeof( g_others[ 0 ] ); ++i )
        {
                printf( "#define %s %s\n", g_others[ i ].name, g_others[ i ].value );
        }
        printf( "\n" );

        return 0;
}

GeographicLib

// main.cpp
#include <iostream>
#include <exception>
#include <cmath>
#include <GeographicLib/Geocentric.hpp>
#include <GeographicLib/LocalCartesian.hpp>

#include <iomanip>

using namespace std;
using namespace GeographicLib;
int main() {
    cout<<setiosflags(ios::fixed)<<setiosflags(ios::right)<<setprecision(8); //输出一个右对齐的小数点后两位的浮点数。
  try {
    Geocentric earth(Constants::WGS84_a(), Constants::WGS84_f());
    // Alternatively: const Geocentric& earth = Geocentric::WGS84();
    const double lat0 = 48 + 50/60.0, lon0 = 2 + 20/60.0; // Paris
    LocalCartesian proj(lat0, lon0, 0, earth);
    {
      // Sample forward calculation
      double lat = 50.9, lon = 1.8, h = 0; // Calais
      double x, y, z;
      proj.Forward(lat, lon, h, x, y, z);
      cout << x << " " << y << " " << z << "\n";
    }
    {
      // Sample reverse calculation
      double x = -38e3, y = 230e3, z = -4e3;
      double lat, lon, h;
      proj.Reverse(x, y, z, lat, lon, h);
      cout << lat << " " << lon << " " << h << "\n";
    }
  }
  catch (const exception& e) {
    cerr << "Caught exception: " << e.what() << "\n";
    return 1;
  }
}
apt-get install libgeographic-dev

g++ main.cpp `pkg-config --cflags --libs geographiclib`
# CMakeLists.txt

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(localCartesian_test LANGUAGES CXX)

#find_package(PkgConfig REQUIRED)
include(FindPkgConfig)

#pkg_search_module(GEOGRAPHICLIB REQUIRED IMPORTED_TARGET geographiclib>=1.49) # 检查包并使用第一个可用包
pkg_check_modules(GEOGRAPHICLIB REQUIRED IMPORTED_TARGET geographiclib>=1.49)  # 检查所有相应的包


#include_directories(${GEOGRAPHICLIB_INCLUDE_DIRS})
include_directories(PkgConfig::GEOGRAPHICLIB)

add_executable(${PROJECT_NAME} main.cpp)

#target_link_libraries(${PROJECT_NAME}  ${GEOGRAPHICLIB_LIBRARIES})
target_link_libraries(${PROJECT_NAME}  PkgConfig::GEOGRAPHICLIB)

UTF-8是一种变长字节编码方式。
对于某一个字符的UTF-8编码,如果只有一个字节则其最高二进制位为0;
如果是多字节,其第一个字节从最高位开始,连续的二进制位值为1的个数决定了其编码的位数,
其余各字节均以10开头。UTF-8最多可用到6个字节。

如表:


1字节 0xxxxxxx
2字节 110xxxxx 10xxxxxx
3字节 1110xxxx 10xxxxxx 10xxxxxx
4字节 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
5字节 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
6字节 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx

因此UTF-8中可以用来表示字符编码的实际位数最多有31位,即上表中x所表示的位。
除去那些控制位(每字节开头的10等),这些x表示的位与UNICODE编码是一一对应的,位高低顺序也相同。
实际将UNICODE转换为UTF-8编码时应先去除高位0,然后根据所剩编码的位数决定所需最小的UTF-8编码位数。
因此那些基本ASCII字符集中的字符(UNICODE兼容ASCII)只需要一个字节的UTF-8编码(7个二进制位)便可以表示

gcc

  • -Wno-unused-function: 发现不使用的函数不警告
  • 全局环境变量( C_INCLUDE_PATH / CPLUS_INCLUDE_PATH )添加自定义的头文件路径
  • -rpath: 用于指定运行动时态库搜索路径