Tampilkan postingan dengan label C++. Tampilkan semua postingan
Tampilkan postingan dengan label C++. Tampilkan semua postingan

Manually install oSIP and eXosip as library on Mac OS X Mountain Lion

No problem with oSIP. Just do the usual configure && make && make install (the last one as root).

It is best to have the autotool from GNU, and not from Apple, of which autoconf and make are part. To install GNU autotool, please ryou need to install XCode (and the Command Line Tools: XCode -> Preferences -> Download -> Component -> Command Line Tools) and mac ports first (www.macports.org) and then:


Once xcode and macports are installed, open a terminal and install the required build-time tools with:

$ sudo port install coreutils automake autoconf libtool intltool wget pkgconfig cmake gmake yasm grep doxygen ImageMagick optipng


Install gas-preprosessor.pl (http://github.com/yuvi/gas-preprocessor/ ) to be copied into /opt/local/bin :

$ wget --no-check-certificate https://raw.github.com/yuvi/gas-preprocessor/master/gas-preprocessor.pl
$ sudo mv gas-preprocessor.pl /opt/local/bin/.
$ sudo chmod +x /opt/local/bin/gas-preprocessor.pl

Link macport libtoolize to glibtoolize

$ sudo ln -s /opt/local/bin/glibtoolize /opt/local/bin/libtoolize

Link host's strings to simulator SDK

For Xcode prior to 4.3:
$ sudo ln -s /usr/bin/strings /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/strings
For newer XCode:
$ sudo ln -s /usr/bin/strings /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/strings


The above lines are from the README of the linphone. Basically you want to install the autotools, but I don't actually know which part of those packages comprise autotools. Some of them are obviously not related to autotools, like the ImageMagick. But just to be safe.... :-))

So, after you install the autotool, the next thing to do is.... trying to configure. It went well for oSIP but not so well for eXosip. configure script for eXosip gave me this:


Undefined symbols for architecture x86_64:
  "_CFRelease", referenced from:
      __tls_add_certificates in eXtl_tls.o
  "_Gestalt", referenced from:
      __tls_add_certificates in eXtl_tls.o
  "_SecKeychainItemCopyAttributesAndData", referenced from:
      __tls_add_certificates in eXtl_tls.o
  "_SecKeychainItemFreeAttributesAndData", referenced from:
      __tls_add_certificates in eXtl_tls.o
  "_SecKeychainOpen", referenced from:
      __tls_add_certificates in eXtl_tls.o
  "_SecKeychainSearchCopyNext", referenced from:
      __tls_add_certificates in eXtl_tls.o
  "_SecKeychainSearchCreateFromAttributes", referenced from:
      __tls_add_certificates in eXtl_tls.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[2]: *** [libeXosip2.la] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

After some searching, I found out that I needed to link against frameworks on Mac OS. So instead of simply calling configure, I needed to call this:

LDFLAGS="-framework CoreFoundation -framework CoreServices -framework Security" ./configure

And then make, and sudo make install. And done!

CoreFoundation is for _CFRelease, CoreServices is for _Gestalt and Security for the others (keychain access).

Code snippet to calculate md5 in C/Ubuntu

First, sudo apt-get install libssl-dev
And then, compile it using the -lcrypto flag to link against /lib/i386-linux-gnu/libcrypto.so.1.0.0 

#include
#include
#include
#include

char *str2md5(const char *str, int length) {
    int n;
    MD5_CTX c;
    unsigned char digest[16];
    char *out = (char*)malloc(33);

    MD5_Init(&c);

    while (length > 0) {
        if (length > 512) {
            MD5_Update(&c, str, 512);
        } else {
            MD5_Update(&c, str, length);
        }
        length -= 512;
        str += 512;
    }

    MD5_Final(digest, &c);

    for (n = 0; n < 16; ++n) {
        snprintf(&(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
    }

    return out;
}

int main(int argc, char **argv) {
  char *output = str2md5("hello", strlen("hello"));
  printf("%s\n", output);
  free(output);
  return 0;
}

oSip and eXosip

I set out to understand linphone source code so I decided to learn SIP and tried to built a terminal SIP client. A simple one. No voice, no nothing, just to perform signalling, registering to SIP registrar. That's all.

I started out by learning oSip. I found out later that oSip is lower level, suitable to build lower level service like SIP proxies or registrars, but too cumbersome to build SIP clients. eXosip is more suitable (=easier to use) to build SIP clients since eXosip is a higher layer abstraction over oSip.

Anyway, I'll tell my story with oSip first. So I installed both osip and exosip on my Ubuntu using the default packaged.

sudo apt-get install libexosip2-dev

The above command will automatically install libosip2 since libosip2 is libexosip2's dependency. I adapted wen's tutorial here for Linux (he wrote it for Windows).

From oSip mailing list, Aymeric Moizard (oSip and eXosip author) told me that the packaged lib is outdated. The Ubuntu packaged library is version 3 (while the latest is version 4) and I needed to compile my source files using the switch  -DOSIP_MT . I don't need to use that option if I compile and link my source against the latest (v4) library.

I then decided to download the latest (version 4 as of this writing) oSip and eXosip source from the GNU repo and compiled and installed them on my own. The library is installed inside /usr/local/lib.
When reading the README of eXosip, it told me to install c-ares for asynchronous network operation, so I did that too.

There are quite some things that I learnt during compilation with these libraries.

First of all, I need to run ldconfig as a root right after I install the libraries. I don't really understand why, but otherwise I get numerous errors when compiling and then linking against the newly installed libraries.

Since I have two kinds of osip and exosip (one installed by apt-get, one manually installed), I need to tell the compiler which lib I want to use. I want to compile against the latest, which is manually installed, so this compiler option is necessary:

-L/usr/local/lib

It tells the compiler the location of my library. I also learnt how library naming system works. Library names end with .a extension and starts with the substring lib. For instance, the following is the result of doing ls /usr/local/lib on my system:



If you want to link against a certain library, then strip the lib and the extension from the library name, and prepend -l to it and use it as compiler option. So if you want to link against libeXosip2.a, you put this as compiler option:

-leXosip2

Or you can also use the cumbersome and longer form:

g++ myfile.c  /path/to/my/libeXosip.a

Anyway, the following is my simple Makefile to compile my eXosip source:


exosip: exosip.c
g++ -L/usr/local/lib -Wall -g exosip.c -o exosip -leXosip2 -lcares -DENABLE_TRACE


I needed to remove -DENABLE_TRACE (against what the README recommended) because it gave me errors. I need to find out why.