You are not logged in.

  • Login

1

Monday, December 6th 2010, 11:39pm

undefined reference bei libyaml

Hallo Leute.
Ich bin jetzt schon seit ein paar Wochen C am lernen. Nun wollte ich gerne YAML in C benutzen. Dazu hab ich mir eine passende C-Bibliothek namens libyaml gesucht.
Dort gibt es im SVN-Repository auch Beispieldateien. Libyaml selbst habe ich über meine Paketverwaltung (gentoo mit emerge) in der Version 0.1.2 installiert.
Mit den Beispieldateien, welche übrigens mit unzähligen Fehlern abbrach, habe ich mir versucht eine eigene Datei zu programmieren.
Jedoch kommt immer der Fehler undefined reference to `yaml_emitter_initialize'. Die yaml.h, welche in /usr/include/ liegt, wird auch korrekt eingebunden.
Hier mal mein bisheriger Code:

C/C++ Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * yaml.c
 *
 *  Created on: 06.12.2010
 *      Author: markus
 *
 *  Datei zum Testen und ausprobieren der libyaml und (l)stat
 */
 
#include <yaml.h>
 
#include <stdio.h>
#include <stdlib.h>
 
 
int main(int argc, char **argv) {
	yaml_parser_t parser;
	yaml_emitter_t emitter;
	yaml_event_t input_event;
	yaml_event_t output_event;
 
	memset(&parser, 0, sizeof(parser));
	memset(&emitter, 0, sizeof(emitter));
	memset(&input_event, 0, sizeof(input_event));
	memset(&output_event, 0, sizeof(output_event));
 
	//FILE *file = fopen("yaml.db", "wb");
 
	yaml_emitter_initialize(&emitter);
	//yaml_emitter_set_output_file(&parser, file);
 
	printf("Hallo\n");
 
	return EXIT_SUCCESS;
}

Ich habe dann nach etwas googlen herausgefunden, dass man wohl noch eine bereits kompilierte Datei einbinden muss.
Dazu habe ich in /usr/lib64/ mit ls -l | grep libyaml folgendes gefunden:

Source code

1
2
3
4
5
lrwxrwxrwx  1 root root       18  6. Dez 19:59 libyaml-0.so.1 -> libyaml-0.so.1.1.0
-rwxr-xr-x  1 root root   124944  6. Dez 19:59 libyaml-0.so.1.1.0
-rw-r--r--  1 root root   170032  6. Dez 19:59 libyaml.a
-rw-r--r--  1 root root      943  6. Dez 19:59 libyaml.la
lrwxrwxrwx  1 root root       18  6. Dez 19:59 libyaml.so -> libyaml-0.so.1.1.0

Anschließend habe ich es mit gcc -L/usr/lib64 -I yaml -o yaml yaml.c versucht die Bibliothek einzubinden. Leider ohne Erfolg, der Fehler blieb der gleiche.
Dann habe ich es manuell mit dem Linker probiert:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
gcc -c yaml.c
ld yaml.o /usr/lib64/libyaml.a
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000f0
yaml.o: In function `main':
yaml.c:(.text+0x2d): undefined reference to `memset'
yaml.c:(.text+0x46): undefined reference to `memset'
yaml.c:(.text+0x5f): undefined reference to `memset'
yaml.c:(.text+0x78): undefined reference to `memset'
yaml.c:(.text+0x91): undefined reference to `puts'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_get_root_node':
(.text+0x16e): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_get_node':
(.text+0x1c4): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_emitter_set_break':
(.text+0x1f1): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_emitter_set_unicode':
(.text+0x225): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_emitter_set_width':
(.text+0x25c): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o):(.text+0x297): more undefined references to `__assert_fail' follow
/usr/lib64/libyaml.a(api.o): In function `yaml_string_write_handler':
(.text+0x786): undefined reference to `memcpy'
/usr/lib64/libyaml.a(api.o): In function `yaml_string_write_handler':
(.text+0x7a8): undefined reference to `memcpy'
/usr/lib64/libyaml.a(api.o): In function `yaml_string_read_handler':
(.text+0x7e8): undefined reference to `memcpy'
/usr/lib64/libyaml.a(api.o): In function `yaml_file_write_handler':
(.text+0x823): undefined reference to `fwrite'
/usr/lib64/libyaml.a(api.o): In function `yaml_file_read_handler':
(.text+0x84b): undefined reference to `fread'
/usr/lib64/libyaml.a(api.o): In function `yaml_file_read_handler':
(.text+0x858): undefined reference to `ferror'
/usr/lib64/libyaml.a(api.o): In function `yaml_alias_event_initialize':
(.text+0x8fe): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_alias_event_initialize':
(.text+0x917): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_delete':
(.text+0x9e7): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_delete':
(.text+0xaa4): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_event_delete':
(.text+0xb80): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o):(.text+0xc74): more undefined references to `__assert_fail' follow
/usr/lib64/libyaml.a(api.o): In function `yaml_queue_extend':
(.text+0x11f4): undefined reference to `memmove'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_append_mapping_pair':
(.text+0x13ae): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_append_mapping_pair':
(.text+0x13c7): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_append_mapping_pair':
(.text+0x13e0): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_append_mapping_pair':
(.text+0x13f9): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_append_mapping_pair':
(.text+0x1412): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o):(.text+0x14d3): more undefined references to `__assert_fail' follow
/usr/lib64/libyaml.a(api.o): In function `yaml_string_extend':
(.text+0x155c): undefined reference to `memset'
/usr/lib64/libyaml.a(api.o): In function `yaml_string_join':
(.text+0x15f7): undefined reference to `memcpy'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_initialize':
(.text+0x18db): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_initialize':
(.text+0x198f): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_initialize':
(.text+0x19a8): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_initialize':
(.text+0x19c1): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_scalar_event_initialize':
(.text+0x1add): undefined reference to `memcpy'
/usr/lib64/libyaml.a(api.o): In function `yaml_scalar_event_initialize':
(.text+0x1b5f): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_scalar_event_initialize':
(.text+0x1b78): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_start_event_initialize':
(.text+0x1e4b): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_start_event_initialize':
(.text+0x1e64): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_start_event_initialize':
(.text+0x1e7d): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o):(.text+0x1e96): more undefined references to `__assert_fail' follow
/usr/lib64/libyaml.a(api.o): In function `yaml_document_add_scalar':
(.text+0x286d): undefined reference to `memcpy'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_add_scalar':
(.text+0x29ad): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_document_add_scalar':
(.text+0x29c6): undefined reference to `__assert_fail'
/usr/lib64/libyaml.a(api.o): In function `yaml_strdup':
(.text+0x871): undefined reference to `__strdup'
/usr/lib64/libyaml.a(api.o): In function `yaml_free':
(.text+0x921): undefined reference to `free'
/usr/lib64/libyaml.a(api.o): In function `yaml_realloc':
(.text+0x119c): undefined reference to `realloc'
/usr/lib64/libyaml.a(api.o): In function `yaml_realloc':
(.text+0x11b0): undefined reference to `malloc'
/usr/lib64/libyaml.a(api.o): In function `yaml_malloc':
(.text+0x1620): undefined reference to `malloc'

###########################################

ld yaml.o /usr/lib64/libyaml.so
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400430

Mittlerweile bin ich mit meinem Latein am Ende. Vielleicht wisst ihr ja, was ich vergessen oder falsch gemacht habe.

This post has been edited 1 times, last edit by "Deadman44" (Dec 7th 2010, 7:40am)


2

Tuesday, December 7th 2010, 5:14pm

ich glaube es muss -lyaml heißen, ohne leerzeichen

3

Tuesday, December 7th 2010, 7:23pm

Danke für den Tip pocky. Ich habe jetzt bemerkt, dass ich statt l (kleines L) ein I (großes i) geschrieben hatte. Jetzt kompiliert er fehlerfrei durch :-).

Similar threads

Social bookmarks