How to include "time" library in the compiler?

Asked

Viewed 376 times

0

I am compiling in C on my Mac by terminal, this all a wonder, the only problem is that when I need to call a new library I don’t know what the command to call it by terminal.

Ex: #include <stdio.h> is -std=c99

I don’t know where I can find the terminal versions of calling functions, now I’m trying to call the library time.h unsuccessfully because I try something like -time do not compile, know where I find this information?

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

2 answers

3

You have to use #include <time.h> within your code. This should be enough because both the header and the library itself are in the same place as the other one that you’ve used and worked.

The -std=c99 has nothing to do with the include.

  • So I tried without calling, but it happened what I predicted, he doesn’t recognize the things that use the team. h pq is not in the terminal when I compile, when compiling with the terminal it is not enough to call in include. I’m doing a game on Allegro and for all functions that use other libraries I have to, besides calling the function in the code, I have q call it when compiling if not it does not recognize. The Allegro libraries had easy names to take away having as reference the header so I had no problems.

  • You must be using the compiler the wrong way but you didn’t pass the error, or exactly what you did with all the details, so I don’t know how to help you. I answered what I could to answer according to the question.

0

(as @Maniero has already replied) in principle cc -o exemplo exemplo.c would be enough for this case.

some notes (some details may vary with the operating system):

  1. Normally, time.h (as well as other files .h) contains only function statements (and some types), do not define them. Therefore, it is not libraries but only statements. The definitions of these functions are contained in the C base library (something like libc) along with a few hundred other functions.

  2. when we need functions that do not belong to the C library (some example sqrt()), include your statement (#include ) and join the respective library (-lm) the compilation line. When the compiler finds p -lm go find the library (.../libm.a or .so or similar) which contains the already compiled definition of these functions.

  3. the -std=c99 (how @Maniero had said little influences this issue) only changes the type warnings, the set of extensions that will be tolerated by the compiler.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.