Main Page Basics, Building SPICE Applications (C)
## Table of Contents
       Basics, Building SPICE Applications (C)
          Note About HTML Links
          Environment Set-up
             Unix/Linux
             Windows
          A simple example program
             Unix/Linux
             Windows
Top # Basics, Building SPICE Applications (C) March 01, 2023 Top ## Note About HTML Links The HTML version of this lesson contains links pointing to various HTML documents provided with the Toolkit. All of these links are relative and, in order to function, require this document to be in a certain location in the Toolkit HTML documentation directory tree. In order for the links to be resolved, if not done already by installing the lessons package under the Toolkit's ``doc/html'' directory, create a subdirectory called ``lessons'' under the ``doc/html'' directory of the ``cspice/'' tree and copy this document to that subdirectory before loading it into a Web browser. Top ## Environment Set-up Top ### Unix/Linux Assume CSPICE is installed at /naif/cspice/. The corresponding path for the CSPICE library being /naif/cspice/lib/cspice.a. Use a terminal window. Top ### Windows Assume CSPICE is installed c:\naif\cspice\. The corresponding path for the CSPICE library being c:\naif\cspice\lib\cspice.lib. Launch a command window with pre-set Visual Studio C compiler environment variables:
       Programs ->
          Visual Studio YYYY ->
             x64 Native Tools Command Prompt
Top ## A simple example program This program calls the CSPICE function 'tkvrsn_c' then outputs the return value. File tk_ver.c:
       #include <stdio.h>
       #include "SpiceUsr.h"

       int main()
          {
          ConstSpiceChar  * versn;

          versn = tkvrsn_c( "TOOLKIT" );

          printf( "Toolkit version %s\n", versn );

          return(0);
          }
Top ### Unix/Linux This example uses the GNU C compiler (gcc):
       $ gcc tk_ver.c -o tk_ver -I/naif/cspice/include \
                      /naif/cspice/lib/cspice.a -lm

       $ ./tk_ver
       Toolkit version N0067
SPICE library naming does not conform to the UNIX convention of libname.a for use with the -L/path_to_libs/ -lname_of_lib compile options. Top ### Windows This example uses the Microsoft Visual Studio 7 C compiler (cl):
       > cl tk_ver.c -Ic:\naif\cspice\include c:\naif\cspice\lib\cspice.lib

       > .\tk_ver.exe
       Toolkit version N0067