Showing posts with label gnu. Show all posts
Showing posts with label gnu. Show all posts

Tuesday, November 24, 2009

use glib

1. install glib

$ apt-get install libglib2.0-dev


2. write source code to print "hello world!"

#include
int main(int argc, char** argv)
{
g_printf("hello world!\n");
}


3. compile

gcc `pkg-config --libs --cflags glib-2.0` hello.c

Monday, March 23, 2009

generate ssh key for github

It looks to me that github is a good place to host open source. Also git is aimed to replace svn, so I would move to git from svn. (currently googlecode is with svn).


$ git config --global user.name "foo"
$ git config --global user.email "foo@gmail.com"
$ cd sur
$ git init
$ git add sur.w %my source code
$ git commit -m "first commit"
$ git remote add origin git@github.com:dsmarkchen/sur.git
$ git push origin master

I got permission denied error message. It is not very hard for me to figure it out.

1. try to connect to github by ssh (it helps to know the problem)

ssh -v git@github.com


2. generate the public key

$ cd ~/.ssh
$ ssh-keygen -t rsa


3. Add the the content of id_rsa.pub to github, then I am ready to see
the magic.

Thursday, November 6, 2008

coding standard (GNU)

I feel I am quite like the coding standard with GNU by reading GTick.

1. variables and variable types are small characters. (add "_t" for types)
dsp_t* dsp;


2. function names are small characters, and written in this way: (in function name: words are connected by "_", this is my favorite way)
dsp_t* dsp_new(comm_t* comm);


3. comments in this layout.
 /* headers*/
#include < stdio.h>
#include < stdlib.h>

/*
* brief.
*
* input: from: data source of input
* from_size: the number of frames in [from]
* output: to: the pointer to the allocated data.
*
* NOTE: here is the note. [to] should be free by the caller.
*/
static int foo(short* from, int from_size, unsigned char** to);


4. CONSTANTS and MACROES are large characters.

Thursday, September 18, 2008

patch

As I use cvs for code control, I found patch is a good tool that helps to build the actual release. To do actual release, some times I need to make changes on the code such as change the macro of "#define ENABLE_FOO 0" or some thing else, and these change may not be good to commit to cvs, and I also don't want to create branch with cvs, as each branch can be orphan if I forget to update. So the basic way is:

1. cvs tag
2. modify some code and build the release.
3. make patch (I use tortoriseCVS)

When you want to apply the patches, first make sure you can the patch is for what 'tag' version. after that
1. cvs co -r "tag" "module name"
2. go to the directory you just check out the source code.
3. patch -p0 < "your patch file"

Monday, August 25, 2008

fpos_t

When compile with gcc, it prompt "cannot convert fpos_t to long int".

Here is the solution:


long dataOffset;
fpos_t filepos;
...
dataOffset = filepos.__pos;

Thursday, May 22, 2008

gnu make on win32 shell

1. The version of gnu make that works on win32 is 3.80, while both 3.78 and 3.81 would not work.

2. win32 shell script. The following is a sample which uses cvs to check out foo source code


@echo off

set PRJ_DIR=%PRJ_ROOT%\foo-%PRJ_TSTAMP%
set PRJ_NAME=foo
if "%1"=="-D" goto check_out_tstamp;

echo "check out HEAD of %PRJ_NAME%"
cvs co -d %PRJ_DIR% -P %PRJ_NAME%

goto end;

: check_out_tstamp
echo "check out with time stamp"
cvs co -D %PRJ_TIME% "-d" %PRJ_DIR% -P %PRJ_NAME%

:end

Wednesday, January 16, 2008

gcc - shared library

When I link the shared library in dynamic mode on FC5 (Fedoral Core 5), I got a failure when run my executables: "cannot restore segment prot after reloc: Permission denied", is it only happend on FC5?

# make compile
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -x c++ -c -Wall -Wno-unknown-pragmas -fno-common -fbounds-check -pipe -g -Wno-deprecated -pipe -o foo.o foo.cpp
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -shared -o libfoo.so foo.o -lc
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-ar -rcs libfoo.a foo.o
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -x c++ -c -Wall -Wno-unknown-pragmas -fno-common -fbounds-check -pipe -g -Wno-deprecated -pipe -o test.o test.cpp
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -dynamic -L. -lfoo -o test test.o
/opt/crosstool/i686-unknown-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/i686-unknown-linux-gnu-g++ -static -L. -lfoo -o test.static test.o libfoo.a
# ./test
./test: error while loading shared libraries: ./libfoo.so: cannot restore segment prot after reloc: Permission d[...]


Here is the solution:

# chcon -t textrel_shlib_t ./libfoo.so