上一页 1 ··· 6 7 8 9 10 11 12 下一页
摘要: 1、需要 python 头文件,下载安装。2、下载安装distcc-3.1.tar.bz2。3、export DISTCC_HOSTS='localhost 10.10.13.162‘ //添加所有欲分发的distcc服务器IP列表,ip应按各服务器性能由好到差排列。export DISTCC_VERBOSE=1 //给出调试信息export DISTCC_LOG=”/root/disstcc.log” //编译出错时可以查看日志,默认路径是/var/log/messages以上可以写入到 ~/.bash_profile 中,以便开机有效。4、在每一台服务器上安装好 distcc 之. 阅读全文
posted @ 2013-03-11 12:39 轻典 阅读(4412) 评论(0) 推荐(1) 编辑
摘要: 编译之后,在 lib/.libs 目录下会生成动态和静态链接库,我比较喜欢动态库,生成文件较小,方便上传服务器。 1 #include <gtest/gtest.h> 2 3 int max(int a,int b) 4 { 5 return a > b ? a:b; 6 } 7 8 TEST(foo,max) 9 {10 EXPECT_EQ(2,max(2,-1));11 EXPECT_EQ(3,max(2,3));12 }13 14 int main(int argc,char** argv)15 {16 ::testing::InitGoogleTes... 阅读全文
posted @ 2013-03-02 00:42 轻典 阅读(672) 评论(0) 推荐(0) 编辑
摘要: 一、安装配置1、简介 google 出的一个C++轻量级日志库,支持以下功能:◆ 参数设置,以命令行参数的方式设置标志参数来控制日志记录行为;◆ 严重性分级,根据日志严重性分级记录日志;◆ 可有条件地记录日志信息;◆ 条件中止程序。丰富的条件判定宏,可预设程序终止条件;◆ 异常信号处理。程序异常情... 阅读全文
posted @ 2013-02-22 10:30 轻典 阅读(62018) 评论(5) 推荐(7) 编辑
摘要: 一个简单的例子:ab.out : a.o b.o g++ -o ab.out o/a.o o/b.oa.o : a.cpp g++ -c a.cpp -o o/a.ob.o : b.cpp g++ -c b.cpp -o o/b.oclean: rm -f o/a.o o/b.o再看下面一个:simple_server_objects = socket/ServerSocket.o socket/Socket.o server.osimple_client_objects = socket/ClientSocket.o socket/Socket.o client.oa... 阅读全文
posted @ 2013-02-16 13:50 轻典 阅读(5272) 评论(0) 推荐(0) 编辑
摘要: 中文MAN文档:wget http://manpages-zh.googlecode.com/files/manpages-zh-1.5.1.tar.gz./configure && make && make installexport LANG=zh_CN.GB2312想看英文的, man -a ls如果想删除,make uninstall如果系统里没有安装gcc 和 g++ 的话:如果是 CentOS 系统,可以使用 yum install gcc使用 yum search gcc ,看到gcc-c++.x86_64 ,所以使用 yum install gc 阅读全文
posted @ 2013-01-11 17:24 轻典 阅读(2097) 评论(0) 推荐(0) 编辑
摘要: py.cpp:#include <iostream>#include <boost/python.hpp>#include <Python.h>using namespace boost::python;using namespace std;int main(){ Py_Initialize(); object main_module = import("__main__"); object main_namespace = main_module.attr("__dict__"); object simple = 阅读全文
posted @ 2013-01-09 12:10 轻典 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 先看下Linux 下的 pthread 多线程例子:#include <pthread.h>#include <stdio.h>#include <time.h>void sleep(int sec){ clock_t delay = sec * CLOCKS_PER_SEC; clock_t start = clock(); while(clock() - start < delay);}void fun1(){ while(1){ printf( "fun1"); }}void fun2(){ while(1){ prin... 阅读全文
posted @ 2013-01-09 12:09 轻典 阅读(672) 评论(0) 推荐(1) 编辑
摘要: 第11章 函数回调#include <iostream>#include <boost/assign.hpp>#include <boost/ref.hpp>#include <boost/typeof/typeof.hpp>struct Ope{ void operator()(int& x){x = x*x;}};struct Print{ void operator()(int x){std::cout<<x<<"\t";}};int main(){ std::vector<int& 阅读全文
posted @ 2012-12-11 18:17 轻典 阅读(280) 评论(0) 推荐(0) 编辑
摘要: 一、基础议题(Basics)1、仔细区别 pointers 和 references当一定会指向某个对象,且不会改变指向时,就应该选择 references,其它任何时候,应该选择 pointers。实现某一些操作符的时候,操作符由于语义要求使得指针不可行,这时就使用引用。2、最好使用 C++ 转型操作符为解决 C 旧式转型的缺点(允许将任何类型转为任何类型,且难以辨识),C++ 导入 4 个新的转型操作符(cast operators):static_cast , const_cast , dynamic_cast , reinterpret_cast:分别是常规类型转换,去常量转换,继承转 阅读全文
posted @ 2012-12-05 14:26 轻典 阅读(3858) 评论(1) 推荐(0) 编辑
摘要: 函数名跟数组名一样,都是地址。数组名是首元素的地址,函数名是函数入口处地址。比如一个函数名为 fun;cout<<fun<<endl; 在VS翻译器下可以正确输出为地址,在GCC编译器下会输出为 1,只需要 cout<<(void *)fun<<endl; 即可。#include <iostream>using namespace std;void print_x(int i){ cout<<"x: "<<i<<endl;}void print_y(int i){ cout< 阅读全文
posted @ 2012-11-30 17:17 轻典 阅读(194) 评论(0) 推荐(0) 编辑
摘要: <boost/foreach.hpp> 提供两个宏:BOOST_FOREACH 和 BOOST_REVERSE_FOREACH#include <string>#include <boost/foreach.hpp>#include <boost/assign.hpp>#include <boost/typeof/typeof.hpp>int main(){ std::vector<int> vect = boost::assign::list_of(1)(2)(3); BOOST_FOREACH(int x,vect) 阅读全文
posted @ 2012-10-24 16:39 轻典 阅读(234) 评论(0) 推荐(0) 编辑
摘要: <boost/array.hpp>:包装内建数组,为其提供标准STL接口,如begin()、front()等,速度性能上与原始数组相差无几。#include <iostream>#include <boost/array.hpp>#include <boost/typeof/typeof.hpp>int main(){ boost::array<int,10> arr; //一个长度为10的int数组,或 boost::array<int,3> arr = {1,2,3} arr[0] = 1; arr.back() = 阅读全文
posted @ 2012-10-24 14:52 轻典 阅读(327) 评论(0) 推荐(0) 编辑
摘要: 当定义了宏 BOOST_ENABLE_ASSERT_HANDLER 后,使用 BOOST_ASSERT() 断言失败后,会调用 boost::assertion_failed() 函数,该函数声明在 boost 名字空间内,但特意被设计为没有实现。#include <iostream>#include <boost/format.hpp>namespace boost{ void assertion_failed(char const* expr,char const * function,char const* file,long line) { boost::fo. 阅读全文
posted @ 2012-10-24 12:08 轻典 阅读(323) 评论(0) 推荐(0) 编辑
摘要: lexical_cast 字面量转换:#include <iostream>#include <boost/lexical_cast.hpp>#include <string>int main(){ int i = 0; try{ i = boost::lexical_cast<int>("100L"); //可能会抛出 bad_lexical_cast 异常 }catch(boost::bad_lexical_cast& e) { std::cout<<e.what()<<std::endl; 阅读全文
posted @ 2012-10-19 10:15 轻典 阅读(840) 评论(0) 推荐(0) 编辑
摘要: 类型自动推导:#include <iostream>#include <boost/typeof/typeof.hpp>#include <vector>#include <string>using namespace std;vector<string> func(){ vector<string> v(10); return v;}int main(){ BOOST_TYPEOF(2.1*3) x = 2.1*3; BOOST_AUTO(y,2.1*3); //我感觉 BOOST_AUTO 更好用些。第一个参数是左值, 阅读全文
posted @ 2012-10-18 10:58 轻典 阅读(289) 评论(0) 推荐(0) 编辑
摘要: auto_ptr、scoped_ptr 与 scoped_array:#include <iostream>#include <boost/scoped_ptr.hpp>#include <boost/scoped_array.hpp>#include <boost/shared_ptr.hpp>#include <boost/make_shared.hpp>class User{ public: User(){} public: int id;};int main(){ std::auto_ptr<int> ap(new 阅读全文
posted @ 2012-10-16 15:32 轻典 阅读(349) 评论(0) 推荐(0) 编辑
摘要: 记时器 timer:#include <iostream>#include <boost/timer.hpp>int main(){ boost::timer t; //声明一个记时器对象,声明对象时即开始记时 std::cout<<t.elapsed_max()<<std::endl; //可度量的最大时间,以h为单位 std::cout<<t.elapsed_min()<<std::endl; //可度量的最小时间,以s为单位 std::cout<<t.elapsed()<<std::endl; 阅读全文
posted @ 2012-10-15 16:54 轻典 阅读(338) 评论(0) 推荐(0) 编辑
摘要: Boost库是一个跨平台、开源并且完全免费的C++程序库。c++98标准把stl纳入c++,1998年,Boost社区也建立,目的是为了向C++程序员提供免费的、同行审查的、可移植的高质量C++源程序库。最新的c++11标准,已经把Boost库中的很多内容如智能指针等并入了c++标准库。Boost库把C++类的声明和实现都放在了一个文件中,后缀名是 .hpp,首先是为了与普通的C头文件区分,另一个很重要的原因就是使Boost库不需要预先编译,直接引入工程即可编译链接,方便库的使用,还有一个原因是C++编译器的限制,许多编译器尚不支持C++标准提出的模板的分离编译模式(export 关键字),而 阅读全文
posted @ 2012-10-15 14:22 轻典 阅读(358) 评论(0) 推荐(0) 编辑
摘要: 一、改变旧有的 C 习惯 (Shifting from C to C++)1、尽量以编译器取代预处理器 预处理器 #define 通常不被视为语言本身的一部分,如 #define PI 3.1415926,则符号名称 PI 可能没有机会被编译器看见,它可能在编译之前就被预处理器替换了,结果导致名称... 阅读全文
posted @ 2012-10-11 10:51 轻典 阅读(924) 评论(0) 推荐(0) 编辑
摘要: 1、安装 c++ 的 man 文档(此不是VIM插件)从 http://gcc.gnu.org/mirrors.html 的其中一个镜像站中,下载最新的 libstdc++/doxygen/libstdc++-man-xxxxxx.tar.bz2然后放到Linux目录下,把里面的 man3 文件夹中... 阅读全文
posted @ 2012-10-09 09:48 轻典 阅读(616) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 下一页