Nie jesteś zalogowany.
Jeśli nie posiadasz konta, zarejestruj je już teraz! Pozwoli Ci ono w pełni korzystać z naszego serwisu. Spamerom dziękujemy!

Ogłoszenie

Prosimy o pomoc dla małej Julki — przekaż 1% podatku na Fundacji Dzieciom zdazyć z Pomocą.
Więcej informacji na dug.net.pl/pomagamy/.

#1  2005-11-30 22:03:09

  willy - Użytkownik

willy
Użytkownik
Zarejestrowany: 2005-03-03

ndbm.h bazy danych pod linuxem

Mam taki problem. Chce cos napisac z baz danych dbm a konkretnie ndbm
Program ponizej to caly kod z ksiazki LinuxProgramowanie N. Matthew R. Stones .
Prubuje go skompilowac:
na wstepien dostaje ze nie mam takiej biblioteki jaka jest ndbm.h
szukam innej i znajduje gdbm-ndbm i taka wstawiam
//#include <ndbm.h>
#include <gdbm-ndbm.h>
i dostaje takie cos

Kod:


$ gcc 3.c -o 3
/tmp/ccT62How.o: In function `main':
3.c:(.text+0x32): undefined reference to `dbm_open'
3.c:(.text+0x205): undefined reference to `dbm_store'
3.c:(.text+0x2af): undefined reference to `dbm_fetch'
3.c:(.text+0x348): undefined reference to `dbm_close'
collect2: ld returned 1 exit status

nie mam pojecia jak to skompilowc aby dzialalo

posiadam takie tylko biblioteki i jak sie orientuj innych juz nie ma

Kod:

$ ls /usr/include/*dbm*
/usr/include/dbm.h  /usr/include/gdbm.h  /usr/include/gdbm-ndbm.h

oto kod programu

Kod:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
//#include <ndbm.h>
#include <gdbm-ndbm.h>
#include <string.h>

#define TEST_DB_FILE "/tmp/dbm1_test"
#define ITEMS_USED 3

/* A struct to use to test dbm */
struct test_data {
    char misc_chars[15];
    int  any_integer;
    char more_chars[21];
};

int main() {

    struct test_data items_to_store[ITEMS_USED];
    struct test_data item_retrieved;

    char key_to_use[20];
    int i, result;

    datum key_datum;
    datum data_datum;
    
    DBM *dbm_ptr;

    dbm_ptr = dbm_open(TEST_DB_FILE, O_RDWR | O_CREAT, 0666);
    if (!dbm_ptr) {
        fprintf(stderr, "Failed to open databasen");
        exit(EXIT_FAILURE);
    }

        /* put some data in the structures */
    memset(items_to_store, '', sizeof(items_to_store));
    strcpy(items_to_store[0].misc_chars, "First!");
    items_to_store[0].any_integer = 47;
    strcpy(items_to_store[0].more_chars, "foo");
    strcpy(items_to_store[1].misc_chars, "bar");
    items_to_store[1].any_integer = 13;
    strcpy(items_to_store[1].more_chars, "unlucky?");
    strcpy(items_to_store[2].misc_chars, "Third");
    items_to_store[2].any_integer = 3;
    strcpy(items_to_store[2].more_chars, "baz");

    for (i = 0; i < ITEMS_USED; i++) {
            /* build a key to use */
        sprintf(key_to_use, "%c%c%d",
            items_to_store[i].misc_chars[0],
            items_to_store[i].more_chars[0],
            items_to_store[i].any_integer);

            /* build the key datum strcture */
        key_datum.dptr = (void *)key_to_use;
        key_datum.dsize = strlen(key_to_use);
        data_datum.dptr = (void *)&items_to_store[i];
        data_datum.dsize = sizeof(struct test_data);

        result = dbm_store(dbm_ptr, key_datum, data_datum, DBM_REPLACE);
        if (result != 0) {
            fprintf(stderr, "dbm_store failed on key %sn", key_to_use);
            exit(2);
        }
    } /* for */

        /* now try and retrieve some data */
    sprintf(key_to_use, "bu%d", 13); /* this is the key for the second item */
    key_datum.dptr = key_to_use;
    key_datum.dsize = strlen(key_to_use);

    data_datum = dbm_fetch(dbm_ptr, key_datum);
    if (data_datum.dptr) {
        printf("Data retrievedn");
        memcpy(&item_retrieved, data_datum.dptr, data_datum.dsize);
        printf("Retrieved item - %s %d %sn",
               item_retrieved.misc_chars,
               item_retrieved.any_integer,
               item_retrieved.more_chars);
    }
    else {
        printf("No data found for key %sn", key_to_use);
    }

    dbm_close(dbm_ptr);

    exit(EXIT_SUCCESS);
}

Jak to skompilowac , ktos ma jakies pomysly
cos slyszalem ze przed kazda funkcjia bilioteki typu dbm_open itp
stawia sie g aby bylo gdbm_open itd.
Prosze o pomoc

POZDRAWIA

Offline

 

#2  2005-11-30 23:03:17

  Bodzio - Ojciec Założyciel

Bodzio
Ojciec Założyciel
Skąd: Gorlice
Zarejestrowany: 2004-04-17
Serwis

Re: ndbm.h bazy danych pod linuxem

Mam taki problem. Chce cos napisac z baz danych dbm a konkretnie ndbm
Program ponizej to caly kod z ksiazki LinuxProgramowanie N. Matthew R. Stones .
Prubuje go skompilowac:
na wstepien dostaje ze nie mam takiej biblioteki jaka jest [color=red]ndbm.h[/color]
[/quote]
apt-get install oskit


Debian jest lepszy niż wszystkie klony
Linux register users: #359018
[img]http://www.freebsd.org/gifs/powerlogo.gif[/img]
[url=https://goo.gl/photos/5XGKFkvaMimLwM2s9]Beskid Niski[/url]

Offline

 

#3  2005-12-01 16:32:12

  willy - Użytkownik

willy
Użytkownik
Zarejestrowany: 2005-03-03

Re: ndbm.h bazy danych pod linuxem

Goglowalem chyba z 2 dni i sie udalo

ma byc

Kod:

#include<gdbm-ndbm.h>

a oto odpowiedz


"   If you want to compile an old C program that used UNIX `dbm' or
`ndbm' and want to use `gdbm' files, execute the following `cc' command:

     cc ... -L/usr/local/lib -lgdbm -lgdbm_compat"

