ubuntu下nodejs编译C++ addon错误解决

在linux下编译nodejs 的C++ addon ,在windows下都是OK的,结果到了ubuntu下反而报错了,错误大概如下:

gyp ERR! Completion callback never invoked

搞了很久,各种搜索都找不到方法,后边进github里面看了下readme,尝试把npm 和node-pyg的pyhon路径设置了一下就可以了。

Configuring Python Dependency配置依赖

If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the --pythonvariable:

$ node-gyp --python /user/bin/python2.7

If node-gyp is called by way of npmand you have multiple versions of Python installed, then you can set npm‘s ‘python’ config key to the appropriate value:

$ npm config set python /user/bin/python2.7

 

使用cmake快速创建vs def文件

C++ VC编译那种跨平台的库时,如果生成的动态库,不会主动给生成lib文件,需要使用def文件生成lib文件,如果手动一个一个的去代码中加exportdll 或者编写def文件都非常麻烦。

可以使用cmake把obj生成def文件,方法如下:

"D:\Program Files\CMake\bin\cmake.exe" -E __create_def "C:\Users\ttDesktop\licensepp-master\build\exports.def" "C:\Users\ubosm\tt\licensepp-master\build\objects.txt"

objects.txt中列出要导出的类对象的obj。如:

C:\Users\ubosm\tt\licensepp-master\build\licensepp-lib.dir\Debug\issuing-authority.obj
C:\Users\ubosm\tt\licensepp-master\build\licensepp-lib.dir\Debug\license.obj
C:\Users\ubosm\tt\licensepp-master\build\licensepp-lib.dir\Debug\utils.obj

 

C++字符串GBK(GB2312)转utf-8


	//判断GBK编码
	bool is_str_gbk(const char* str)
	{
		unsigned int nBytes = 0;//GBK可用1-2个字节编码,中文两个 ,英文一个 
		unsigned char chr = *str;
		bool bAllAscii = true; //如果全部都是ASCII,  

		for (unsigned int i = 0; str[i] != '\0'; ++i) {
			chr = *(str + i);
			if ((chr & 0x80) != 0 && nBytes == 0) {// 判断是否ASCII编码,如果不是,说明有可能是GBK
				bAllAscii = false;
			}

			if (nBytes == 0) {
				if (chr >= 0x80) {
					if (chr >= 0x81 && chr <= 0xFE) {
						nBytes = +2;
					}
					else {
						return false;
					}

					nBytes--;
				}
			}
			else {
				if (chr < 0x40 || chr>0xFE) {
					return false;
				}
				nBytes--;
			}//else end
		}

		if (nBytes != 0) {		//违返规则 
			return false;
		}

		if (bAllAscii) { //如果全部都是ASCII, 也是GBK
			return true;
		}

		return true;
	}

	std::string GBKStringToUTF8String(const std::string &gbkStr)
	{
		const char* GBK_LOCALE_NAME = ".936"; //GBK在windows下的locale name		

		//构造GBK与wstring间的转码器(wstring_convert在析构时会负责销毁codecvt_byname,所以不用自己delete)
		wstring_convert<codecvt_byname<wchar_t, char, mbstate_t>> cv1(new codecvt_byname<wchar_t, char, mbstate_t>(GBK_LOCALE_NAME));
		wstring tmp_wstr = cv1.from_bytes(gbkStr);

		wstring_convert<codecvt_utf8<wchar_t>> cv2;
		string utf8_str = cv2.to_bytes(tmp_wstr);
		return utf8_str;
	}

	std::string GBKToUTF8(const char* strGBK)
	{
		int len = MultiByteToWideChar(CP_ACP, 0, strGBK, -1, NULL, 0);
		wchar_t* wstr = new wchar_t[len + 1];
		memset(wstr, 0, len + 1);
		MultiByteToWideChar(CP_ACP, 0, strGBK, -1, wstr, len);
		len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
		char* str = new char[len + 1];
		memset(str, 0, len + 1);
		WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
		string strTemp = str;
		if (wstr) delete[] wstr;
		if (str) delete[] str;
		return strTemp;
	}

	int code_convert(char *from_charset, char *to_charset, char *inbuf, size_t inlen, char *outbuf, size_t outlen)
	{
		iconv_t cd;
		int rc;
		 char **pin = &inbuf;
		char **pout = &outbuf;
		cd = iconv_open(to_charset, from_charset);
		if (cd == 0)
			return -1;
		memset(outbuf, 0, outlen);
		if (iconv(cd, pin, &inlen, pout, &outlen) == -1)
			return -1;
		iconv_close(cd);
		return 0;
	}
	std::string any2utf8(std::string in, std::string fromEncode, std::string toEncode)
	{
		char* inbuf = (char*)in.c_str();
		int inlen = strlen(inbuf);
		int outlen = inlen * 3;//in case unicode 3 times than ascii
		char* outbuf = new char[outlen];// = { 0 };
		int rst = code_convert((char*)fromEncode.c_str(), (char*)toEncode.c_str(), inbuf, inlen, outbuf, outlen);
		if (rst == 0) {
			return std::string(outbuf);
		}
		else {
			return in;
		}
	}
	std::string gbk2utf8(const char* in)
	{
		return any2utf8(std::string(in), std::string("gbk"), std::string("utf-8"));
	}

一共三个方法,有一个用的是iconv的C++库 ,库的下载地址http://windows.php.net/downloads/php-sdk/deps/vc14/x64/,当然你也可以自己下源码来编

 

thymeleaf使用附加属性data-*的方法

使用th:attr解决。

th:attr to the rescue Thymeleaf documentation – Setting attribute values.

