Posted on 06-05-2015
Filed Under (Technology) by bigbang

In Android jni folder, we will always add some C/C++ header file folders. Basically, there are two ways to do this job.

Option 1:

Add one of the following lines to your Android.mk inside a module of your choice:

LOCAL_C_INCLUDES := /path/to/your/includes # ignore previous includes
                                           # OR
LOCAL_C_INCLUDES += /path/to/your/includes # preserve previous includes

If necessary you could create an environment variable pointing at ‘/path/to/your/includes’ and include it like this:

LOCAL_C_INCLUDES := $(MYLIB_INCLUDES_PATH) # ignore previous includes
                                           # OR
LOCAL_C_INCLUDES += $(MYLIB_INCLUDES_PATH) # preserve previous includes

If you write following code but there is no effect:

LOCAL_C_INCLUDES := ../example/include
LOCAL_C_INCLUDES += ../example/include2

please add $(LOCAL_PATH) to them, which will be:

LOCAL_C_INCLUDES := $(LOCAL_PATH)../example/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)../example/include2

Option 2:

  1. Copy the complete folder with all header-files in it (mylib) into the ‘jni’ folder of your project.
  2. Add the following line to your Android.mk inside a module of your choice:
LOCAL_C_INCLUDES := $(LOCAL_PATH)/mylib

or

LOCAL_C_INCLUDES += $(LOCAL_PATH)/mylib

Depending on whether there are previous includes or not. If the include is the first one, use the first examle which use := as keyword. If has previous includes, use latter which is += as keyword.

(0) Comments    (56) Views    Read More   

When we put the jni folder under projects and compile it using command line tool ndk-build, we will get libs & obj folders like this:

|--jni
|--libs
|----armeabi-v7a
|--obj

But under Android Studio develop environment, android studio can’t find the so files under libs folder.

We can do it by using following folder structure under Android Studio:

|---app
|------jni
|------libs
|------obj
|------src
|---------androidTest
|---------main

We can use this folder structure to compile JNI. When we compile the JNI file, ndk-build will generate libs & obj folders.

Finally, we add following to android part in build.gradle to let Android Studio finds the so files generated by jni folder:

sourceSets.main {
    jniLibs.srcDirs = ['libs']
}

Finally, the build.gradle should look like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "org.waterlin.mediatester"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets.main {
        jniLibs.srcDirs = ['libs']
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
}

By this way, Android Studio can let you use local jni code to generate so library and integrated into your Android project.

(0) Comments    (70) Views    Read More   
Posted on 08-04-2014
Filed Under (Technology) by bigbang

If you are under Windows, you may need to config golang develop environment manually.

Get Emacs go-mode from misc/emacs/, there are two files: go-mode-load.el and go-mode.el.

Put them into your Emacs load-path, then add following code to .emacs:

