Compiling C libraries on OS X

If you have compiled or built shared C libraries before you would have come across the following code:

  
     gcc -c -fPIC some_code.c -o some_code.o
gcc -shared -Wl,-soname,mylib.so.1 -o mylib.so.1.0.1 some_code.o

The above essentially compiles native C code into object files using gcc compiler and then linking it into a library called ‘mylib.so’.

If you issue the command above on a MAC, you will get the following errors:

   
      /usr/bin/ld: unknown flag: -soname
      collect2: ld returned 1 exit status
    

Within OS X, the second command will not work as OS X treats shared libraries as dynamic libraries. The second line needs to be changed to:

   
      gcc -Wall -D_FILE_OFFSET_BITS=64 -fPIC -arch ppc -arch i386 -arch x86_64 -dynamiclib -o mylib.dylib calc_mean.o
   

Then move the shared library mylib.dylib into ‘/usr/lib/’:

  
    sudo cp -v mylib.dylib /usr/lib/
  
Tagged with:
 

Control your Nginx processes using signals

This is a follow up on my previous articles on using the NGINX server. On my older wordpress blog, I highlighted the steps involved in installing and getting NGINX running on your development environment. Here, I would like to share how I manage my nginx processes in the same development environment.

If you use Apache through the Passenger gem, you could type something like this to restart the server gracefully:

  
      sudo apachectl graceful
  

and to shutdown:

  
    sudo apachectl shutdown
  

To do the same in nginx, you would need to type the following:

  
     sudo kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`

What the above command does is to do a graceful shutdown of the master process, which would in turn call shutdown on the worker processes. Note the backticks and the cat command. What it does is to run the cat command on the pid file to grab the pid value and pass it to the QUIT signal.

If you need to reload the server after making changes to the configuration file (i.e. nginx.conf), just do:

  
    sudo kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

More command line options can be found on the NGINX wiki, which even details the sequence of events when signals are sent as well as how to upgrade an entire nginx executable on the fly with 0 downtime.

Sweet!

 

29 Steps relaunched!

29 Steps relaunch

After the initial launch of 29 steps, I decided to revamp the existing website to coincide with a new marketing strategy for the company. While there was nothing wrong with the original website, I felt that the design and overall look-and-feel was a bit amateurish and did not reflect the company accurately. I decided to re-design the site and in the process, stick it into a CMS for better management as one of the problems I had previously while using JEKYLL to generate site content is the apathy of having to code a single blog post by hand and republishing the content again (note a criticism of JEKYLL mind, more of my own laziness as it is a great system).Hopefully, with this system in place, it would ‘force’ me to write more blogs regularly.

A lot has happened since the launch of 29 Steps two months ago. We received quite a fair amount of requests for work, both in terms of Rails development and static design. Majority of the work is for bespoke projects which means I will not be able to disclose any further information due to the NDAs but where possible, I will provide short descriptions of what the projects are about.

Technically, I feel that I have learnt an awful lot more than I ever did. I am more confident with both Ruby Rails and the amount of front-end work I had to engage with means I’m also more comfortable and confident with javascript and css.

Other areas which I never had the opportunity to work with until now include the use of Google APIs such as with Google Maps whereupon I wrote an entire javascript application to locate certain areas using data from CSV files and also the use of Google Charts within my own payment application, keChing! to highlight the amount of payments made and received visually.

Where do we go from here? That’s one of the questions I keep asking myself . I like to think that it can only get better.

Let’s hope that the rest of 2009 will allow me to work on more exciting green-field projects and some open-source work. Check out G.O.R.T., a Rails 2,3 template which has the AuthLogic plugin built in together with the controllers, views as well as mailers to send emails for user subscriptions and registrations. The only thing that is missing is the css but it is meant o be generic so bring your own!

If you have any requests for any work to be done or just want to find out more, please contact us. We love to hear from you.