Go to main content
Oracle® Developer Studio 12.5: C User's Guide

Exit Print View

Updated: June 2017
 
 

3.2.1 Selecting an Atomics Library

You can choose to use either the Oracle Developer Studio atomics library (libstatomic.so) or the GCC atomics library (libatomic.so), but it is important to make this consistent among executables and libraries that are linked together. Only one atomics library should be used in a running process.


Note -  If you do not need to be compatible with gcc-built libraries that use atomics, you should use libstatomic.so with the Oracle Developer Studio compilers.

To control which library is used at link time, use the –xatomic option. To link to Oracle Developer Studio's library libstatomic, use –xatomic=studio and to link to GCC's library libatomic, use –xatomic=gcc. To prevent linking with a library, use –xatomic=none.

As an aid to porting existing Makefiles or source code that uses GCC compilers, if –latomic is passed to the compiler, the option is converted to –xatomic=studio.

For C++ programs, the atomic support library is linked by default, when needed.


Note -  The –xatomic=none option ensures that the application does not have the Oracle Developer Studio libstatomic installation directory as a run path. In order to build the application that calls the library functions with –xatomic=none, libstatomic.so should be linked explicitly at build time.

Deploying Applications that use libstatomic.so

The bundled atomics library libstatomic.so is fully supported as a part of the Oracle Developer Studio product. You can deploy an application that uses the library, but you need to include the library unless the application will run on a system where Oracle Developer Studio is installed.

  1. Determine the run-time path from your executable to listatomic.so.

    For example:

    ./lib
  2. Determine the build-time path to libstatomic.so.

    For example:

    build-path/import/libstatomic.so
  3. Add –xatomic=none to your linking step.
  4. Add new link time options.

    For example:

    –R runtime-path build-path-to-atomics/libstatomic.so.1
  5. Copy the libstatomic library into your own product installation tree.
Example 1  Including libstatomic.so With a myprog Executable

The following example deploys an application on a 64-bit SPARC platform that does not have Oracle Developer Studio installed.

Before the application is built on the build machine, decide where libstatomic will be located relative to the executable. For example, if your application is located at app_root, and the libstatomic library is in app_root/lib, the relative directory of the library is ./lib.

bash-4.1$ ls app_root/
lib     myprog
bash-4.1$ ls app_root/lib/
libstatomic.so    libstatomic.so.1

On the build machine, determine where libstatomic.so is located. For example, if Oracle Developer Studio is installed in install-dir/, then libstatomic.so is located at install-dir/lib/compilers/atomic/sparcv9/libstatomic.so.

Compile the program, using the following command:

$ install-dir/bin/CC -m64 [compiler-options] -xatomic=none myprog.cc -o myprog -R./lib install-dir/lib/compilers/atomic/sparcv9/libstatomic.so

On the deployment machine, create the package directories.

Then copy the 64-bit libstatomic.so library to app_root/lib.

$ cp install-dir/lib/compilers/atomic/sparcv9/libstatomic.so app_root/lib

Copy the resulting executable for myprog to the app_root directory. This enables the runtime linker to find libstatomic.so under ./lib when myprog is executed.

$ cp myprog.out app_root