That should give you the clues i.e. tweak the Makefile or FLAGS or whatever
to get the link line to say:

  "-lgdbm -lgdbm_compat"

[/quote]

Dzieki Bodzio za zainteresowanie
a co do oskitu to jakos nie moglem polinkowac tych wszystkich biblotek zawsze byly jakies błedy

POZDRAWIAM

Offline

 

#4  2005-12-01 16:55:13

  Bodzio - Ojciec Założyciel

Bodzio
Ojciec Założyciel
Skąd: Gorlice
Zarejestrowany: 2004-04-17
Serwis

Re: ndbm.h bazy danych pod linuxem

Goglowalem chyba z 2 dni i sie udalo

ma byc

Kod:

#include<[color=red]gdbm-ndbm.h[/color]>

[/quote]

apt-get install libgdbm-dev

Tak dla ułatwienia, jeżeli szukasz jakiejś biblioteki to wchodzisz na tę  http://www.debian.org/distrib/packages  stronę. Masz tam dwa okna. W górnym wpisujesz szukanego pakietu, natomiast jak chcesz bibliotekę to wpisujesz jej nazwę w dolne okno :)


Debian jest lepszy niż wszystkie klony
Linux register users: #359018
[img]http://www.freebsd.org/gifs/powerlogo.gif[/img]
[url=https://goo.gl/photos/5XGKFkvaMimLwM2s9]Beskid Niski[/url]

Offline

 

#5  2005-12-01 17:45:35

  willy - Użytkownik

willy
Użytkownik
Zarejestrowany: 2005-03-03

Re: ndbm.h bazy danych pod linuxem

Jeszcze raz dzieki za zainterezowanie - problem rozwiazany wiec ZAMYKAMY TEMAT


Ad Bodzio:
Jezeli uzylem biblioteki <gdbm-ndbm.h> i nie dostalem errora ze takiej biblioteki nie ma to chyba bylo oczywiste ze libgdbm-dev jest juz zainstalowane.

POZDRAWIAM

Offline

 

Stopka forum

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson
Możesz wyłączyć AdBlock — tu nie ma reklam ;-)

[ Generated in 0.008 seconds, 10 queries executed ]

Informacje debugowania

Time (s) Query
0.00012 SET CHARSET latin2
0.00005 SET NAMES latin2
0.00126 SELECT u.*, g.*, o.logged FROM punbb_users AS u INNER JOIN punbb_groups AS g ON u.group_id=g.g_id LEFT JOIN punbb_online AS o ON o.ident='3.142.12.240' WHERE u.id=1
0.00070 REPLACE INTO punbb_online (user_id, ident, logged) VALUES(1, '3.142.12.240', 1714957199)
0.00054 SELECT * FROM punbb_online WHERE logged<1714956899
0.00061 DELETE FROM punbb_online WHERE ident='47.128.39.193'
0.00070 SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, 0 FROM punbb_topics AS t INNER JOIN punbb_forums AS f ON f.id=t.forum_id LEFT JOIN punbb_forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=2382 AND t.moved_to IS NULL
0.00006 SELECT search_for, replace_with FROM punbb_censoring
0.00141 SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM punbb_posts AS p INNER JOIN punbb_users AS u ON u.id=p.poster_id INNER JOIN punbb_groups AS g ON g.g_id=u.group_id LEFT JOIN punbb_online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id=2382 ORDER BY p.id LIMIT 0,25
0.00084 UPDATE punbb_topics SET num_views=num_views+1 WHERE id=2382
Total query time: 0.00629 s