colorful

zc qq:1337220912

 

linux 下安装luabind

  luabind需要boost 和lua, 请先安装boost, lua
  luabind用到lua的动态库,请在安装lua时编译出 liblua.so

  a: export BOOST_ROOT=/home/zc/tools/boost_1_48_0
  b: export LUA_PATH=/usr/local/
  c: bjam stage --toolset=gcc --with-date_time --with-fpic --with-filesystem link=static debug release  --这一步可以不要
  d: bjam install

posted @ 2012-09-25 20:11 多彩人生 阅读(866) | 评论 (0)编辑 收藏

关于lua5.1.4找不到luaL_openlibs的问题

忙了一下午,最后才发现是src/Makefile里少数据
LUAC_T=    luac
LUAC_O=    luac.o print.o
LUA_SO= liblua.so

ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUA_SO)
ALL_A= $(LUA_A)

default: $(PLAT)

all:    $(ALL_T)

o:    $(ALL_O)

a:    $(ALL_A)

$(LUA_A): $(CORE_O) $(LIB_O)
    $(AR) $@ $?
    $(RANLIB) $@

$(LUA_T): $(LUA_O) $(LUA_A)
    $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)

$(LUAC_T): $(LUAC_O) $(LUA_A)
    $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)

$(LUA_SO):$(CORE_O) $(LIB_O)
    $(CC) -o $@ -shared -fPIC $? -ldl -lm

posted @ 2012-09-25 19:53 多彩人生 阅读(1877) | 评论 (0)编辑 收藏

lua 安装

下载源文件
tar zxvf lua.tar.gz
make linux
make install

提示找不到readline/readline.h
apt-get install libncurses5-dev libreadline5-dev

posted @ 2012-09-25 14:23 多彩人生 阅读(292) | 评论 (0)编辑 收藏

VS2008下编译luabind 0.8.1

     学了一段时间Lua,显然直接在项目中使用是很不方便,google了一下,似乎大家都对luabind这个lua包装类青睐有加,于是我也随大势想用用看。
     先做好准备工作,下载了luabin 0.8.1源码,Boost 1.3.8源码和lua 5.1.4源码,编译环境是VS2008 SP1。之前在网上看到一些文章说这些开源软件之间的版本依赖比较敏感,可能会有这样那样的问题,动手之前有些惶恐。
     幸运的是,编译过程很顺利,如下:
     1.编译lua 5.1.4
     进入VS2008的命令行工具,定位到lua的源码目录下,执行命令etc\luavs.bat,没什么问题的话很快就可以编译好lua,得到lua51.lib和lua51.dll。
     2.编译luabind
     解压下载回来的luabind压缩包,假设解压到d:\luabind-0.8.1\,Boost解压到d:\boost 1_38_0\,lua解压到d:\lua 5.1.4\
     在 VS中新建一个静态库项目,将d:\luabind-0.8.1\src下的源码全部添加到项目中,然后在项目中新建luabind和luabind \detail\两个虚拟文件夹,对应的将d:\luabind-0.8.1\luabind和d:\luabind-0.8.1\luabind \detail下的文件添加到文件夹中。
     然后为项目添加附加包含目录,右键点击项目节点->属性->配置属性->C\C++标签下,在附加包含目录中填入d: \luabind-0.8.1\;d:\boost 1_38_0\k;d:\lua 5.1.4\src\。然后修改项目字符集为多字节字符集。
     准备就绪,生成项目。在我的环境中编译很顺利,没有出现任何问题,成功后会得到luabind.lib。

     接下来就按照惯例来写一个hello world程序作为使用luabind的第一步。
     在VS中新建一个控制台项目,类型为DLL,命名项目为Hello World,然后键入以下代码:

 1#include "stdafx.h"
 2#include <iostream>
 3#include <luabind/luabind.hpp>
 4
 5void greet()
 6{
 7    std::cout << "hello world!\n";
 8}

 9
