Friday, December 22, 2006

Linking 101

For many software developers, this post will be linking-101. Yet, recently I was looking into an issue on Windows (yes, I know), where an application developed using Visual Studio 2005, was linking against a libary developer with Visual C 6. I needed to understand a little more on how linking works in Windows. Many of these bullet points are known secrets. But if you lived too long in the Unix world, the Windows secrets will be a mystery and vice versa. So here's a short summary:

Windows
  • .dll is the extension for a Windows dynamic library. DLL Hell exists and even has a Wikipedia entry.
  • .lib is the extension for both a DLL wrapper, as it is used for static libraries. A DLL wrapper or "import" LIB file, which is used to link against. For each function the DLL exports, the LIB file contains a stub which will load and call into the DLL. You only need these .lib files when linking, but not when deploying.
    • If on Windows a DLL is missing, you will get hit during run time, as it can not find the DLL module to load. On Unix, the application will not start up. This has pro's an cons. Pro: if you do not want to use a particular feature of the application, which requires an expensive 3rd party library, you can still run the application. The con: if your application was doing a lot of work and then aborts, you will slap the machine a couple of times.
  • Convention: Files ending with z.lib or zd.lib are the static libraries. (d for debug)
  • C Run Time (CRT) libraries are development environment dependent. If your program links against both, you have to be very very careful. Since memory management are (slightly) different between CRTs, linking against malloc()/free() from different CRTs can corrupt your heap. The bug will unfortunately show up in weird and unrelated ways. The take away is avoid linking against two different CRTs. But if you have to, make sure you keep your program modules separate. For reference:
    • msvcrt.dll is used by VC6.0
    • msvcr70.dll for VS .NET
    • msvcr71.dll for VS .NET 2003
    • msvcr80.dll for VS 2005
    • with "d" added to the name for debug CRTs
Unix
  • Static libraries (archives) are created and updated by the ar (archive) utility. Convention dictates that static libraries have a ".a" extension on their filename.
  • Dynamically linked libraries are created by the link editor, ld. The conventional file extension for a dynamic library is ".so" (shared object).
  • You tell the compiler to link with, libpthread.so, by giving the option -lthread.
  • The compiler finds libraries as specificied by LD_LIBRARY_PATH or using the compiler option -Lpathname.
  • nm utility to the rescue when you run into Undefined Symbols
  • The order of statically linked libraries on the compiler command line is significant: (i..e they should be listed after your own code). Although I believe gcc can be instructed to make a few passes through the static library arguments to make sure undefined symbols, defined in previously stated static libraries are picked up.
  • Knowing which library files to link against is sometimes a mystery. Take a look at the #includes and guess the library name. Often the man pages might mention something as well.
An excellent book on gotchas, weird bugs and behaviors is Expert C programming - Deep C secrets, by Peter Van Der Linden. It is not a C programming text book. It is a collection of C programming experiences (aka the stuff for which experienced programmers get paid the big bucks). I happen to work on a few projects ((USB/CDRW) with Peter, when he was leading the I/O team in the Sun workstation group. He is a very interesting guy, who wrote many programming books from C to Java and Linux. Here's an interview with Peter from ITConversations.

Technorati:

Monday, December 11, 2006

E n g l i s h !

Living in the Bay Area, you hear a lot of different dialects, accents and levels of the English language. I am not a native English speaker myself, so I won't proclaim to be proficient in it. There are however two expressions which annoy me tremendously. More and more native English speakers are starting to use them. Argh!
  1. Long time no see - when meeting somebody after a long while. Wikipedia expands: "Long time no see" is a common Chinglish term, meaning "I haven't seen you for a long time"
  2. My bad - when making a mistake. Mea culpa.

Wednesday, December 06, 2006

It's about the data, stupid!

If you read my blog over the year (Software as a service, it's about the data platform) (Saas infrastructure, an update), you understand my view on who will hold the best cards on the internet in the future.

Today, I learned on TechCrunch about a interesting new company, who puts data central to their business: Swivel. "Swivel is a place where curious people explore data — all kinds of data.", according to their website. Ha! Right up my alley. It is like Chart of the Day, but then for all kinds of data. Here's an interesting one comparing Wine and Crime data sets (based upon 25 data points, imported from www.ers.usda.gov and bjsdata.ojp.usdoj.gov). How related are these items to one another? 77%, according to Swivel.

1054868

Swivel allows you to customize the graph and generates the html to embed into your blog. This might an interesting company to keep track of. .. mmh.. let's chart out Swivel page visits against the amount of newborns.

Technorati:

Netbeans C/C++ official release

I've been working with Netbeans and CND, the C/C++ pack for several months (see also Netbeans CND: revamped import wizard). Today is the official release of both Visual Web Pack (aka Creator) and the C/C++ Pack. Hurray!

Technorati:

The Biota bottle

Here's one of the coolest product I've seen in a while. My wife was sipping from a bottle of spring water: Biota, Colorado pure spring water. I had never heard of the brand. The name apparently stands for "Blame It On The Altitude(r)".

The water tasted great. It feels like a regular plastic bottle. And the logo is like any other logo for spring water: blue and with a snow covered mountain.


Until you read the label: the bottle is compostable!! COMPOSTABLE! How great is that?
BIOTA uses nature-based packaging from NatureWorks ™ PLA. NatureWorks ™ PLA is the first commercially viable packaging material derived entirely from an annually renewable resource - corn. BIOTA is the first beverage company in the world to exclusively use NatureWorks ™ PLA to bottle its products. BIOTA water bottles are completely compostable. They are approved and certified as commercially compostable by the Biodegradable Products Institute (BPI). Initial testing has demonstrated that a BIOTA water bottle will degrade within 75 to 80 days in a commercial composting situation. A traditional plastic bottle will never biodegrade.
The information site has more details on the conditions under which composting works well:

How does the BIOTA bottle composting process work?
BIOTA bottles need high heat, micro-organisms and high moisture levels to break down. A BIOTA PLA bottle will not degrade as rapidly in a home compost pile. When exposed to the necessary conditions, BIOTA bottles will break down into water, carbon dioxide and organic material.

How long does it take for a BIOTA bottle to disappear?
Given the right composting conditions including high heat, humidity and micro-organisms, a BIOTA bottle will disappear in 75 to 80 days...basically 12 weeks.

Technorati:

Sunday, December 03, 2006

Boom!

I am a big fan of Presentation Zen. The blog has a tremendous amount of info and tips on becoming a better public speaker. Steve Jobs is often used as an example. Here he is in real good form: