Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #102457 > unrolled thread

How to find the problem in the object file

Started byAlla _ <modelling.data@gmail.com>
First post2017-01-26 05:14 -0800
Last post2017-01-27 01:26 -0800
Articles 3 on this page of 83 — 15 participants

Back to article view | Back to comp.lang.c


Contents

  How to find the problem in the object file Alla _ <modelling.data@gmail.com> - 2017-01-26 05:14 -0800
    Re: How to find the problem in the object file BartC <bc@freeuk.com> - 2017-01-26 13:22 +0000
      Re: How to find the problem in the object file BartC <bc@freeuk.com> - 2017-01-26 13:37 +0000
    Re: How to find the problem in the object file Richard Heathfield <rjh@cpax.org.uk> - 2017-01-26 13:53 +0000
      Re: How to find the problem in the object file Alla _ <modelling.data@gmail.com> - 2017-01-26 06:20 -0800
        Re: How to find the problem in the object file BartC <bc@freeuk.com> - 2017-01-26 14:28 +0000
          Re: How to find the problem in the object file Alla _ <modelling.data@gmail.com> - 2017-01-26 06:48 -0800
          Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-01-26 08:29 -0800
            Re: How to find the problem in the object file BartC <bc@freeuk.com> - 2017-01-26 16:54 +0000
              Re: How to find the problem in the object file luser droog <luser.droog@gmail.com> - 2017-01-26 09:01 -0800
              Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-01-26 11:20 -0800
              Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-01-26 23:12 +0100
                Re: How to find the problem in the object file BartC <bc@freeuk.com> - 2017-01-27 01:32 +0000
                  Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-01-27 09:50 +0100
            Re: How to find the problem in the object file supercat@casperkitty.com - 2017-01-26 09:19 -0800
              Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-01-26 11:21 -0800
                Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-02 02:39 -0800
                  Re: How to find the problem in the object file fir <profesor.fir@gmail.com> - 2017-02-02 04:08 -0800
                    Re: How to find the problem in the object file fir <profesor.fir@gmail.com> - 2017-02-02 04:31 -0800
                    Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-04 10:48 -0800
                      Re: How to find the problem in the object file fir <profesor.fir@gmail.com> - 2017-02-04 11:07 -0800
                  Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-02 10:22 -0800
                    Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-04 11:00 -0800
                      Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-04 14:14 -0800
                        Re: How to find the problem in the object file Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-02-04 20:02 -0800
                        Re: How to find the problem in the object file supercat@casperkitty.com - 2017-02-05 13:39 -0800
                          Re: How to find the problem in the object file Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-02-05 13:44 -0800
                            Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-05 13:56 -0800
                              Re: How to find the problem in the object file Ian Collins <ian-news@hotmail.com> - 2017-02-06 13:07 +1300
                                Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-05 16:14 -0800
                                  Re: How to find the problem in the object file Ian Collins <ian-news@hotmail.com> - 2017-02-06 13:24 +1300
                                    Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-02-06 01:59 +0100
                                  Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-08 21:32 -0800
                          Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-05 13:54 -0800
                          Re: How to find the problem in the object file Ian Collins <ian-news@hotmail.com> - 2017-02-06 11:18 +1300
                        Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-08 21:32 -0800
                          Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-02-09 10:33 +0100
                            Re: How to find the problem in the object file supercat@casperkitty.com - 2017-02-09 09:10 -0800
                            Re: How to find the problem in the object file Ian Collins <ian-news@hotmail.com> - 2017-02-10 08:01 +1300
                          Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-09 09:01 -0800
                            Re: How to find the problem in the object file supercat@casperkitty.com - 2017-02-09 09:35 -0800
                              Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-09 09:57 -0800
                                Re: How to find the problem in the object file Jean-Marc Bourguet <jm@bourguet.org> - 2017-02-09 20:45 +0100
                                  Re: How to find the problem in the object file supercat@casperkitty.com - 2017-02-09 14:59 -0800
                                    Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-09 15:20 -0800
                                      Re: How to find the problem in the object file supercat@casperkitty.com - 2017-02-09 16:12 -0800
                                        Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-02-13 10:21 +0100
                                          Re: How to find the problem in the object file supercat@casperkitty.com - 2017-02-13 07:20 -0800
                                            Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-13 09:28 -0800
                                    Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-02-13 09:55 +0100
                                  Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-16 03:36 -0800
                            Re: How to find the problem in the object file Jean-Marc Bourguet <jm@bourguet.org> - 2017-02-09 20:56 +0100
                            Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-16 07:00 -0800
                              Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-02-16 20:03 +0100
                                Re: How to find the problem in the object file Ian Collins <ian-news@hotmail.com> - 2017-02-17 09:22 +1300
                                  Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-16 13:07 -0800
                                    Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-24 09:21 -0800
                                  Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-24 09:02 -0800
                                    Re: How to find the problem in the object file Ian Collins <ian-news@hotmail.com> - 2017-02-25 09:05 +1300
                                Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-24 09:26 -0800
                                  Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-02-25 19:38 +0100
                  Re: How to find the problem in the object file Ian Collins <ian-news@hotmail.com> - 2017-02-03 07:32 +1300
                    Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-04 11:24 -0800
                  Re: How to find the problem in the object file Robert Wessel <robertwessel2@yahoo.com> - 2017-02-02 16:56 -0600
                    Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-04 11:12 -0800
                      Re: How to find the problem in the object file Robert Wessel <robertwessel2@yahoo.com> - 2017-02-06 04:47 -0600
                        Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-08 21:59 -0800
                      Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-02-09 09:13 -0800
                        Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-15 19:28 -0800
                          Re: How to find the problem in the object file Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-02-24 17:48 -0800
                            Re: How to find the problem in the object file Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-25 17:36 -0800
        Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-01-26 15:51 +0100
          Re: How to find the problem in the object file Alla _ <modelling.data@gmail.com> - 2017-01-26 08:29 -0800
            Re: How to find the problem in the object file Richard Heathfield <rjh@cpax.org.uk> - 2017-01-26 16:34 +0000
              Re: How to find the problem in the object file Alla _ <modelling.data@gmail.com> - 2017-01-26 09:48 -0800
            Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-01-26 08:52 -0800
            Re: How to find the problem in the object file James Kuyper <jameskuyper@verizon.net> - 2017-01-26 13:53 -0500
              Re: How to find the problem in the object file supercat@casperkitty.com - 2017-01-26 11:00 -0800
            Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-01-26 23:49 +0100
              Re: How to find the problem in the object file Alla _ <modelling.data@gmail.com> - 2017-01-27 06:08 -0800
                Re: How to find the problem in the object file David Brown <david.brown@hesbynett.no> - 2017-01-27 16:20 +0100
          Re: How to find the problem in the object file Keith Thompson <kst-u@mib.org> - 2017-01-26 08:41 -0800
            Re: How to find the problem in the object file m.labanowicz@gmail.com - 2017-01-27 01:26 -0800

