“All other things being equal, the simplest solution is the best.” - this is the essence of occams razor and the reason why I enjoy so much finding minimalist coding solutions that acheive the same functionality as unneccessarily large and complex frameworks.

This time, I would like to introduce a great, lightweight, intuitive, cross platform thread wrapper - libpsync. It is written by Benbuck Nason and can be downloaded from:

http://sourceforge.net/projects/libpsync/ 

 Enjoy !

The information below is taken from an MSDN forum:

it is just the first search result I tried and it worked (actually the first part didn’t work but the second did), which is why I’m posting the information here:

Go to Tools->Import and Export Settings…Select Reset all settings.

I figured I didn’t have anything to lose, so selected to just reset settings, overwriting my current settings, but I imagine that saving the settings wouldn’t hurt anything.

I selected Visual C# Development settings, but i imagine (again) that the others would work equally well.

Hit Finish, and everything was fine.

If that doesn’t work, try going to:
\Program Files\Microsoft Visual Studio 8\Common7\IDE
and execute devenv /setup from the command line and try again.”

As every good software developer knows, part of a good design is writing loosely coupled code. Having a set of discrete black boxes gives you a lots of advantages in debugging, unit testing, refactoring, stability, maintaining the code etc. etc.

However, for some reason this knowledge doesn’t seem to stop experienced software developers from writing tightly coupled software libraries.

What do I mean by tightly coupled software libraries ? Well, I’ll explain by an example: the other day I was looking for a simple cross platform C++ socket wrapper for the JNEXT project. It also had to have a license which is not too restrictive commercially (something like MPL,Boost,public domain etc).

With the richness of source code available on the Web you’d think this would be quite easy to find but all the socket wrappers I found were too heavy for what I needed. So I decided to take a look at one of the many good open source cross platform libraries available - ACE, Boost, Poco, PWLib and a few others. Don’t get me wrong - these libraries are great, but it is impossible to take a relevant cpp and header file from them and just add them to your project because they depend on too many other definitions in the library framework.

Sometimes you just need a specific functionality - It would be much easier if you could just select the source component you need without building a gigantic library and then linking it to your application which can on occasion lead to injecting your application with unnecessary bloat.

By the way - I did eventually find a great cross platform C++ socket wrapper with a very liberal license, so if you are looking for a wrapper like this, let me save you the time I’ve wasted:

http://www.msobczak.com/prog/bin/sockets.zip

The above link is from the home page of Maciej Sobczak and also has many other very useful and high quality C++ code and libraries available for downloading. The irony is that one of these quality libraries is SOCI (which is a superb database abstraction library) which I’ve already used in JNEXT for the SQLite plugin, which goes to teach you that if you find one gem at a site you should take the time to look for others…

From JS to OS…

September 4th, 2007

I’ve completed a first complete working and tested version of the JavaScript native extensions. It will soon be hosted and available for download at http://www.jnext.org (soon like in next week).

The jnext framework will enable to securely access local native OS resources such as sockets, files, databases or any thing else you can imagine via JavaScript from within a Web page in a browser.

The framework uses ActiveX on Windows IE and NPAPI for other browsers and platforms. It has been tested thoroughly on both Linux and Windows.

If there is any native function or class you wish to add support for from JavaScript, just write your own extension to jnext. As in the tradition of this site - the learning curve for adding your own extension is close to nothing - just copy the sample template code for a plugin and start implementing whatever you like, knowing you will then be able to use these extensions on any browser and any platform (any exceptions will quickly be dealt with).

Now is the time where I want to invite developers to write additional plugins (currently only async TCP sockets are implemented but I intend to add a new extension every couple of days, the next on my list being file and SQLite extensions.

The sky’s the limit here - the last gap in making JavaScript truly awesome has been bridged - knock yourself out… :-)

-Amnon

I wasted a lot of time today trying to understand why a certain code did not find a function (via the function name) in a shared object ( Linux equivalent of Windows DLLs ). The same code had no problem finding the function in the Windows DLL version. The function was a simple C function (although it was defined in a cpp file which contained som C++ class definitions and implementations)

If you encounter this problem, I’ll give you the short version of the story so you can carry on with your work without having to listen to boring war stories: When you compile a shared library with g++, and the C functions you export are defined within a cpp file that might also contain other C++ code, you have to wrap the exported C function definitions with an

extern “C” {

// … exported function definitions go here

}

otherwise the exported functions will get mangled by the compiler in the same way C++ methods do and the code that tries to find the function by its name will not find it.

Ok - boring war story comes here, continue only if you have nothing better to do:

After trying just about every relevant combination of g++ compiler flags, I eventually arrived at the conclusion that the name is either not exported at all or it is exported incorrectly. I had a suspicion that it might be due to g++ mangling the C function names. Searching the net I learned that the readelf utility can, among other things dump all the symbolic names exported by a shared library (yes, you already know this but I’m refreshing my Linux knowledge after a long break…). The function I was looking for was named “SetEventFunc” so I ran a :

