默认选项GCC

时间:2016-01-19 00:13:24

标签: c linux gcc

我在这个文件上使用C语言在Linux上工作:

#include "headerFiles.h"

#define TRUE  1
#define FALSE 0
#define BUFSIZE 256
#define SERVER_PORT 8887

int main (int argc, char *argv[])
{
    signal(SIGCHLD, SIG_IGN);

    int ls; // listen socket
    int s;  // descrittore socket
    int n;  // byte letti inviati
    int waitSize; // massimo numero persone in coda

    struct sockaddr_in serverAddr;
    struct sockaddr_in clientAddr;

    int clientAddrLen = sizeof( clientAddr );

    memset(&serverAddr,0,sizeof(serverAddr));

    serverAddr.sin_family = AF_INET;
    serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
    serverAddr.sin_port = htons(SERVER_PORT);

    if( (ls = socket(AF_INET,SOCK_STREAM,0)) < 0) {

        perror("Errore: creazione della socket di asolto fallita!");
        exit(1);
    }

    int so_reuseaddr = TRUE;

    if( fork() == 0) {

        //---------------------------------------------------//
        //CODICE
        while (1) {

            char cmd[BUFSIZE];
            char var1[BUFSIZE];
            char var2[BUFSIZE];
            char string[100];

            memset(cmd, 0, sizeof(cmd));
            memset(var1, 0, sizeof(var1));
            memset(var2, 0, sizeof(var2));
            memset(string, 0, sizeof(string));
        }
    }

    close(s);
    exit(0);
}

此代码代表C上的迷你服务器但我有这个问题: 如何检查我是否有默认的gcc编译器选项?

因为,例如,在Mac上我得到一些警告而在Linux上没有。

更新:

用于编译我使用这个makefile:

elaborato: *.c *.h
    gcc *.c -o elaborato

当我执行它时,我会:./elaborato

我想使用默认的gcc设置编译该程序。 这够了吗?

3 个答案:

答案 0 :(得分:2)

需要注意的一点是,您的gcc版本很可能与众不同。如果运行gcc -v,您将看到系统上启用的标志。例如:

gcc -v -o t9 t9.c

为我显示了一堆这样的行:

Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" \
-cc1 -triple x86_64-apple-macosx10.10.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage \
-emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name t9.c \
-mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose \
-munwind-tables -target-cpu core2 -target-linker-version 253.2 -v -dwarf-column-info \
-resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0 \
-fdebug-compilation-dir /Users/bruce/test -ferror-limit 19 -fmessage-length 193 \
-stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 \
-fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option \
-fcolor-diagnostics -o /var/folders/kl/kz62dj0j3zx7zvdgs7w005_w0000gn/T/t9-e101bb.o -x c t9.c
clang -cc1 version 7.0.0 based upon LLVM 3.7.0svn default target x86_64-apple-darwin14.5.0

除了选项都在一条非常长的行上,没有如此处所示包裹。

答案 1 :(得分:1)

在Mac上,clang可能是gcc -Wall -Werror的符号链接,-Wall是一个不同的编译器。尝试让您的代码使用-Wextra,然后Mac上应该没有任何问题:)

