Water's Home

Just another Life Style

0%

CMakeLists.txt

cmake_minimum_required(VERSION 3.12)
project(network_information)

SET(CMAKE_SYSTEM_NAME Linux)

add_definitions(“-std=c++17”)

specify the cross compiler

SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)

if(${CMAKE_HOST_SYSTEM_NAME} MATCHES “Windows”)
set(BOOST_ROOT “C:/MinGW/msys/1.0/home/d/boost_1_68_0”)
else()
set(BOOST_ROOT /root/Downloads/boost_1_68_0)
endif()

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

include_directories(sdk/inc)
link_directories(“sdk/lib”)

add_executable(network_information
network_information.cpp
)
TARGET_LINK_LIBRARIES(network_information “-lpthread” “-ldl” “-lpos” “-lrt” “-lpng” “-liconv” “-lfreetype” “-lz”)

GNUlinux_config.cmake

set(GNULINUX_PLATFORM ON)
set(CMAKE_SYSTEM_NAME “Linux”)
set(CMAKE_SYSTEM_PROCESSOR “arm”)

if(NOT DEFINED ENV{NE10_LINUX_TARGET_ARCH})
set(NE10_LINUX_TARGET_ARCH “armv7”)
else()
set(NE10_LINUX_TARGET_ARCH $ENV{NE10_LINUX_TARGET_ARCH})
endif()

if(NE10_LINUX_TARGET_ARCH STREQUAL “armv7”)
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
set(CMAKE_ASM_COMPILER arm-linux-gnueabihf-as)
find_program(CMAKE_AR NAMES “arm-linux-gnueabihf-ar”)
find_program(CMAKE_RANLIB NAMES “arm-linux-gnueabihf-ranlib”)
elseif(NE10_LINUX_TARGET_ARCH STREQUAL “aarch64”)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_ASM_COMPILER aarch64-linux-gnu-as)
find_program(CMAKE_AR NAMES “aarch64-linux-gnu-ar”)
find_program(CMAKE_RANLIB NAMES “aarch64-linux-gnu-ranlib”)
endif()

mark_as_advanced(CMAKE_AR)
mark_as_advanced(CMAKE_RANLIB)

CMakeSettings.json

{
“configurations”: [
{
“environments”: [
{
“MINGW64_ROOT”: “C:\\MinGW\\msys\\1.0\\home\\d\\gcc-linaro-7.3.1-2018.05-i686-mingw32_arm-linux-gnueabihf”,
“BIN_ROOT”: “${env.MINGW64_ROOT}\\bin”,
“FLAVOR”: “x86_64-w64-mingw32”,
“TOOLSET_VERSION”: “7.3.0”,
“PATH”: “${env.MINGW64_ROOT}\\bin;${env.MINGW64_ROOT}\\..\\usr\\local\\bin;${env.MINGW64_ROOT}\\..\\usr\\bin;${env.MINGW64_ROOT}\\..\\bin;${env.PATH}”,
“INCLUDE”: “${env.INCLUDE};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\tr1;${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\${env.FLAVOR}”,
“environment”: “mingw_64”
}
],
“name”: “Mingw64-Release”,
“generator”: “Ninja”,
“configurationType”: “Release”,
“inheritEnvironments”: [
“mingw_64”
],
“buildRoot”: “${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}”,
“installRoot”: “${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}”,
“cmakeCommandArgs”: “”,
“buildCommandArgs”: “-v”,
“ctestCommandArgs”: “”,
“intelliSenseMode”: “linux-gcc-x64”,
“variables”: [
{
“name”: “CMAKE_TOOLCHAIN_FILE”,
“value”: “GNUlinux_config.cmake”
},
{
“name”: “CMAKE_C_COMPILER”,
“value”: “${env.BIN_ROOT}\\arm-linux-gnueabihf-gcc.exe”
},
{
“name”: “CMAKE_CXX_COMPILER”,
“value”: “${env.BIN_ROOT}\\arm-linux-gnueabihf-g++.exe”
}
]
}
]
}

zlib

tar xvf zlib-1.2.11.tar.xz
cd zlib-1.2.11/
./configure –prefix=/root/Downloads/sftp-server/rootfs

[root@localhost zlib-1.2.11]# diff Makefile Makefile_bak
19c19
< CC=arm-linux-gnueabihf-gcc


CC=gcc
30,31c30,31
< LDSHARED=arm-linux-gnueabihf-gcc -shared -Wl,-soname,libz.so.1,–version-script,zlib.map
< CPP=arm-linux-gnueabihf-gcc -E


LDSHARED=gcc -shared -Wl,-soname,libz.so.1,–version-script,zlib.map
CPP=gcc -E
39c39
< AR=arm-linux-gnueabihf-ar


AR=ar
41c41
< RANLIB=arm-linux-gnueabihf-ranlib


RANLIB=ranlib

make
make install

openssh

tar xzf openssh-6.9p1.tar.gz
cd openssh-6.9p1/
./configure –prefix= –host=arm-linux-gnueabihf –sysconfdir=/etc –with-zlib=/root/Downloads/sftp-server/rootfs
make sftp-server

[root@localhost openssh-6.9p1]# file sftp-server
sftp-server: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, BuildID[sha1]=3f3bb0178b0e2ff2e27553e4754bd58d78dffd4d, not stripped

CMakeLists.txt

cmake_minimum_required(VERSION 3.12)
project(untitled1)

SET(CMAKE_SYSTEM_NAME Linux)

add_definitions(“-std=c++17”)

SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)

