Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How to find the problem in the object file Date: Thu, 26 Jan 2017 08:41:21 -0800 Organization: None to speak of Lines: 60 Message-ID: References: <23ab01a2-5220-42cb-80b2-20a2b4a35d5c@googlegroups.com> <2beebc58-3f8f-46c6-bd10-e2ec3cf87906@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="c4bbf5deaa7fb5ee9d54a2c91785016f"; logging-data="29903"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yqPsg4hCNvVN0cuBG75Rh" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:Dmz6T5v/gxlL9YETAs/+JinKxLw= sha1:EtMFeR/QOvvHypOoABE1aS7Ra4E= Xref: csiph.com comp.lang.c:102472 David Brown 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 #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 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"