编辑:结合Olaf的异议,如果默认设置更高级别(如gcc -v),则传递-Werror可能会降低警告级别。默认情况下将使用的标志可以使用 + (void)drawDemos { collectedppaths = [NSMutableArray new]; //// Color Declarations UIColor* color2 = [UIColor colorWithRed: 1 green: 0 blue: 0 alpha: 1]; //// Group { //// demo 0 Drawing UIBezierPath* demo0Path = [UIBezierPath bezierPath]; [demo0Path moveToPoint: CGPointMake(35.5, 215.55)]; [demo0Path addLineToPoint: CGPointMake(86.38, 215.55)]; [demo0Path addLineToPoint: CGPointMake(86.38, 253.39)]; [demo0Path addLineToPoint: CGPointMake(35.5, 254.32)]; [demo0Path addLineToPoint: CGPointMake(35.5, 215.55)]; [demo0Path closePath]; [color2 setStroke]; demo0Path.lineWidth = 5; [demo0Path stroke]; [collectedppaths addObject:demo0Path]; //// demo 1 Drawing UIBezierPath* demo1Path = [UIBezierPath bezierPath]; [demo1Path moveToPoint: CGPointMake(35.5, 254.79)]; [demo1Path addLineToPoint: CGPointMake(86.38, 254.79)]; [demo1Path addLineToPoint: CGPointMake(86.38, 304.76)]; [demo1Path addLineToPoint: CGPointMake(35.5, 303.36)]; [demo1Path addLineToPoint: CGPointMake(35.5, 254.79)]; [demo1Path closePath]; [color2 setStroke]; demo1Path.lineWidth = 5; [demo1Path stroke]; [collectedppaths addObject:demo1Path]; //// demo 3 Drawing UIBezierPath* demo3Path = [UIBezierPath bezierPath]; [demo3Path moveToPoint: CGPointMake(86.38, 254.79)]; [demo3Path addLineToPoint: CGPointMake(102.71, 256.19)]; [demo3Path addLineToPoint: CGPointMake(122.78, 260.39)]; [demo3Path addLineToPoint: CGPointMake(138.19, 266)]; [demo3Path addLineToPoint: CGPointMake(155.46, 259.46)]; [demo3Path addLineToPoint: CGPointMake(169.46, 250.12)]; [demo3Path addLineToPoint: CGPointMake(177.86, 240.78)]; [demo3Path addLineToPoint: CGPointMake(183.46, 239.37)]; [demo3Path addLineToPoint: CGPointMake(182.53, 302.9)]; [demo3Path addLineToPoint: CGPointMake(88.24, 303.83)]; [demo3Path addLineToPoint: CGPointMake(86.38, 254.79)]; [demo3Path closePath]; [color2 setStroke]; demo3Path.lineWidth = 5; [demo3Path stroke]; [collectedppaths addObject:demo3Path]; //// demo 6 Drawing UIBezierPath* demo6Path = [UIBezierPath bezierPath]; [demo6Path moveToPoint: CGPointMake(183.93, 238.91)]; [demo6Path addLineToPoint: CGPointMake(182.53, 308.5)]; [demo6Path addLineToPoint: CGPointMake(279.61, 307.1)]; [demo6Path addLineToPoint: CGPointMake(279.61, 254.79)]; [demo6Path addLineToPoint: CGPointMake(208.2, 254.79)]; [demo6Path addLineToPoint: CGPointMake(191.4, 241.24)]; [demo6Path addLineToPoint: CGPointMake(183.93, 238.91)]; [demo6Path closePath]; [color2 setStroke]; demo6Path.lineWidth = 5; [demo6Path stroke]; [collectedppaths addObject:demo6Path]; //// demo 5 Drawing UIBezierPath* demo5Path = [UIBezierPath bezierPath]; [demo5Path moveToPoint: CGPointMake(182.99, 158.1)]; [demo5Path addLineToPoint: CGPointMake(279.14, 206.68)]; [demo5Path addLineToPoint: CGPointMake(279.61, 254.79)]; [demo5Path addLineToPoint: CGPointMake(208.66, 254.79)]; [demo5Path addCurveToPoint: CGPointMake(191.4, 241.24) controlPoint1: CGPointMake(208.66, 254.79) controlPoint2: CGPointMake(191.4, 241.71)]; [demo5Path addCurveToPoint: CGPointMake(183.93, 238.91) controlPoint1: CGPointMake(191.4, 240.78) controlPoint2: CGPointMake(183.93, 238.91)]; [demo5Path addLineToPoint: CGPointMake(182.99, 158.1)]; [demo5Path closePath]; [color2 setStroke]; demo5Path.lineWidth = 5; [demo5Path stroke]; [collectedppaths addObject:demo5Path]; //// demo 4 Drawing UIBezierPath* demo4Path = [UIBezierPath bezierPath]; [demo4Path moveToPoint: CGPointMake(218.47, 74.5)]; [demo4Path addLineToPoint: CGPointMake(225.47, 82.91)]; [demo4Path addLineToPoint: CGPointMake(232.94, 103.46)]; [demo4Path addLineToPoint: CGPointMake(241.34, 119.34)]; [demo4Path addLineToPoint: CGPointMake(260.01, 132.42)]; [demo4Path addLineToPoint: CGPointMake(281.48, 139.42)]; [demo4Path addLineToPoint: CGPointMake(279.14, 206.68)]; [demo4Path addLineToPoint: CGPointMake(182.99, 158.1)]; [demo4Path addLineToPoint: CGPointMake(182.99, 111.4)]; [demo4Path addLineToPoint: CGPointMake(179.26, 97.39)]; [demo4Path addLineToPoint: CGPointMake(218.47, 74.5)]; [demo4Path closePath]; [color2 setStroke]; demo4Path.lineWidth = 5; [demo4Path stroke]; [collectedppaths addObject:demo4Path]; //// demo 7 Drawing UIBezierPath* demo7Path = [UIBezierPath bezierPath]; [demo7Path moveToPoint: CGPointMake(281.95, 140.36)]; [demo7Path addLineToPoint: CGPointMake(300.62, 143.16)]; [demo7Path addLineToPoint: CGPointMake(319.75, 143.16)]; [demo7Path addLineToPoint: CGPointMake(352.42, 165.58)]; [demo7Path addLineToPoint: CGPointMake(359.43, 183.79)]; [demo7Path addLineToPoint: CGPointMake(387.9, 196.4)]; [demo7Path addLineToPoint: CGPointMake(397.7, 221.16)]; [demo7Path addLineToPoint: CGPointMake(377.16, 228.63)]; [demo7Path addLineToPoint: CGPointMake(297.35, 228.63)]; [demo7Path addLineToPoint: CGPointMake(292.68, 225.83)]; [demo7Path addLineToPoint: CGPointMake(289.88, 213.69)]; [demo7Path addLineToPoint: CGPointMake(279.14, 206.68)]; [demo7Path addLineToPoint: CGPointMake(281.95, 140.36)]; [demo7Path closePath]; [color2 setStroke]; demo7Path.lineWidth = 5; [demo7Path stroke]; [collectedppaths addObject:demo7Path]; //// demo 8 Drawing UIBezierPath* demo8Path = [UIBezierPath bezierPath]; [demo8Path moveToPoint: CGPointMake(279.61, 206.21)]; [demo8Path addLineToPoint: CGPointMake(289.88, 213.69)]; [demo8Path addLineToPoint: CGPointMake(292.68, 225.83)]; [demo8Path addLineToPoint: CGPointMake(297.35, 228.63)]; [demo8Path addLineToPoint: CGPointMake(376.7, 228.63)]; [demo8Path addLineToPoint: CGPointMake(397.7, 221.16)]; [demo8Path addLineToPoint: CGPointMake(400.5, 228.63)]; [demo8Path addLineToPoint: CGPointMake(393.5, 253.85)]; [demo8Path addLineToPoint: CGPointMake(279.61, 253.85)]; [demo8Path addLineToPoint: CGPointMake(279.61, 206.21)]; [demo8Path addLineToPoint: CGPointMake(279.61, 206.21)]; [demo8Path closePath]; [color2 setStroke]; demo8Path.lineWidth = 5; [demo8Path stroke]; [collectedppaths addObject:demo8Path]; //// demo 9 Drawing UIBezierPath* demo9Path = [UIBezierPath bezierPath]; [demo9Path moveToPoint: CGPointMake(280.08, 253.39)]; [demo9Path addLineToPoint: CGPointMake(398.17, 253.39)]; [demo9Path addLineToPoint: CGPointMake(394.9, 261.33)]; [demo9Path addLineToPoint: CGPointMake(388.83, 266.93)]; [demo9Path addCurveToPoint: CGPointMake(382.76, 270.67) controlPoint1: CGPointMake(388.83, 266.93) controlPoint2: CGPointMake(382.76, 270.2)]; [demo9Path addCurveToPoint: CGPointMake(377.16, 276.74) controlPoint1: CGPointMake(382.76, 271.13) controlPoint2: CGPointMake(377.16, 276.74)]; [demo9Path addLineToPoint: CGPointMake(374.83, 282.81)]; [demo9Path addLineToPoint: CGPointMake(377.16, 308.5)]; [demo9Path addLineToPoint: CGPointMake(280.08, 308.5)]; [demo9Path addLineToPoint: CGPointMake(280.08, 253.39)]; [demo9Path closePath]; [color2 setStroke]; demo9Path.lineWidth = 5; [demo9Path stroke]; [collectedppaths addObject:demo9Path]; //// demo 2 Drawing UIBezierPath* demo2Path = [UIBezierPath bezierPath]; [demo2Path moveToPoint: CGPointMake(86.84, 215.55)]; [demo2Path addLineToPoint: CGPointMake(183.93, 215.55)]; [demo2Path addLineToPoint: CGPointMake(183.93, 238.91)]; [demo2Path addLineToPoint: CGPointMake(177.86, 240.78)]; [demo2Path addLineToPoint: CGPointMake(169.46, 250.12)]; [demo2Path addLineToPoint: CGPointMake(155.46, 259.46)]; [demo2Path addLineToPoint: CGPointMake(138.19, 266)]; [demo2Path addLineToPoint: CGPointMake(122.78, 260.39)]; [demo2Path addLineToPoint: CGPointMake(102.71, 256.19)]; [demo2Path addLineToPoint: CGPointMake(86.84, 254.79)]; [demo2Path addLineToPoint: CGPointMake(86.84, 215.55)]; [demo2Path closePath]; [color2 setStroke]; demo2Path.lineWidth = 5; [demo2Path stroke]; [collectedppaths addObject:demo2Path]; } } 进行检查,您可以使用此方法进行验证 另外需要注意的是{{1}}当然不会改变警告级别,而是将所有警告视为错误。因此,如果编译器输出任何警告,则代码将无法编译。

答案 2 :(得分:-1)

对于Linux上的GCC:

> gcc -Q --help=target

将生成启用|禁用标志

的选项列表