if(${CMAKE_HOST_SYSTEM_NAME} MATCHES “Windows”)
set(BOOST_ROOT “C:/MinGW/msys/1.0/home/d/boost_1_68_0”)
else()
set(BOOST_ROOT /root/Downloads/boost_1_68_0)
endif()

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

find_package(Boost COMPONENTS regex system date_time timer REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(“${Boost_INCLUDE_DIRS}/stage/lib”)
include_directories(sdk/inc)
link_directories(“sdk/lib”)
MESSAGE( STATUS “Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}.”)
MESSAGE( STATUS “Boost_LIBRARIES = ${Boost_LIBRARIES}.”)
MESSAGE( STATUS “Boost_LIB_VERSION = ${Boost_LIB_VERSION}.”)

add\_executable(untitled1 main.cpp)

TARGET\_LINK\_LIBRARIES(untitled1 ${Boost\_LIBRARIES} "-lpthread" "-lpos" "-lrt" "-lpng" "-liconv" "-lfreetype" "-lz" "-l:libboost\_system.a")

endif()

GNUlinux_config.cmake

set(GNULINUX_PLATFORM ON)
set(CMAKE_SYSTEM_NAME “Linux”)
set(CMAKE_SYSTEM_PROCESSOR “arm”)

if(NOT DEFINED ENV{NE10_LINUX_TARGET_ARCH})
set(NE10_LINUX_TARGET_ARCH “armv7”)
else()
set(NE10_LINUX_TARGET_ARCH $ENV{NE10_LINUX_TARGET_ARCH})
endif()

if(NE10_LINUX_TARGET_ARCH STREQUAL “armv7”)
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
set(CMAKE_ASM_COMPILER arm-linux-gnueabihf-as)
find_program(CMAKE_AR NAMES “arm-linux-gnueabihf-ar”)
find_program(CMAKE_RANLIB NAMES “arm-linux-gnueabihf-ranlib”)
elseif(NE10_LINUX_TARGET_ARCH STREQUAL “aarch64”)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_ASM_COMPILER aarch64-linux-gnu-as)
find_program(CMAKE_AR NAMES “aarch64-linux-gnu-ar”)
find_program(CMAKE_RANLIB NAMES “aarch64-linux-gnu-ranlib”)
endif()

mark_as_advanced(CMAKE_AR)
mark_as_advanced(CMAKE_RANLIB)