Page 5 of 5 — ← Prev page 1 2 3 4 [5]


#102530

FromDavid Brown <david.brown@hesbynett.no>
Date2017-01-27 16:20 +0100
Message-ID<o6fodf$int$1@dont-email.me>
In reply to#102525
On 27/01/17 15:08, Alla _ wrote:
> On Friday, January 27, 2017 at 1:50:09 AM UTC+3, David Brown wrote:
>> On 26/01/17 17:29, Alla _ wrote:
>>
>>> Not me - Apple has changed gcc for clang. But I still use gcc command,
>>> clang knows how to interpret that.
>>> -Wall -Werror -Wextra -pedantic -std=c99 ...
>>
>> (As has been pointed out, you /are/ using clang.  clang accepts pretty 
>> much the same set of flags as gcc.  The list I give below is for gcc, 
>> based on the flag sets I use - I hope they match clang here.)
>>
>> Those flags are fine as a starting point - but you can get more help 
>> from your compiler with more flags.  Because different people write code 
>> in different ways, and some warnings trigger on legal C that some people 
>> think is perfectly good, additional warnings are not included in the 
>> "-Wall -Wextra" sets.  It is up to the individual programmer (or project 
>> manager, etc.) to decide the details here.  But here are a few 
>> suggestions for additional or alternative flags that you might find 
>> helpful - I certainly do:
>>
>>
>> Consider using -std=c11.  For the kind of code you are writing, c11 does 
>> not add much - but it is the current standard.  The key benefit that I 
>> see is the _Static_assert() feature.  Personally, I have no use for 
>> "-pedantic" and prefer "-std=gnu11" because I feel the gcc extensions 
>> let me write better and safer code - but for learning, it is best to 
>> stick as close as possible to the standards with -pedantic.
>>
>>
>> Additional warning flags:
>>
>> -Wlogical-op (Warns about odd-looking uses of logical operators)
>>
>> -Wredundant-decls (Warns about duplicate declarations)
>>
>> -Wmissing-prototypes -Wmissing-declarations (With these in place, your 
>> functions need to be either "static", or have a declarations before the 
>> definition - typically in a header)
>>
>> -Wundef (Warn if an undefined identifier is used in an #if directive)
>>
>> -Wnull-dereference (Warn if the compiler can spot a null deference when 
>> optimisation is on)
>>
>> -Wduplicated-branches -Wduplicated-cond (Warn about branches and 
>> conditionals that have the duplicates)
>>
>> -Wcast-qual -Wcast-align (Warn about some possible bad casts)
>>
>> I also recommend using -O1 to enable optimisation - it also enables 
>> better code analysis, and therefore better static error checking.
> 
> What a wonderful list! Thank you so much. 
> 

I have had a quick glance at clang's documentation, and I am not sure it
has these same warning flags.  Try it an see.

If possible, you might also consider getting gcc 6 (real gcc, not clang
with a gcc link) - it has a number of new warnings that add extra
warnings, such as "-Wmisleading-indentation" (part of -Wall) and
suggestions about some misspellings and other hints about the causes of
errors.

You can also use the "sanitize" options (in gcc and clang) to spot some
kinds of errors at run-time.

[toc] | [prev] | [next] | [standalone]


#102472

FromKeith Thompson <kst-u@mib.org>
Date2017-01-26 08:41 -0800
Message-ID<lnbmutepu6.fsf@kst-u.example.com>
In reply to#102466
David Brown <david.brown@hesbynett.no> writes:
> On 26/01/17 15:20, Alla _ wrote:
[...]
>> Yes, the linker, sorry.
>> And ... it can't get more embarrassing than this! just can't. 
>> A few hours, hours, of writing, re-writing the code, copying, etc.
>> Yes, a tiny misspelling - how could I miss it?! 
>> And, what's even more embarrassing - for the last almost 10 
>> attempts I was compiling one of the previous wrong files. Gee.
>> And I had to bother people here with this stupid post - not that
>> any other my posts are better; but some are much more 
>> meaningful. 
>> 
>
> It looks like you are using clang as your compiler.  What compiler flags
> are you using?  And are you using more than one source file but not
> using a header to declare the external function(s)?  If this kind of
> error is getting as far as the linker, you either have a poor choice of
> compiler flags, or you are declaring external functions in your C files
> rather than in a header file.  Either way, it should not be hard to
> avoid such mistakes (once you know the settings to use, of course).

There's no reason to think there's anything wrong with the source files,
the compiler, the linker, or any of the flags.

Here's one way a similar error can happen:

    $ cat lib.h
    #ifndef H_LIB
    #define H_LIB

    void library_function(void);

    #endif
    $ cat lib.c
    #include <stdio.h>
    #include "lib.h"

    void library_function(void) {
        puts("Hello");
    }
    $ cat main.c
    #include "lib.h"
    int main(void) {
        library_function();
    }
    $ clang -c lib.c
    $ clang -c main.c
    $ clang main.o -o main
    main.o: In function `main':                                                                                                                main.c:(.text+0x5): undefined reference to `library_function'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

A carefully constructed Makefile, among other possible solutions, can
avoid this -- *if* the Makefile is kept in sync with the sources.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#102517

Fromm.labanowicz@gmail.com
Date2017-01-27 01:26 -0800
Message-ID<b7be96e2-68af-496f-b478-d1e23b3352f3@googlegroups.com>
In reply to#102472
>     $ clang -c lib.c
>     $ clang -c main.c
>     $ clang main.o -o main
>     main.o: In function `main':                                                                                                                main.c:(.text+0x5): undefined reference to `library_function'
>     clang: error: linker command failed with exit code 1 (use -v to see invocation)
> 
> A carefully constructed Makefile, among other possible solutions, can
> avoid this -- *if* the Makefile is kept in sync with the sources.
> 

Another case when all files passed to linker makes that linking fails:
Order is meaningful:

$ ar q lib.a lib.o 
ar: creating lib.a
$ clang -o main main.o lib.a # OK
$ clang -o main lib.a main.o # ERROR
main.o: In function `main':
main.c:(.text+0x5): undefined reference to `library_function'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Cheers

-- 
Maciej Labanowicz

[toc] | [prev] | [standalone]


Page 5 of 5 — ← Prev page 1 2 3 4 [5]

Back to top | Article view | comp.lang.c


csiph-web