1 Reply Latest reply on Mar 16, 2012 5:48 AM by 921987

    Compiling basic C Program

      I am a java programmer trying to learn C....any direction would be helpful.

      I have a simple C program that references sys/time.h. I am trying to execute some code and profile some timings. I have a declaration

      timeval startTime, endTime, interval;
      gettimeofday(&startTime, NULL);
      gettimeofday(&endTime, NULL);
      timersub(&startTime, &endTime, &interval);
      My editor indicated it finds timeval & gettimeofday fine. I ctrl-click on sys/time.h which includes a library bits/time.h which has a struct timeval. I can also ctrl-click directly to timeval and it is found in the editor.

      So on to the MakeFile. I used the makefile wizard and was able to get things compiling ok until I added in the time.h libraries, now they all break.

      This is my compile command generated by the wizard:
      cc -g -xCC -xopenmp -xloopinfo -lst -c -I/usr/include -I/opt/oracle/solarisstudio12.3/prod/include/cc -I/opt/oracle/solarisstudio12.3/prod/lib/compilers/rtlibs/usr/include -o dist/main.o main.c

      and a portion of my output
      "main.c", line 59: undefined symbol: timeval
      "main.c", line 59: syntax error before or at: startTime
      "main.c", line 67: undefined symbol: startTime
      "main.c", line 67: warning: argument #1 is incompatible with prototype:
           prototype: pointer to struct timeval {long tv_sec, long tv_usec} : "/usr/include/sys/time.h", line 73
           argument : pointer to int
      "main.c", line 73: undefined symbol: endTime

      I have messed around with the -I parameters and put them in different order. Where are the libraries supposed to be that I am working with? I found some blog indicating I needed a -lst parameter when working with time.h but doesn't seem to work.

      Any help would be very appreciated.

      Edited by: nyronian on Mar 15, 2012 10:05 PM
        • 1. Re: Compiling basic C Program
          I finally found that the example I was using was bad. [http://allmybrain.com/2008/06/10/timing-cc-code-on-linux/|http://allmybrain.com/2008/06/10/timing-cc-code-on-linux/]

          I had to simply define do:

          struct timeval startTime, endTime, interval;

          and it all worked.

          I couldn't find a way to delete the message or I would have. Thank you for your patience.