The Most Important Thing on Windows

cmake -DCMAKE_TOOLCHAIN_FILE=GNUlinux_config.cmake ..

A Simple Demo

//
// Created by Water on 2018/6/9.
//

#include #include #include namespace bpo = boost::program_options;

int main(int argc, char const *argv[])
{
bpo::options_description opts(“all options”);
bpo::variables_map vm;

opts.add\_options()
        ("filename", bpo::value(), "the file name which want to be found")
        ("help", "this is a program to find a specified file");

try{
    bpo::store(bpo::parse\_command\_line(argc, argv, opts), vm);
}
catch(...){
    std::cout << "undefined option!\\n";
    return 0;
}

if(vm.count("help") ){
    std::cout << opts << std::endl;
}
if(vm.count("filename") ){
    std::cout << "find " << vm\["filename"\].as() << std::endl;
}
if(vm.empty() ){
    std::cout << "no options found \\n";
}
return 0;

}

Test

How to Set Default Value

//
// Created by Water on 2018/6/9.
//

#include #include #include #include namespace bpo = boost::program_options;

int main(int argc, char const *argv[])
{
std::vector v_para;
std::string port;
int baud = 0;
int timeout = 0;
bpo::options_description opt(“all options”);

opt.add\_options()
        ("v\_para,v", bpo::value >()->multitoken(), "Serial v\_para")
        ("port,p", bpo::value(&port)->default\_value("COM1"), "Serial Port")
        ("baud,b", bpo::value(&baud)->default\_value(115200), "Serial Baud")
        ("timeout,t", bpo::value(&timeout)->default\_value(5000), "Timeout")
        ("help", "a demo ( default value )");

bpo::variables\_map vm;

try{
    bpo::store(parse\_command\_line(argc, argv, opt), vm);
}
catch(...){
    std::cout << "undefined option!\\n";
    return 0;
}

bpo::notify(vm);

if(vm.count("help") ){
    std::cout << opt << std::endl;
    return 0;
}
if(vm.count("v\_para") ){
    std::cout << "v\_para:";
    for(auto& str : vm\["v\_para"\].as >() )
        std::cout << str << " ";
    std::cout << std::endl;
}
std::cout << "port:" << port << std::endl;
std::cout << "baud:" << baud << std::endl;
std::cout << "timeout:" << timeout << std::endl;
return 0;

}

Test

First

http://archive.apache.org/dist/ws/axis2/c/1\_6\_0/axis2c-bin-1.6.0-win32.zip ftp://ftp.zlatkovic.com/libxml/libxml2-2.7.8.win32.zip ftp://ftp.zlatkovic.com/libxml/iconv-1.9.2.win32.zip ftp://ftp.zlatkovic.com/libxml/zlib-1.2.5.win32.zip http://archive.apache.org/dist/httpd/binaries/win32/httpd-2.2.25-win32-x86-openssl-0.9.8y.msi

Install Axis2/C

  1. Extract the binary distribution to a folder of your choice.(example: C:\axis2c-bin-1.6.0-win32)
  2. Copy the iconv.dll, libxml2.dll and zlib1.dll to C:\axis2c-bin-1.6.0-win32\lib
  3. Set the variable AXIS2C_HOME to the deploy folder (C:\axis2c-bin-1.6.0-win32)
  4. Add the path to lib directory to the PATH variable (%AXIS2C_HOME%\lib)

Install Apache 2.2

  1. Copy C:\axis2c-bin-1.6.0-win32\lib\mod_axis2.dll C:\Apache22\modules\mod_axis2.so
  2. Edit the Apache2’s configuration file (generally httpd.conf) and add the following directives
  3. LoadModule axis2_module modules/mod_axis2.so Axis2RepoPath C:/axis2c-bin-1.6.0-win32 Axis2LogFile C:/axis2c-bin-1.6.0-win32/logs Axis2MaxLogFileSize 40 Axis2LogLevel warn
  4. Restart apache2 and test whether mod_axis2 module is loaded by typing the URL http://localhost/axis2/services in your Web browser