10extern "C" int __declspec(dllexport) init(lua_State* L)
11{
12    using namespace luabind;
13
14    open(L);
15
16    module(L)
17    [
18        def("greet"&greet)
19    ];
20
21    return 0;
22}


   注意,在Windows环境下init函数之前是要加 __declspec(dllexport)才能将函数导出的,而luabind的文档中的环境是linux,默认不用加 __declspec(dllexport)也可以导出(就因为这个折腾了我半天才把hello word成功运行)。
   编译项目,(记得将luabind.lib和lua51.lib添加到链接选项中:项目属性->连接器->输入->附加依赖文件,加入luabind.lib和lua51.lib)。
   将hello world.dll放到lua51.dll和lua.exe所在的目录下。
   打开lua命令行,键入:
    
   测试成功,enjoy。

posted @ 2012-09-10 21:05 多彩人生 阅读(214) | 评论 (0)编辑 收藏

pg_ctl

pg_ctl -- 启动、停止、重启 PostgreSQL
2010-01-11 19:08

pg_ctl

名称

pg_ctl -- 启动、停止、重启 PostgreSQL

语法

pg_ctl start [-w] [-s] [-D datadir] [-l filename] [-o options] [-p path]
pg_ctl stop [-W] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ]
pg_ctl restart [-w] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-o options]
pg_ctl reload [-s] [-D datadir]
pg_ctl status [-D datadir]
pg_ctl kill [signal_name] [process_id]
pg_ctl register [-N servicename] [-U username] [-P password] [-D datadir] [-w] [-o options]
pg_ctl unregister [-N servicename]

描述

pg_ctl 用于启动、停止、重启 PostgreSQL 后端服务器(postgres),或者显示一个运行着的服务器的状态。尽管可以手动启动服务器,但是 pg_ctl 封装了重新定向日志输出,与终端和进程组合理分离,以及另外提供了一个选项用于有控制的关闭。

start 模式里会启动一个新的服务器。服务器是在后台启动的,标准输入被附着到了 /dev/null 上。如果使用了 -l ,那么标准输出和标准错误将被定向到一个日志文件,要么就是重定向到 pg_ctl 的标准输出(而不是标准错误)。如果没有选定日志文件,pg_ctl 的标准输出应该重定向到一个文件或者用管道输出到类似 rotatelogs 这样的日志滚动程序,否则,postgres 将把它的输出写到控制终端(在后台)并且将不会脱离 shell 的进程组。

stop 模式下,那个正在特定数据目录运行的服务器将被关闭。你可以用 -m 选项选择三种不同的关闭模式:"Smart"模式等待所有客户端中断连接,这是缺省。"Fast"模式并不等待客户端中断连接,所有活跃事务都被回滚并且 客户端都被强制断开。"Immediate"模式将在没有干净关闭的情况下强行退出。这么做将导致在重新启动的时候的恢复。

restart 实际上是先执行一个停止,然后紧跟一个启动。它允许变换 postgres 的命令行选项。

reload 模式简单地给 postgres 发送一个 SIGHUP 信号,导致它重新读取配置文件(postgresql.conf, pg_hba.conf 等),这样就允许修改配置文件选项而不用重启系统即可生效。

status 模式监查一个服务器是否在指定的数据目录运行,如果是,那么显示其 PID 和调用它的命令行选项。

kill 模式允许你给一个指定的进程发送信号。这个功能对 Microsoft Windows 特别有用,因为它没有 kill 命令。使用 --help 查看支持的信号名字列表。

register 模式允许你在 Microsoft Windows 上注册一个系统服务。

unregister 模式允许你在 Microsoft Windows 上删除先前用 register 命令注册的系统服务。

选项

-D datadir

声明该数据库的文件系统位置。如果忽略则使用 PGDATA 环境变量。

-l filename

把服务器日志输出附加在 filename 文件上。如果该文件不存在则创建它。umask 设置为 077 ,因此缺省时是不允许从其它用户向日志文件访问的。

-m mode

声明关闭模式。mode 可以是 smart, fast, immediate 之一,或者是这三个的首字母之一。

-o options

声明要直接传递给 postgres 的选项。

参数通常都用单或者双引号包围以保证它们作为一个整体传递。

-p path

声明 postgres 可执行文件的位置。缺省位于 pg_ctl 自身所在目录,如果没找到则使用硬编码的安装目录。除非你想干点什么特别的事情,并且想得到类似没有找到 postgres 这样的错误,否则必须使用这个选项。

-s

只打印错误,而不打印提示性信息。

-w

