How to compile a *.c file with Clang to signal problems?

Asked

Viewed 1,093 times

5

In GCC I typed in the terminal:

gcc -wall -o nomedoarquivo.c nomedoexecutavel

or if you only had 1 file . c [OBS.: typed "a" to make it easier in the]:

gcc -wall -o *.c a

The restriction I used, if there is in the code the library math.h, had to add -lm in the code. Then it would look like this:

gcc -wall -o *.c a -lm

How should I type to compile the same file using Clang problems in the code? There are some restrictions?

  • clang -Weverything ... but don’t complain that you give too much warning :)

  • I use all gcc flags in the Clang. So far I have had no problem, I would like to know if there are any.

2 answers

4

The Clang is built quite modularized so that the command line processor (called driver) is completely separate from the compiler itself. There are basically two drivers. One that has identical interface to GCC and another, much more recent, that simulates the MSVC tools.

That means all you need to do is s/gcc/clang/g. All gcc options will work smoothly. To report a healthy amount of alerts use -Wall -Wextra.

  • 1

    +1 "A healthy amount of alerts" :)

3

the parameter is -Wall

I use it in a different order than the one you are using. I think in the end it becomes clearer.

clang -Wall nomedoarquivo.c -o nomedoexecutavel

clang -Wall *.c -o a

clang -Wall *.c -lm -o a

Browser other questions tagged

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