readelf -s Sockets.o | grep SetEvent

sure enough - what was found was a function named: _Z12SetEventFuncPFvPKcE

no wonder the function was not found

I then wrapped the exported C functions in extern “C”, rebuilt the library and the next grep showed a clean SetEventFunc (as shown below)

Shared library mangled exports

I guess what threw me off was the fact that in Windows, the compiler (VS2005) doesn’t seem to mangle C style functions, even if they are declared in a C++ file, so the problem never came up in windows.

By the way - the screen shot above is my first screen shot on Linux, performed with the standard tools described here - I have to say that Linux in general and Ubuntu in particular are starting to grow on me. I’m writing this from a virtual VMWare Ubuntu desktop, but the more I use Ubuntu, the more I feel like making my Windows XP the VMWare guest OS instead of the VMWare hosting OS…

PWLib and Ubuntu

August 23rd, 2007

Apparently (as was to be expected), it wasn’t a problem with the Fedora configuration that caused problems running configure for the PWLib library. When I attempted to do the same on Ubuntu, I got the same problem when running configure:

checking for g++ … no
checking for c++ … no
checking for gpp … no
checking for aCC … no

etc. etc.

After some searches, it became evident that just having the gcc compiler install isn’t enough and what was missing is the build-essential package.

On Ubuntu, this is solved by:

$sudo apt-get install build-essential

(on other systems you would probably need to replace apt-get with yum, yast or something else)

I got the lead for this here

The next step was to try and build PWLib. Apparently there are two more libraries that had to be installed:

$sudo apt-get install flex

(otherwise you get: configure: error: pwlib needs the GNU Project fast lexical analyzer generator flex)

$sudo apt-get install bison

(otherwise you get: configure: error: pwlib needs the GNU Project parser generator bison)

Onwards and Upwards

August 23rd, 2007

I completed the framework for the JavaScript extensions on Windows + firefox. What is left to complete before I release the sources is the following:

  • Support for Firefox on Linux
  • Support for IE on Windows
  • Some cleaning up

If all goes well, I should be able to release the first version of jsex (sexy name right ?) within around a couple of weeks.

I first tried to create a development environment on Linux by running Fedora Core 6 on VMWare, but got so many issues just trying run configure for PWLib that I switched to Ubuntu as I’ve heard good things about it.