等待启动或者关闭的完成(60 秒超时),这个参数是关闭时的缺省值。成功的关闭是以删除 PID 文件为标志的。对于启动而言,一次成功的 psql -l 就标志着成功。pg_ctl 将企图使用对 psql 合适的端口,如果存在 PGPORT 环境变量,那么将用它。否则,它将查找在 postgresql.conf 文件里是否设置了一个端口。如果都没有,它将使用 PostgreSQL 编译时的缺省端口(缺省 5432)。在等待的时候,pg_ctl 将根据启动或者关闭的成功状况返回一个准确的退出代码。

-W

不等待启动或者停止的完成。这是启动和重启的缺省。

posted @ 2012-08-15 18:14 多彩人生 阅读(450) | 评论 (0)编辑 收藏

精确获取时间(QueryPerformanceCounter)

LARGE_INTEGER tima,timb;
QueryPerformanceCounter(&tima);

在 Windows Server 2003 和 WindowsXP 中使用 QueryPerformanceCounter 函数的程序可能执行不当

QueryPerformanceCounter 來精確計算執行時間
QueryPerformanceCounter 來精確計算執行時間
// 這個程式展示了如何使用QueryPerformanceCounter 來精確計算執行時間
//代码


 

  1. LARGE_INTEGER m_liPerfFreq={0};
  2.  //获取每秒多少CPU Performance Tick
  3.  QueryPerformanceFrequency(&m_liPerfFreq); 

  4.  LARGE_INTEGER m_liPerfStart={0};
  5.  QueryPerformanceCounter(&m_liPerfStart);

  6.  for(int i=0; i< 100; i++)
  7.   cout << i << endl;

  8.  LARGE_INTEGER liPerfNow={0};
  9.  // 计算CPU运行到现在的时间
  10.  QueryPerformanceCounter(&liPerfNow);

  11.  int time=( ((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000)/m_liPerfFreq.QuadPart);

  12.  char buffer[100];
  13.  sprintf(buffer,"執行時間 %d millisecond ",time);

  14.  cout<<buffer<<endl;


QueryPerformanceCounter()这个函数返回高精确度性能计数器的值,它可以以微妙为单位计时.但是 QueryPerformanceCounter()确切的精确计时的最小单位是与系统有关的,所以,必须要查询系统以得到 QueryPerformanceCounter()返回的嘀哒声的频率.
QueryPerformanceFrequency()提供了这个频率值,返回每秒嘀哒声的个数.
计算确切的时间是从第一次调用QueryPerformanceCounter()开始的
假设得到的LARGE_INTEGER为nStartCounter,过一段时间后再次调用该函数结束的,
设得到nStopCounter.
两者之差除以QueryPerformanceFrequency()的频率就是开始到结束之间的秒数.由于计时函数本身要耗费很少的时间,要减去一个很少的时间开销.但一般都把这个开销忽略.公式如下:   
                         nStopCounter-nStartCounter
ElapsedTime=------------------------------------ - overhead
frequency

double time=(nStopCounter.QuadPart-nStartCounter.QuadPart)/frequency.QuadPart

 

 

这两个函数是VC提供的仅供Windows 95及其后续版本使用的精确时间函数,并要求计算机从硬件上支持精确定时器。
QueryPerformanceFrequency()函数和QueryPerformanceCounter()函数的原型如下:

       BOOL  QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency);        BOOL  QueryPerformanceCounter(LARGE_INTEGER *lpCount);

  数据类型ARGE_INTEGER既可以是一个8字节长的整型数,也可以是两个4字节长的整型数的联合结构, 其具体用法根据编译器是否支持64位而定。该类型的定义如下:

       typedef union _LARGE_INTEGER        {            struct            {               DWORD LowPart ;// 4字节整型数               LONG  HighPart;// 4字节整型数            };            LONGLONG QuadPart ;// 8字节整型数                     }LARGE_INTEGER ;

  在进行定时之前,先调用QueryPerformanceFrequency()函数获得机器内部定时器的时钟频率, 然后在需要严格定时的事件发生之前和发生之后分别调用QueryPerformanceCounter()函数,利用两次获得的计数之差及时钟频率,计算出事件经 历的精确时间。下列代码实现1ms的精确定时:

 
  1.        LARGE_INTEGER litmp; 
  2.        LONGLONG QPart1,QPart2;
  3.        double dfMinus, dfFreq, dfTim; 
  4.        QueryPerformanceFrequency(&litmp);
  5.        dfFreq = (double)litmp.QuadPart;// 获得计数器的时钟频率
  6.        QueryPerformanceCounter(&litmp);
  7.        QPart1 = litmp.QuadPart;// 获得初始值
  8.        do
  9.        {
  10.           QueryPerformanceCounter(&litmp);
  11.           QPart2 = litmp.QuadPart;//获得中止值
  12.           dfMinus = (double)(QPart2-QPart1);
  13.           dfTim = dfMinus / dfFreq;// 获得对应的时间值,单位为秒
  14.        }while(dfTim<0.001);

  其定时误差不超过1微秒,精度与CPU等机器配置有关。 下面的程序用来测试函数Sleep(100)的精确持续时间:

 
  1.        LARGE_INTEGER litmp; 
  2.        LONGLONG QPart1,QPart2;
  3.        double dfMinus, dfFreq, dfTim; 
  4.        QueryPerformanceFrequency(&litmp);
  5.        dfFreq = (double)litmp.QuadPart;// 获得计数器的时钟频率
  6.        QueryPerformanceCounter(&litmp);
  7.        QPart1 = litmp.QuadPart;// 获得初始值
  8.        Sleep(100);
  9.        QueryPerformanceCounter(&litmp);
  10.        QPart2 = litmp.QuadPart;//获得中止值
  11.        dfMinus = (double)(QPart2-QPart1);
  12.        dfTim = dfMinus / dfFreq;// 获得对应的时间值,单位为秒    

  由于Sleep()函数自身的误差,上述程序每次执行的结果都会有微小误差。下列代码实现1微秒的精确定时:

 
  1.        LARGE_INTEGER litmp; 
  2.        LONGLONG QPart1,QPart2;
  3.        double dfMinus, dfFreq, dfTim; 
  4.        QueryPerformanceFrequency(&litmp);
  5.        dfFreq = (double)litmp.QuadPart;// 获得计数器的时钟频率
  6.        QueryPerformanceCounter(&litmp);
  7.        QPart1 = litmp.QuadPart;// 获得初始值
  8.        do
  9.        {
  10.           QueryPerformanceCounter(&litmp);
  11.           QPart2 = litmp.QuadPart;//获得中止值
  12.           dfMinus = (double)(QPart2-QPart1);
  13.           dfTim = dfMinus / dfFreq;// 获得对应的时间值,单位为秒
  14.        }while(dfTim<0.000001);

其定时误差一般不超过0.5微秒,精度与CPU等机器配置有关。(

posted @ 2012-07-27 19:00 多彩人生 阅读(469) | 评论 (0)编辑 收藏

C/C++通用Makefile

http://wenku.baidu.com/view/17a11ef8fab069dc502201d4.html
http://wenku.baidu.com/view/a2429bd728ea81c758f578cd.html
http://blog.csdn.net/fljing/article/details/6257867

posted @ 2012-07-26 23:19 多彩人生 阅读(288) | 评论 (0)编辑 收藏

gcc的参数

http://wuqinzhong.blog.163.com/blog/static/452223120095248474729/

posted @ 2012-07-26 22:34 多彩人生 阅读(226) | 评论 (0)编辑 收藏

cannot pass objects of non-POD type

移植代码到Linux下,运行总是崩溃(在windows下正常)。
调试发现问题出在下列语句:
   wxString szSiteHead = wxString::Format( wxT("<Location /%s>"), file.GetName() );
查看编译记录有下列警告信息
   warning: cannot pass objects of non-POD type 'class wxString' through '...'; call will abort at runtime|
提示在运行时会异常。
 
查找 POD type定义如下:非原生类型
 
POD stands for Plain Old Data - that is, a struct (or class) with no members except data members. Wikipedia goes into a bit more detail and defines a POD in C++ as "A Plain Old Data Structure in C++ is an aggregate class that contains only PODS as members, has no user-defined destructor, no user-defined copy assignment operator, and no nonstatic members of pointer-to-member type."
 
代码更改后OK。
wxString szSiteHead = wxString::Format( wxT("<Location /%s>"), file.GetName().c_str() );

===================================================================================
ctags: c++ warning "cannot pass objects of non-POD type"

1、不要忽视编译时的任何一个 Warning .2、正确使用输入输出流,避开高危函数。

1、printf("Hello %s" ,str.c_str());
2、cout<<str;

string 非原生类型 non-POD,编译器无法把它传入.

下面是一个网上的小例子。

im trying to compile following code
--------------------sam.cpp---------------------
#include <string>
#include <iostream>
#include <stdarg.h>
using namespace std;

void Write( const char* msg, const char* msg2, ...)
{
cout <<msg <<" "<<msg2<<endl;
}

int main()
{
string str("World");
Write("Hello","Debug out %s" ,str);
return 0;
}
-------------------------------------------

When i compile this code i get following compilation warning .

[oracle@sahyagiri test]$ g++ sam.cpp
sam.cpp: In function `int main()':
sam.cpp:17: warning: cannot pass objects of non-POD
type `struct std::string'
through `...'; call will abort at runtime

When i run the executable, a.out it fails with Illegal
instruction eror

posted @ 2012-07-26 12:45 多彩人生 阅读(1169) | 评论 (0)编辑 收藏

shell脚本中局部变量

在shell中定义函数可以使代码模块化,便于复用代码。不过脚本本身的变量和函数的变量的作用域问题可能令你费解,在这里梳理一下这个问题。

(1)Shell脚本中定义的变量是global的,其作用域从被定义的地方开始,到shell结束或被显示删除的地方为止。

例1:脚本变量的作用域
#!/bin/bash
#define the function ltx_func
ltx_func()
{
   echo $v1
   #modify the variable v1
   v1=200
}
#define the variable v1
v1=100
#call the function ltx_func
ltx_func
echo $v1

结果:
100
200
解析:脚本变量v1的作用域从被定义的地方开始,到shell结束。调用函数ltx_func的地方在变量v1的作用域内,所以能够访问并修改变量v1。

(2)Shell函数定义的变量默认是global的,其作用域从“函数被调用时执行变量定义的地方”开始,到shell结束或被显示删除处为止。函数定义的变量可以被显示定义成local的,其作用域局限于函数内。但请注意,函数的参数是local的。

例2:函数定义的global变量
#!/bin/bash
#define the function ltx_func
ltx_func()
{
   #define the variable v2
   v2=200
}
#call the function ltx_func
ltx_func
echo $v2

结果:
200
解析:函数变量v2默认是global的,其作用域从“函数被调用时执行变量定义的地方”开始,到shell结束为止。注意,不是从定义函数的地方开始,而是从调用函数的地方开始。打印命令在变量v2的作用域内,所以能够访问变量v2。

例3:函数定义的local变量
#!/bin/bash
#define the function ltx_func
ltx_func()
{
   #define the local variable v2
   local v2=200
}
#call the function ltx_func
ltx_func
echo $v2

结果:
(空)
解析:函数变量v2显示定义为local的,其作用域局限于函数内。打印命令在函数外,不在变量v2的作用域内,所以能够不能访问变量v2。

例4:函数参数是local变量
#!/bin/bash
#define the function ltx_func
ltx_func()
{
   echo "param 1: $1"
}
#call the function ltx_func
ltx_func 100

结果:
100
解析:函数参数是local的,通过位置变量来访问。打印命令输出函数的第一个参数。

(3)如果同名,Shell函数定义的local变量会屏蔽脚本定义的global变量。

例5:同名local变量屏蔽global变量
#!/bin/bash
#define the function ltx_func
ltx_func()
{
   echo $v1
   #define the local variable v1
   local v1=200
   echo $v1
}
#define the global variable v1
v1=100

#call the function ltx_func
ltx_func
echo $v1

结果:
100
200
100
解析:global变量v1的作用域从被定义的地方开始,到shell结束。调用函数ltx_func的地方在变量v1的作用域内,所以能够变量v1。函 数又定义了同名的local变量v1,同名local变量屏蔽global变量,所以函数第二次打印访问的是local变量。退出函数后再次打印v1,此 时函数定义的local变量已经消失,访问的是global变量。

posted @ 2012-07-26 10:53 多彩人生 阅读(342) | 评论 (0)编辑 收藏

仅列出标题
共25页: First 9 10 11 12 13 14 15 16 17 Last 

导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