External libraries within a shader
I don't believe you can call external libraries but you can certainly log messages to the console using 'printf(...)', 'warning(...)' or 'error(...)' function calls. For example :

printf("Point %f,%f,%f\n", P[0], P[1], P[2]);


This can produce the following output :

Point 0.352600 -0.724535 0.683879
Point 0.377360 -0.151356 0.841542
Point -0.081450 -0.115284 0.909532
Point -0.075156 -0.181691 0.885011
Point -0.018898 -0.221594 0.864882
....


The 'warning(...)' and 'error(...)' calls work a similar way but include additional formatting around the output string :

WARNING: Shader warning [my_shader]: Point -0.320504 -0.812141 0.157532
WARNING: Shader warning [my_shader]: Point 0.304608 -0.822310 0.270545
WARNING: Shader warning [my_shader]: Point 0.626177 0.138751 -0.099909


Looking at the OSL spec, there is also an 'fprintf(...)' function that accepts an additional argument for the output filename and will append the output to that file (rather than having to capture the console output and extract the details from there). However, my particular version of Blender (2.76b) does not seem to support that - it's presumably implemented at a later version.