The first thing I wanted to do was to create a root account on Ubuntu (by default the VMWare image from the Ubuntu site does not have a root account - only a user ubuntu with password ubuntu. To set a root account on Ubuntu, do the following (I found the answer here)

  1. Open a terminal window
  2. Type: sudo passwd
  3. You will be asked for a password. Type: ubuntu
  4. Next you will be asked for the root password. Choose and enter a root password
  5. Confirm the root password you have previously entered.
  6. That’s it - you have created a root account and set the root password.

The next problem that I encountered was when trying to install a new software - in my case, trying to install cvs. In Ubuntu, you do this by typing:

apt-get install cvs

Ubuntu responded with the following:

Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
cvs
0 upgraded, 1 newly installed, 0 to remove and 114 not upgraded.
Need to get 0B/1658kB of archives.
After unpacking 3617kB of additional disk space will be used.
Media change: please insert the disc labeled
‘Ubuntu 7.04 _Feisty Fawn_ - Release i386 (20070415)’
in the drive ‘/cdrom/’ and press enter

now I don’t have an Ubuntu CD and anyway I wanted to install cvs from the network and not from a CD. I finally found the answer here which is to open the file /etc/apt/sources.list and comment out the entries related to cd-rom sources.

ok - moving on to compiling the JavaScript extensions on Linux…

JavaScript Extensions

August 20th, 2007
Comments Off

I plan to soon release a first version of cross platform native Browser JavaScript extensions. The idea is to combine the power of JavaScript and DHTML with the power of native OS support such as sockets, files, databases - you name it. I already had this project almost ready for release almost a year ago but left due to priority changes. Google recent release of Google Gears and various other developments have made a step in the right direction but lack some options, which led me to decide to complete the original plan. The extension will be implemented both via an ActiveX for IE and via an NPAPI plugin for Mozilla based browsers. I hope to release it within a couple of weeks.

While compiling the project again with VS2005, I received lots of linker errors relating to unresolved externals in libcpmt.lib such as std::exception::exception . This was only when compiling a Release build. A Debug build completed with no issues. After running a quick search, I found a good lead here. I ran a quick search for libcpmt.lib files on my disk and sure enough, there was an abundance of them dispersed among various SDKs that are in my search path. I then added a /verbose option in the command line of the linker which confirmed that the wrong libcpmt.lib was being linked to create the plugin DLL. rearranging the order of the library paths sorted it out.

Posted in Time savers | Comments Off

I’d like to list the tools I always install each time I move to a new PC. Many of the tools listed here work on both Windows and Linux, but since I spend most of my development time in a Windows environment, there are also some tools that only work on Windows. I will point out those tools that are Windows specific.

I like to keep my desktop clean so what I usually do is create a tools folder and place all the tools (or their shortcuts) in that desktop folder for easy access.

So, here are the list of tools that I find indispensable in my work (where possible I have preferred open source applications. Links open in a new Window):

Software Development Environments:

  • NetBeans for Java development
  • Microsoft Visual Studio 2005 Express Edition for C++ development. The service pack is here. Windows only.
  • Aptana for Javascript development (actually, I personally prefer to develop Javascript with a text editor and FireBug, but I thought this IDE should be mentioned)
  • WAMP5 - Windows Apache + MySQL + PHP5 (again, I prefer using my favorite text editor to code PHP scripts). Windows Only

Text Editors (with syntax coloring for many languages of course):

Other tools I use:

  • WireShark network protocol analyzer (used to be known as Ethereal).
  • 7zip - used to open or compress files in various formats including bz2 and of course 7z
  • Adobe Acrobat Reader - no introduction necessary.
  • File Difference and Merge tools: WinMerge for Windows and Meld for Linux
  • VMWare player - to run your Windows, Linux or whatever OS in a virtual machine within your Windows, Linux or whatever OS… You can even clone the host OS to a virtual OS image using their free VMWare Converter tool.
  • TkSQLite - A great tool to manage SQLite databases (both 2.x and 3.x versions).

Windows Specific Tools

  • Sysinternals Suite - if you develop on Windows, get these.
  • JKDefrag - the best disk defragmenter for Windows that I’ve came across.
  • DTaskManager - a replacement for the standard Windows Task Manager. No more pesky processes that refuse to terminate…
  • PDFCreator - create PDF documents from almost any Windows application

Thats about all I need. Note that there are a lot more free tools out there, for example check out the free country site. I’ve just listed above those that I use on a regular basis.

When attempting to bring a project up to date with the latest Microsoft SDKs, the project did not compile. I had this issue before when re-compiling a project on Windows Vista and yesterday a similar problem occurred on Windows XP. I forgot how I solved the problem on Windows Vista - next time I encounter it I’ll describe the solution - but while its fresh in my mind, here is what I did to solve it on XP.

First a description of the problem: I needed to compile a project which requires the Windows Server 2003 R2 Platform SDK and the DirectShow SDK and the Windows Media Format 11 SDK. Now the DirectShow SDK is part of the platform SDK, but requires among other things a file named ddshow.h which is not available with the latest platform SDK, so you have to download and install the latest DirectX SDK in order to be able to compile the DirectShow that comes with the Platform SDK. Confused yet ?

Now after I installed the latest Platform SDK , the latest DirectX SDK (I only needed the libraries and include files) and the WMFSDK11 (Windows Media Format) SDK, set the new directories in Visual Studio 2005 and compiled, the compiler started choking on several types that it claimed are not recognized in propsys.h (such as PROPERTYKEY and REFPROPVARIANT). Now the thing is that these type are defined in wtypes.h, but there are several wtypes.h files that reside in the different SDK folders and only the wtypes.h in the WMFSDK11 include folder contained the definitions for the types the compiler complained about. So at this point I just put the include directory of the WMFSDK at the top of the list, recompiled and hoped for the best. This, however caused some clashes:

1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\shobjidl.h(1950) : error C2365: ‘SHCOLSTATE_TYPE_STR’ : redefinition; previous definition was ‘enumerator’
1> c:\wmsdk\wmfsdk11\include\shtypes.h(425) : see declaration of ‘SHCOLSTATE_TYPE_STR’
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\shobjidl.h(1951) : error C2365: ‘SHCOLSTATE_TYPE_INT’ : redefinition; previous definition was ‘enumerator’
1> c:\wmsdk\wmfsdk11\include\shtypes.h(426) : see declaration of ‘SHCOLSTATE_TYPE_INT’
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\shobjidl.h(1952) : error C2365: ‘SHCOLSTATE_TYPE_DATE’ : redefinition; previous definition was ‘enumerator’
1> c:\wmsdk\wmfsdk11\include\shtypes.h(427) : see declaration of ‘SHCOLSTATE_TYPE_DATE’
etc…

at this point, as it was getting late and my patience was growing short, I took the drastic step and simply opened up the above shobjidl.h in the SDK and commented out lines 1948 to line 1969 in that file which contain the redefinition of the types which were already defined in the WMF11’s shtypes.h

After that point, everything compiled fine. I suppose that are more elegant ways to do this but I don’t have the luxury to spend time on researching how to get the SDKs working together in perfect harmony - and you probably don’t have that time either so hopefully, this will save you the time I wasted.

Below is the order of the include folders that was set in Visual Studio 2005 (right click and select View Image or something similar to view it in a normal size)

include dirs

Note that the Server 2003 R2 Platform SDK is replaced by the new Windows SDK - maybe if I’d have installed that things would have been smoother. If I ever need it, I’ll post an update…