编译boost与测试

1.下载boost_v1.57.0版本。
http://heanet.dl.sourceforge.net/project/boost/boost/1.57.0/boost_1_57_0.tar.gz
2.解压
tar -xf boost_1_57_0.tar.gz
3.进入目录,执行以下命令
cd boost_1_57_0 && ./bootstrap.sh
4.boostrap.sh会生成一个b2的执行文件。执行这个文件
./b2
默认是最小编译,也可以完全编译,他会对Boost进行完整编译,生成所有调试版、发行版的静态库和动态库,如下所示:
./b2 --build-type=complete --layout=versioned
经实践,在编译阶段–prefix参数没有意义,它只有按装阶段时,指定地址才有意义,否则仍旧默认安装在/usr/local/include目录下。
它会编译boost文件,如果报错bzlib.h头文件错误,则可以按以下命令查找
sudo yum whatprovides */bzlib.h
该命令会列表出哪些库会有这个文件,然后你安装那个库就可以了。
sudo yum install bzip2-devel
其实大部份boost的头文件可以直接引用就可以了,但部分与平台相关文件则需要编译,才行。如下这些库:
Boost.Chrono
Boost.Context
Boost.Filesystem
Boost.GraphParallel
Boost.IOStreams
Boost.Locale
Boost.MPI
Boost.ProgramOptions
Boost.Python (see the Boost.Python build documentation before building and installing it)
Boost.Regex
Boost.Serialization
Boost.Signals
Boost.System
Boost.Thread
Boost.Timer
Boost.Wave
5.安装boost
./b2 install
头文件会安装到/usr/local/include目录下,库文件会安装在/usr/local/lib下。
./b2 install --prefix=/boost-1.57.0
指定安装目录。
6.在CMake环境中测试。
CMakeLists.txt中编辑如下:
cmake_minimum_required(VERSION 3.5)
project(boostTest)

include_directories("/gcc-4.8.5/include/c++/4.8.5")
include_directories("/usr/local/include/")
link_directories("/usr/local/lib")
link_directories("/gcc-4.8.5/lib64")
set(CMAKE_C_COMPILER "/gcc-4.8.5/bin/gcc")
set(CMAKE_CXX_COMPILER "/gcc-4.8.5/bin/g++")

#等价于cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/gcc-4.8.5/bin/gcc -DCMAKE_CXX_COMPILER=/gcc-4.8.5/bin/g++ /home/abc/Downloads/cpp-netlib-0.12.0-final
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(boostTest ${SOURCE_FILES})

在main.cpp文件如下
#include
#include

int main() {
std::cout << "Hello, World!" << std::endl; std::cout << "Using Boost " << BOOST_VERSION / 100000 << "." // major version << BOOST_VERSION / 100 % 1000 << "." // minor version << BOOST_VERSION % 100 // patch level << std::endl; return 0; }

7.编译执行试试。

修改YII的请求参数

在YII2中,由于封装了大量的插件,很多插件是依赖Yii::$app->request->queryParams这样的参数,如Sort排序,Linkpager分页、Gridview表格等,因此有时因需要是有必要修改该参数。由于queryParams是只读属性,不能直接修改。但它提供了显式的setQueryParams的函数,让你修改。如下所示
$searchModel = new BookSearch();
$params = Yii::$app->request->queryParams;
if(isset($params['sort'])){
$cookies = Yii::$app->response->cookies;
$cookies->add(new \yii\web\Cookie([
'name' => $this->id.'_index_sort',
'value' => $params['sort'],
'expire'=>time()+3600
]));
}else{
$cookies = Yii::$app->request->cookies;
$sort = $cookies->get($this->id.'_index_sort', '');
$params['sort'] = $sort->value;
Yii::$app->request->setQueryParams($params);
}
$dataProvider = $searchModel->search($params);

id

gcc4.8.5与gdb7.11编译

在centos6.8系统上
gcc编译如下:
1.安装C++静态编译库,(据说是可以编译出静态库文件)。

yum install glibc-static libstdc++-static -y

2.在源码目录下,执行gcc的预安装检查,缺少相应文件,则会下载(gmp、mpc、mpfr这三个依赖库)。
由于gmp,mpc,mpfr这三个库是联网国外下载,国内可能被墙的原因,可按如下方式下载。

vim ./contrib/download_prerequisites
检查gmp,mpc,mpfr的相应版本号,并把相应的下载地址指你的个人地址。如本人的
http://kxtry.com/upload/mpc-0.8.1.tar.gz
http://kxtry.com/upload/mpfr-2.4.2.tar.bz2
http://kxtry.com/upload/gmp-4.3.2.tar.bz2

cd gcc-4.8.5
./contrib/download_prerequisites

3.创建gcc-4.8.5的兄弟目录。
mkdir gcc-build-4.8.5
4.配置

cd gcc-build-4.8.5
../gcc-4.8.5/configure --prefix=/gcc-4.8.5 --enable-checking=release --enable-languages=c,c++ --disable-multilib
--enable-checking:禁止检查,可以加快编译速度
--disable-multilib:禁用多平台支持。
--enable-languages:仅限c及c++的编译

5.编译
make

GDB的安装较简便:

cd gdb-7.11.1
./configure --prefix=/gdb-7.11.1
make

6.在CMake中使用如下:
cmake_minimum_required(VERSION 3.5)

project(untitled)

set(CMAKE_C_COMPILER “/gcc-4.8.5/bin/gcc”)
set(CMAKE_CXX_COMPILER “/gcc-4.8.5/bin/g++”)

set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -std=c++11”)