Create Project & Generate .ts

lupdate TestInternational.pro -ts zh_CN.ts

Translate with Linguist

Save & Release to Generate .qm

Add Code to Choose Language

#include “widget.h”
#include #include #include int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QTranslator trans;
 if(trans.load(a.applicationDirPath() + "/../../../zh\_CN.qm"))
    a.installTranslator(&trans);

Widget w;
w.show();

return a.exec();

}

The Result

SerializeToString & SerializeToArray

syntax = “proto3”;

package test;

message People {
string name = 1;
int32 age = 2;
int32 steps = 3;
}

protoc Usage :

water@waters-MacBook-Pro:/Documents/GitHub/CppQt5/TestProtobuf$ protoc –cpp_out=. people.proto
water@waters-MacBook-Pro:
/Documents/GitHub/CppQt5/TestProtobuf$ ls people.p*
people.pb.cc people.pb.h people.proto

#include #include “people.pb.h”

int main(int argc, char *argv[])
{
test::People pep;
pep.set_name(“heheda”);
pep.set_age(5);
pep.set_steps(1304);

std::string buff;
pep.SerializeToString(&buff);

test::People pep2;
pep2.ParseFromString(buff);

std::cout << pep2.name() << std::endl;
std::cout << pep2.age() << std::endl;
std::cout << pep2.steps() << std::endl;

int data\_len = pep.ByteSize();
unsigned char data\[1024\] = "\\0";
pep.SerializeToArray(data, data\_len);
for(auto i = 0; i < data\_len; i ++)
    printf("%02X ", data\[i\]);
printf("\\n");

test::People pep3;
pep3.ParseFromArray(data, data\_len);

std::cout << pep3.name() << std::endl;
std::cout << pep3.age() << std::endl;
std::cout << pep3.steps() << std::endl;

return 0;

}

Build

water@waters-MacBook-Pro:/Downloads/protobuf-3.5.1$ ./autogen.sh
water@waters-MacBook-Pro:
/Downloads/protobuf-3.5.1$ ./configure
water@waters-MacBook-Pro:/Downloads/protobuf-3.5.1$ make
water@waters-MacBook-Pro:
/Downloads/protobuf-3.5.1$ make install
water@waters-MacBook-Pro:~/Downloads/protobuf-3.5.1$ protoc –version
libprotoc 3.5.1

CMAKE Config

mingw32-make & install

c:\protobuf-3.5.1build>mingw32-make
Scanning dependencies of target libprotobuf-lite
[ 0%] Building CXX object CMakeFiles/libprotobuf-lite.dir/C_/protobuf-3.5.1/src/google/protobuf/arena.cc.obj
[ 1%] Building CXX object CMakeFiles/libprotobuf-lite.dir/C_/protobuf-3.5.1/src/google/protobuf/arenastring.cc.obj
[ 1%] Building CXX object CMakeFiles/libprotobuf-lite.dir/C_/protobuf-3.5.1/src/google/protobuf/extension_set.cc.obj
[ 2%] Building CXX object CMakeFiles/libprotobuf-lite.dir/C_/protobuf-3.5.1/src/google/protobuf/generated_message_table_driven_lite.cc.obj
……

c:\protobuf-3.5.1build>mingw32-make install
[ 12%] Built target libprotobuf-lite
[ 52%] Built target libprotobuf
[ 52%] Built target js_embed
[ 99%] Built target libprotoc
[100%] Built target protoc
Install the project…
– Install configuration: “”
– Installing: C:/protobuf-3.5.1-qt5.9/lib/libprotobuf-lite.a
– Installing: C:/protobuf-3.5.1-qt5.9/lib/libprotobuf.a
– Installing: C:/protobuf-3.5.1-qt5.9/lib/libprotoc.a
– Installing: C:/protobuf-3.5.1-qt5.9/bin/protoc.exe
……