Thread: Compiler Warnings

  1. #1
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187

    Compiler Warnings

    Hello guys.
    I used to know how to check the compiler warnings but I completely forgot how to.
    Can someone please enlighten me ?
    Thanks,

    Dean.

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    72
    click 2 times onto warnings messages below your code in build log, it goes the line which gives you warning.

  3. #3
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Didn't understand what you are trying to say rac1, sorry.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Your question in post one is not very clear. Do you need help to insure your compiler is generating warnings? Or do you need help figuring out some specific error message? You will either need to say how you are compiling your code, what compiler, operating system, IDE you are using. Or post the warning message and the code that generated the message, then ask specific questions on the code, messages provided.

    Jim

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    I don't know of a single compiler that would make it difficult to find warnings.

    But if you really had no idea where to start, and you had already looked for them yourself, already searched the help files for your compiler, and already searched google.... why would you post your question in a board specific to C programming?

  6. #6
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Quote Originally Posted by jimblumberg View Post
    Your question in post one is not very clear. Do you need help to insure your compiler is generating warnings? Or do you need help figuring out some specific error message? You will either need to say how you are compiling your code, what compiler, operating system, IDE you are using. Or post the warning message and the code that generated the message, then ask specific questions on the code, messages provided.

    Jim
    The type of warnings you showed on my other thread Jim.
    When the program compiles fine but still has some errors like unitialized variables and stuff like that.

    I'm on Ubuntu and I'm using the console.

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Quote Originally Posted by DeanWinchester View Post
    The type of warnings you showed on my other thread Jim.
    When the program compiles fine but still has some errors like unitialized variables and stuff like that.

    I'm on Ubuntu and I'm using the console.
    GCC does show warnings by default, it's just probable that your code is so ....ed up that it's all errors. But if there's errors, your program shouldn't compile; if it does, they're not. If you really want to see warnings, use "-Wall -pedantic" when compiling.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    If you are using the console to compile your code you need to add switches to generate warnings. I usually compile with the following compiler flags:
    -Winit-self -Wredundant-decls -Wcast-align -Wundef -Wfloat-equal -Winline -Wunreachable-code
    -Wmissing-declarations -Wmissing-include-dirs -Wswitch-enum -Wswitch-default
    -Wshadow -Wmain -pedantic-errors -pedantic -Wextra -Wall -ansi -g -std=c99
    The last line is what I usually consider the minimum warnings. The -g includes debug information to be able to run the the program with the debugger.

    Jim

  9. #9
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Found out how to.
    When compiling I usually do gcc -w -o "name of the function" "name of the function .c"
    In this case I just had to do gcc -w "name of the function" "name of the function .c"

    I got this though :

    Code:
    alocamemoria: In function `_start':
    (.text+0x0): multiple definition of `_start'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o:(.text+0x0): first defined here
    alocamemoria: In function `_fini':
    (.fini+0x0): multiple definition of `_fini'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crti.o:(.fini+0x0): first defined here
    alocamemoria:(.rodata+0x0): multiple definition of `_IO_stdin_used'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
    alocamemoria: In function `__data_start':
    (.data+0x0): multiple definition of `__data_start'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o:(.data+0x0): first defined here
    alocamemoria: In function `__data_start':
    (.data+0x8): multiple definition of `__dso_handle'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtbegin.o:(.data+0x0): first defined here
    alocamemoria: In function `_init':
    (.init+0x0): multiple definition of `_init'
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crti.o:(.init+0x0): first defined here
    /tmp/ccG51wV7.o: In function `ver':
    alocamemoria.c:(.text+0x0): multiple definition of `ver'
    alocamemoria:(.text+0xe4): first defined here
    /tmp/ccG51wV7.o: In function `main':
    alocamemoria.c:(.text+0x17c): multiple definition of `main'
    alocamemoria:(.text+0x260): first defined here
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
    alocamemoria:(.dtors+0x8): first defined here
    /usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
    /usr/bin/ld: error in alocamemoria(.eh_frame); no .eh_frame_hdr table will be created.
    collect2: ld returned 1 exit status
    Strange warnings

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Quote Originally Posted by memcpy View Post
    GCC does show warnings by default, it's just probable that your code is so ....ed up that it's all errors. But if there's errors, your program shouldn't compile; if it does, they're not. If you really want to see warnings, use "-Wall -pedantic" when compiling.
    GCC does not show warnings by default, you must use compiler flags to enable these warnings.

    Jim

  11. #11
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    How should I be using those compiler flags ?
    Never had to use 'em so I have no idea on how to.
    Sorry, Jim.

    Once again thanks, Dean.

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    From Option Summary - Using the GNU Compiler Collection (GCC)
    -w
    Inhibit all warning messages.
    Get rid of "-w"

    Tim S.

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    The -w turns off all warnings, this is definitely not what you want.

    Jim

  14. #14
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Quote Originally Posted by jimblumberg View Post
    GCC does not show warnings by default, you must use compiler flags to enable these warnings.

    Jim
    Derp, I was thinking of something else ._.

    @DeanWinchester - Those aren't warnings, they're linker errors. It's probably caused by abusing #include or having functions with the same name.

  15. #15
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Hum, thanks all!
    I took off -w and compiled it just using -o and it worked perfectly. Gave me just what I was looking for.
    Thanks ya'll D:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more about compiler warnings
    By MK27 in forum C Programming
    Replies: 5
    Last Post: 10-11-2008, 04:14 PM
  2. Compiler Warnings
    By Elysia in forum C++ Programming
    Replies: 10
    Last Post: 10-25-2007, 12:44 PM
  3. Compiler warnings
    By Zach L. in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-22-2003, 01:13 PM
  4. compiler warnings
    By Roaring_Tiger in forum C Programming
    Replies: 2
    Last Post: 04-10-2003, 12:06 PM
  5. compiler warnings
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-31-2002, 02:12 PM