For your scenario, this should do the job:

<div th:attr="data-el_id=${element.getId()}">

XML rules do not allow you to set an attribute twice in a tag, so you can’t have more than one th:attr in the same element.

Note: If you want more that one attribute, separate the different attributes by comma:如果想使用多个,方法如下

<div th:attr="data-id=${element.getId()},data-name=${element.getN‌​ame()}"> 

如果想拼接字符串。

If you need to include a variable as part of a string you need to do this: th:attr="data-id='some-text'+${element.getId()}+'some-other-‌​text',data-name=${el‌​ement.getName()}"


原地址:https://stackoverflow.com/questions/24411826/using-data-attribute-with-thymeleaf

PHP文件去掉utf8 bom

这个东西确实很烦,文件编码格式,各种情况 各种纠结,验证码一直不显示 找了几天 才发现是这个原因,最后网上找了一段代码才解决,下边是解决方法。

项目开始之初强调了utf8的编码,但居然还有no bom & bom 区分。痛苦啊!!
搞了个 kill utf8-bom 的php脚本,实现 convert utf-bom to utf8-nobom。

 

把以下代码保存为:killbom.php,放在要转换的文件根目录下执行即可。

**********************************************************************

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
if (isset($_GET['dir'])){ //config the basedir
    $basedir=$_GET['dir'];
}else{
    $basedir = '.';
}
$auto = 1;
checkdir($basedir);
function checkdir($basedir){
    if ($dh = opendir($basedir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file != '.' && $file != '..'){
                if (!is_dir($basedir."/".$file)) {
                    echo "filename: $basedir/$file".checkBOM("$basedir/$file")."<br>";
                }else{
                    $dirname = $basedir."/".$file;
                    checkdir($dirname);
                }
            }
        }
    closedir($dh);
    }
}
function checkBOM ($filename) {
    global $auto;
    $contents = file_get_contents($filename);
    $charset[1] = substr($contents, 0, 1);
    $charset[2] = substr($contents, 1, 1);
    $charset[3] = substr($contents, 2, 1);
    if (ord($charset[1]) == 239 && ord($charset[2]) == 187 &&ord($charset[3]) == 191) {
        if ($auto == 1) {
            $rest = substr($contents, 3);
            rewrite ($filename, $rest);
            return ("<font color=red>BOM found,automatically removed.</font>");
        } else {
            return ("<font color=red>BOM found.</font>");
        }
    }
    else return ("BOM Not Found.");
}
function rewrite ($filename, $data) {
    $filenum = fopen($filename, "w");
    flock($filenum, LOCK_EX);
    fwrite($filenum, $data);
    fclose($filenum);
}
?>

ffmpeg录屏命令

ffmpeg -f gdigrab -framerate 24 -offset_x 100 -offset_y 100 -video_size 1000×580 -i desktop out.mpg
ffmpeg -f dshow  -i video=”UScreenCapture” -vf crop=1200:500:10:10 -r 30 -vcodec mpeg4 -q 12 out.mp4
ffmpeg -rtbufsize 1500M -f dshow  -i video=”UScreenCapture” -vf crop=1200:500:10:10 -r 30 -crf 0 -vcodec libx264 -q 12 out.mkv
ffmpeg -rtbufsize 1500M -f dshow -r 24 -i video=”UScreenCapture” -vf crop=1200:500:10:10 -crf 0 -vcodec mpeg4 -x264opts keyint=1   out.mp4
ffmpeg -rtbufsize 1500M -f dshow -i video=UScreenCapture -vcodec h264 -r 15  -q 12 -pix_fmt yuv420p -vf crop=1200:800:10:10 out.flv
ffmpeg -rtbufsize 1500M -f dshow -i video=”UScreenCapture” -vcodec libx264 -crf 0 -preset ultrafast output.flv
ffmpeg -f gdigrab -framerate 16 -offset_x 100 -offset_y 100 -video_size 1000×580 -i desktop  -vcodec h264   -q 12 -pix_fmt yuv420p out.flv
ffmpeg -rtbufsize 1500M -f dshow -i audio=”virtual-audio-capturer” -f gdigrab -framerate 30 -draw_mouse 1 -i title=RecordWindow -pix_fmt yuv420p -profile:v baseline -y test.mp4

vs2015编译ffmpeg无法解析外部符号__imp__fprintf解决方法

使用vs2015编译ffmpeg的一个小项时,出现了__imp__fprintf和__imp____iob_func 的错误,google了一下,有的人 建议下载SDL源码重新编译一下,当然这个方案非常不科学。所以又继续搜,终于有所发现。

这是老外的原话:

In visual studio 2015, stdin, stderr, stdout are defined as follow :

#define stdin  (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))

But previously, they were defined as:

#define stdin  (&__iob_func()[0])
#define stdout (&__iob_func()[1])
#define stderr (&__iob_func()[2])

So now __iob_func is not defined anymore which leads to a link error when using a .lib file compiled with previous versions of visual studio.

To solve the issue, you can try defining __iob_func() yourself which should return an array containing {*stdin,*stdout,*stderr}.

Regarding the other link errors about stdio functions (in my case it was sprintf()), you can add legacy_stdio_definitions.lib to your linker options.

答题意思就是stdin, stderr, stdout 这几个函数vs2015和以前的定义得不一样,所以报错。

解决方法呢,就是使用{*stdin,*stdout,*stderr}数组自己定义__iob_func()

其实就是下边这样。

extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }

然后__imp__fprintf的解决方法就是在链接器输入lib里加上legacy_stdio_definitions.lib这个LIB