set(SOURCE_FILES main.cpp)
add_executable(untitled ${SOURCE_FILES})
7.检验c++11是否编译及调试正常。

设置CMake的g++版本

cmake -D CMAKE_C_COMPILER=/usr/local/bin/gcc -D CMAKE_CXX_COMPILER=/usr/local/bin/g++
—————————————–
https://cmake.org/Wiki/CMake_FAQ#Method_3_.28avoid.29:_use_set.28.29
How do I use a different compiler?
Method 1: use environment variables
For C and C++, set the CC and CXX environment variables. This method is not guaranteed to work for all generators. (Specifically, if you are trying to set Xcode's GCC_VERSION, this method confuses Xcode.)
For example:
CC=gcc-4.2 CXX=/usr/bin/g++-4.2 cmake -G "Your Generator" path/to/your/source

Method 2: use cmake -D
Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid compiler name or full path on the command-line using cmake -D.
For example:
cmake -G "Your Generator" -D CMAKE_C_COMPILER=gcc-4.2 -D CMAKE_CXX_COMPILER=g++-4.2 path/to/your/source


Method 3 (avoid): use set()

Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid compiler name or full path in a list file using set(). This must be done before any language is set (ie before any project() or enable_language() command).
For example:
set(CMAKE_C_COMPILER "gcc-4.2")
set(CMAKE_CXX_COMPILER "/usr/bin/g++-4.2")

project("YourProjectName")

Yii的URL美化

在main.php中的compont数组中添加如下:
‘urlManager’=>[
‘class’=>’source\core\base\UrlManager’,
“enablePrettyUrl” => true,
‘showScriptName’ =>false,
// 为路由指定了一个别名,以 post 的复数形式来表示 post/index 路由
// ‘rules’ => [
//// // 为路由指定了一个别名,以 post 的复数形式来表示 post/index 路由
//// ‘posts’ => ‘post/default/list’,
//// ‘fjyy’ => ‘post/default/list&taxonomy=20’,
//// ‘admin.php’ =>’admin.php’,
//
// // id 是命名参数,post/100 形式的URL,其实是 post/view&id=100
// ‘post/‘ => ‘post/default/list’,
//
//
// // controller action 和 id 以命名参数形式出现
// ‘//‘ => ‘/‘,
//
// // 包含了 HTTP 方法限定,仅限于DELETE方法
//// ‘DELETE /‘ => ‘/delete’,
//
// // 需要将 Web Server 配置成可以接收 *.digpage.com 域名的请求
//// ‘http://.digpage.com//profile’ => ‘user/profile’,
// ]
],

例子:
use yii\helpers\Url;
use yii\helpers\Html;

$url = Html::a(‘Alink’, [‘/book’,’b’=>’cdf’]);
$url2 = Url::to([‘/book/setting’,’b’=>’cdf’]);
$url3 = Url::to([‘/book/setting/create’,’b’=>’cdf’]);
$url4 = Url::to(‘/book/setting/create?b=cdf’);
$url5 = Url::to(‘/book/setting/delete?b=cdf&id=3’);
$url6 = Url::toRoute([‘book’,’b’=>’cdf’]);

安装Git2.x版本

在Centos6.x系统中,Git的版本为1.7.1.0版本,也Phpstorm要求的Git版本的最小版本为1.7.1.1,仅差0.0.0.1,如果要启用所有的phpstorm自带的GIT管理功能,则有必要升级GIT的版本。
因为本人还升级python为2.7.8故,仍需要确/usr/bin/python是可执行的。
根据官方文章介绍。https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
Installing from Source
Some people may instead find it useful to install Git from source, because you’ll get the most recent version. The binary installers tend to be a bit behind, though as Git has matured in recent years, this has made less of a difference.

If you do want to install Git from source, you need to have the following libraries that Git depends on: curl, zlib, openssl, expat, and libiconv. For example, if you’re on a system that has yum (such as Fedora) or apt-get (such as a Debian based system), you can use one of these commands to install the minimal dependencies for compiling and installing the Git binaries:

$ sudo yum install curl-devel expat-devel gettext-devel \
openssl-devel perl-devel zlib-devel
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
libz-dev libssl-dev
In order to be able to add the documentation in various formats (doc, html, info), these additional dependencies are required (Note: users of RHEL and RHEL-derivatives like CentOS and Scientific Linux will have to enable the EPEL repository to download the docbook2X package):

$ sudo yum install asciidoc xmlto docbook2X
$ sudo apt-get install asciidoc xmlto docbook2x
Additionally, if you’re using Fedora/RHEL/RHEL-derivatives, you need to do this

$ sudo ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
due to binary name differences.

When you have all the necessary dependencies, you can go ahead and grab the latest tagged release tarball from several places. You can get it via the Kernel.org site, at https://www.kernel.org/pub/software/scm/git, or the mirror on the GitHub web site, at https://github.com/git/git/releases. It’s generally a little clearer what the latest version is on the GitHub page, but the kernel.org page also has release signatures if you want to verify your download.

Then, compile and install:

$ tar -zxf git-2.0.0.tar.gz
$ cd git-2.0.0
$ make configure
$ ./configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info
After this is done, you can also get Git via Git itself for updates:

$ git clone git://git.kernel.org/pub/scm/git/git.git

Android后台运行

在播放音乐或定时器的情况,需要程序在后台运行,则此时可以打开以下开关。

<meta-data android:name=”android.app.background_running” android:value=”true”/>