Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Can't link a simple header file to an even more simple program |
| Date | 2016-11-28 11:00 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <o1h2mt$ed4$1@dont-email.me> (permalink) |
| References | <e11bcfb9-8cb4-48c2-89ea-b2586ab4a5f1@googlegroups.com> |
On 28/11/2016 10:41, Alla _ wrote:
> I have an issue with a very simple test code (downloaded from net): the compiler shows an error
> message, which usually would indicate (at least this what I managed to learn about his error message)
> that I have not added a correct library
>
> Undefined symbols for architecture x86_64:
> "_function1", referenced from:
> _main in 02_01-18ac0b.o
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
>
> Originally both the header and the .c file, which defines functions in the header file, didn't have an #include <stdio.h> line; the compiler displayed the above error message. Haven't found any mistake, I have added the stdio.h library, but the compiler still displays the same error message. I don't
> understand why the header is not being linked.
>
> (1) a program:
> #include <stdio.h>
> #include <stdlib.h>
>
> #include "myLibrary.h"
>
> #define MAX_LENGTH 21.8
> #define WORK_WEEK 5
>
> int main(void) {
> function1();
> return EXIT_SUCCESS;
> }
>
> (2) header file:
>
> #include <stdio.h> /** wasn't in the original file, added by me**/
>
> #ifndef MYLIBRARY_H_
> #define MYLIBRARY_H_
>
> void function1(void);
> void function2(void);
>
> #endif /* MYLIBRARY_H_ */
>
> (3)
> #include <stdio.h> /** wasn't in the original file, added by me**/
>
> void function1(void){
> puts("It works :)\n");
> }
>
> void function2(void){
> //This function does nothing as well
> }
If file (1) is called test.c, file (2) is called myLibrary.h, and (3) is
called myLibrary.c, then try this command line:
gcc test.c myLibrary.c
(Similar for clang.)
It should compile both files and generate an executable a.out or a.exe
(unless you specify -o test.exe or something but I won't go into that).
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 02:41 -0800
Re: Can't link a simple header file to an even more simple program BartC <bc@freeuk.com> - 2016-11-28 11:00 +0000
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 03:17 -0800
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 03:04 -0800
Re: Can't link a simple header file to an even more simple program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-28 13:39 +0000
Re: Can't link a simple header file to an even more simple program Ike Naar <ike@iceland.freeshell.org> - 2016-11-28 12:48 +0000
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 08:05 -0800
Re: Can't link a simple header file to an even more simple program Richard Heathfield <rjh@cpax.org.uk> - 2016-11-28 16:20 +0000
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 09:26 -0800
Re: Can't link a simple header file to an even more simple program Richard Heathfield <rjh@cpax.org.uk> - 2016-11-28 17:56 +0000
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 10:04 -0800
Re: Can't link a simple header file to an even more simple program Richard Heathfield <rjh@cpax.org.uk> - 2016-11-28 18:08 +0000
Re: Can't link a simple header file to an even more simple program "James R. Kuyper" <jameskuyper@verizon.net> - 2016-11-28 12:57 -0500
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 10:10 -0800
Re: Can't link a simple header file to an even more simple program Richard Heathfield <rjh@cpax.org.uk> - 2016-11-28 18:13 +0000
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 10:17 -0800
Re: Can't link a simple header file to an even more simple program "James R. Kuyper" <jameskuyper@verizon.net> - 2016-11-28 13:19 -0500
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 10:22 -0800
Re: Can't link a simple header file to an even more simple program David Thompson <dave.thompson2@verizon.net> - 2016-12-10 22:40 -0500
Re: Can't link a simple header file to an even more simple program Richard Heathfield <rjh@cpax.org.uk> - 2016-11-28 12:55 +0000
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 08:45 -0800
Re: Can't link a simple header file to an even more simple program Richard Heathfield <rjh@cpax.org.uk> - 2016-11-28 17:11 +0000
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 09:49 -0800
Re: Can't link a simple header file to an even more simple program Richard Heathfield <rjh@cpax.org.uk> - 2016-11-28 18:00 +0000
Re: Can't link a simple header file to an even more simple program Alla _ <modelling.data@gmail.com> - 2016-11-28 10:12 -0800
csiph-web