Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
LIBRARY_PATH和LD_LIBRARY_PATH是Linux下的两个环境变量,二者的含义和作用分别如下:
LIBRARY_PATH环境变量用于在程序编译期间查找动态链接库时指定查找共享库的路径,例如,指定gcc编译需要用到的动态链接库的目录。设置方法如下(其中,LIBDIR1和LIBDIR2为两个库目录):
export LIBRARY_PATH=LIBDIR1:LIBDIR2:$LIBRARY_PATH
LD_LIBRARY_PATH环境变量用于在程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径,注意,LD_LIBRARY_PATH中指定的路径会在系统默认路径之前进行查找。设置方法如下(其中,LIBDIR1和LIBDIR2为两个库目录):
export LD_LIBRARY_PATH=LIBDIR1:LIBDIR2:$LD_LIBRARY_PATH
举个例子,我们开发一个程序,经常会需要使用某个或某些动态链接库,为了保证程序的可移植性,可以先将这些编译好的动态链接库放在自己指定的目录下,然后按照上述方式将这些目录加入到LD_LIBRARY_PATH环境变量中,这样自己的程序就可以动态链接后加载库文件运行了。
// trim from start
static inline std::string &string_ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
// trim from end
static inline std::string &string_rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
@alenstarx
alenstarx / log.h
Last active December 25, 2017 03:07
#ifndef DEF_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/ipc.h>
#include <sys/socket.h>
#include <sys/types.h>
@alenstarx
alenstarx / H264_Decoder.cpp
Created March 24, 2016 03:30 — forked from roxlu/H264_Decoder.cpp
LibAV parser and decoder example with openGL (YUV420 -> RGB shader).
#include "H264_Decoder.h"
H264_Decoder::H264_Decoder(h264_decoder_callback frameCallback, void* user)
:codec(NULL)
,codec_context(NULL)
,parser(NULL)
,fp(NULL)
,frame(0)
,cb_frame(frameCallback)
,cb_user(user)
@alenstarx
alenstarx / opengl_wrappers.c
Created March 24, 2016 03:40 — forked from roxlu/opengl_wrappers.c
A couple of wrappers for opengl which are handy when you want to provide some openGL features in your library. Simply embed these into your cpp file. (Note that your executable will become slightly bigger because of this.)
/*
See https://gist.github.com/roxlu/6152fccfdd0446533e1b for the latest version.
Author: roxlu
Twitter: http://www.twitter.com/roxlu
*/
/* ------------------------------------------------------------------------*/
#ifndef UTIL_STRING_UTILS_HPP
#define UTIL_STRING_UTILS_HPP
// trim from start
static inline std::string &string_ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
// trim from end
@alenstarx
alenstarx / get.js
Created May 5, 2017 15:18
GET requests in gjs with libsoup
const Lang = imports.lang;
const Soup = imports.gi.Soup;
let _session = new Soup.SessionAsync();
function GET(url, callback) {
let request = Soup.Message.new('GET', url);
_session.queue_message(request, Lang.bind(this,
function(session, message) {
@alenstarx
alenstarx / post.js
Created May 5, 2017 15:18
POST requests in gjs
const Lang = imports.lang;
const Soup = imports.gi.Soup;
let _session = new Soup.SessionAsync();
function POST(url, params, callback) {
let request = Soup.Message.new('POST', url);
let _params = Soup.form_encode_hash(params);
request.set_request('application/x-www-form-urlencoded',