;; golang mode
(add-to-list 'load-path "~/emacs/site-lisp/go-mode")
(require 'go-mode-load)
(require 'go-mode)

Then you can open go source file with syntax highlight now.

If you are under Ubuntu/Debian, the easiest way to install golang-mode is by:

sudo apt-get install golang-mode

After this installation, retart your Emacs then you can edit go source file with syntax highlight.

Posted on 08-04-2014
Filed Under (Technology) by bigbang

If you have a keyboard with two Alt keys (e.g. a US Keyboard), you will find that PuTTY doesn’t recognize the one on the right side. It is a fatal problem if you are using Emacs in putty on Windows to editing files on a remote computer.

After doing some reasearching on it, I think there are two soluctions for this problem.

  1. Easily fixed the problem with a simple registry edit

    The putty topic Right Alt Key Broken shows an easy solution for it by add following registry code:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
    "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,38,00,38,e0,00,00,00,00
    
  2. Use AutoHotkey to cheat Putty right Alt as left Alt

    Right click on AutoHotkey icon and click ‘Window Spy’ in the menu, you can get Putty class name in AutoHotkey. Then add following setting in current script in AutoHotkey:

    #IfWinActive ahk_class PuTTY
    RAlt::LAlt
    #IfWinActive
    

    Reload the script and you can use right Alt to invoke Emacs M-x key bindings in Putty.

I prefer the second way to fix the Right Alt Key Broken problem in Putty under Windows.

(0) Comments    (777) Views    Read More   
Posted on 01-04-2014
Filed Under (Technology) by bigbang

Django-Chartit looks like a good tool for drawing some data charts under Python Django framework.

But it is a little hard to get it ready for work. Here I remind of two key steps while using Chartit:

  1. add chartit to your INSTALLED_APPS.
  2. install simplejason if you get ‘use_decimal’ error.

    The error message is something like:

    TypeError at /charts/
    __init__() got an unexpected keyword argument 'use_decimal'
    

I don’t think Chartit is the best choice current now, and I prefer Chart.js instead if you just want to draw some basic charts.

(0) Comments    (542) Views    Read More   
Posted on 01-04-2014
Filed Under (Technology) by bigbang

While I make my cpp source files linking ZeroMQ under Ubuntu, I got following error:

/usr/bin/ld: test_server.o: undefined reference to symbol 'zmq_strerror'
/usr/bin/ld: note: 'zmq_strerror' is defined in DSO /usr/local/lib/libzmq.so.3 so try adding it to the linker command line
/usr/local/lib/libzmq.so.3: could not read symbols: Invalid operation

The ZeroMQ library has already installed. By checking the man:

Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.

I get rid of the error by following steps:

  1. install libtool;
  2. add the library path to LD_LIBRARY_PATH;
  3. use root to make.

I think the last one, using root to make, is the key point. Why?

(0) Comments    (652) Views    Read More   
Posted on 27-03-2014
Filed Under (Technology) by bigbang

While I am using ‘go get’ command to install the libraries of GoLang, I get this error:

# pkg-config --cflags libzmq libzmq libzmq libzmq
exec: "pkg-config": executable file not found in $PATH

We need to install pkg-config to fix this problem. On Ubuntu, just use command:

sudo apt-get install pkg-config

It’s because that package (sdl) uses pkg-config to get necessary cflags and ldfalgs for compiler and linker, respectively.

(0) Comments    (702) Views    Read More   
Posted on 23-02-2014
Filed Under (Technology) by bigbang

I am using Clojure & Compojure to write my webpages, and I am trying to use Selmer as template system for Clojure.

Here is my template file structure: there is a basic template file base.tpl which defines basic header, footer or something else. And some other files like index.tpl, search.tpl to do the real job by including base.tpl template. The base.tpl file defines the common part of my site and changes few times during my project lifetime.

In some suitations, we need to modify base.tpl. But after modification of base.tpl, Clojure & Selmer don’t re-render base.tpl when I visit and render index.tpl file. So I need to restart lein ring server every time after I modify base.tpl.

It is too troublesome and forgettable to restart lein ring server every time after modified base.tpl. Finally I find the reason on Selmer official doc site:

Note that changes in files referenced by the template will not trigger a recompile. This means that if your template extends or includes other templates you must touch the file that’s being rendered for changes to take effect.

Alternatively you can turn caching on and off using

(selmer.parser/cache-on!)

and

(selmer.parser/cache-off!)

respectively.

(0) Comments    (610) Views    Read More   
Posted on 13-02-2014
Filed Under (Technology) by bigbang

While I am using Visual Studio 2008, there is an warning of this content:

warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

There is also this kind of warnings when you are using sprintf etc.. We can use preprocessor _CRT_SECURE_NO_WARNINGS to shutdown this warning.

(0) Comments    (402) Views    Read More   
Posted on 22-01-2014
Filed Under (Technology) by bigbang

I am using Clojure & Compojure to write my webpages, and I am trying to use Selmer as template system for Clojure.

Today I find a strange thing in my template file. I used following code to take the position of real content:

{{content}}

Then I generate real html content in my clojure code like this:

(defn index-render [params]
    "render file content of index.html"
    (let [basecon "<B>to be done</B>"]
    (render-file "./myproject/templates/front.tpl" 
               {:content basecon})))

But after render the content, the page just shows following content:

<B>to be done</B>

and I printed the html result I found following content in html:

&lt;B&gt;to be done&lt;/B&gt;

which means the render has escaped < and > to &lt; and &gt; for me.

The solution is very easy. Just use filter in template files.

Selmer is basically the same as The Django template language, so the Automatic HTML escaping is also basically the same. According to Filters part in Selmer online doc, the problem can be done by specifying a filter ‘safe’ following the name of the variable. The filters are separated using the | character.

So I change my templete file into

{{content|safe}}

and it works fine!

(0) Comments    (535) Views    Read More