lefantome
28-10-2010, 17:53
Allora devo utilizzare una libreria statica già creata all'interno del mio progetto.
nel makefile gli faccio compilare linkando la libreria mentre nel codice utilizzo gli identificatori di quella libreria.
Ora in due funzioni in cui li utilizzo mi viene dato questo errore:
msgserv.c:72: error: expected ‘)’ before ‘*’ token
msgserv.c:85: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
che non ha molto senso a meno che non riconosca i due identificatori.
Ecco il codice:
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/un.h>
#include <string.h>
#include "comsock.h"
/* #include "fileut.h" */
#define SOCKNAME "./tmp/msgsock"
#define EOF (-1)
/* System Call exception with return -1 SETTARE ERRNO!!!!*/
#define EC_RT(s,m) \
if((s) == -1) { perror(m); return -1; }
#define EC_NL(s,m) \
if((s) == NULL) { perror(m); return -1; }
/* =========================================================================================================*/
/** Compare
*/
int compare_int(void *a, void *b) {
int *_a, *_b;
_a = (int *) a;
_b = (int *) b;
return ((*_a) - (*_b));
}
int compare_string(void *a, void *b) {
char *_a, *_b;
_a = (char *) a;
_b = (char *) b;
return strcmp(_a,_b);
}
/* =========================================================================================================*/
/** Copy
*/
void * copy_int(void *a) {
int * _a;
if ( ( _a = malloc(sizeof(int) ) ) == NULL ) return NULL;
*_a = * (int * ) a;
return (void *) _a;
}
void * copy_string(void * a) {
char * _a;
if ( ( _a = strdup(( char * ) a ) ) == NULL ) return NULL;
return (void *) _a;
}
/* =========================================================================================================*/
/** Print
*/
void print_List(list_t * q){
elem_t* p;
for(p = q->head;p !=NULL;p=p->next){
printf("%p ", p->key);
}
}
/* =========================================================================================================*/
/** Crea una hasTable_t
*/
hashTable_t * createHashTable(int size){
hashTable_t* hs;
EC_NL(( hs = new_hashTable(size,compare_string,copy_string,copy_int,hash_string)),"Error createHash");
return hs;
}
/** ******************************** M A I N ***************************************************************************** */
int main(int argc, char *argv[]){
/* FILE DESCRIPTOR */
FILE *fd = NULL;
const int namelen = 256;
char* buf= (char*)malloc(sizeof(char)*namelen);
if (buf ==NULL){ perror("mallocerror!");}
int i;
for (i = 0; i<namelen; i++){ buf[i] = '-';}
/* TABELLA HASH */
hashTable_t* hs = createHash(256);
printf("File argomento : %s\n",argv[1]);
EC_NL((fd = fopen(argv[1],"r")), "Err Apertura file");
while (( buf = fgets(buf,namelen-1,fd)) !=NULL)
{
add_hashElement(hs,buf, buf );
printf("%s",buf);
}
fclose(fd);
return 0;
}
ed il makefile che sto utilizzando:
CC = gcc
CFLAGS = -Wall -pedantic
LIBDIR = ../lib
LIBNAME = libmsg.a
LIBS = -L$(LIBDIR)
objects = msgserv.o
msgserv: msgserv.o comsock.o
$(CC) $(CFLAGS) -o msgserv msgserv.o comsock.o
msgserv.o: msgserv.c
$(CC) $(CFLAGS) msgserv.c $(LIBS)
#serverut.o: serverut.c serverut.h
# $(CC) $(CFLAGS) serverut.c $(LIBNAME)
comsock.o: comsock.c comsock.h
$(CC) $(CFLAGS) comsock.c
Non riesco proprio a capire, ho controllato se avevo scritto i nomi della libreria per bene e sembrano uguali
nel makefile gli faccio compilare linkando la libreria mentre nel codice utilizzo gli identificatori di quella libreria.
Ora in due funzioni in cui li utilizzo mi viene dato questo errore:
msgserv.c:72: error: expected ‘)’ before ‘*’ token
msgserv.c:85: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
che non ha molto senso a meno che non riconosca i due identificatori.
Ecco il codice:
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/un.h>
#include <string.h>
#include "comsock.h"
/* #include "fileut.h" */
#define SOCKNAME "./tmp/msgsock"
#define EOF (-1)
/* System Call exception with return -1 SETTARE ERRNO!!!!*/
#define EC_RT(s,m) \
if((s) == -1) { perror(m); return -1; }
#define EC_NL(s,m) \
if((s) == NULL) { perror(m); return -1; }
/* =========================================================================================================*/
/** Compare
*/
int compare_int(void *a, void *b) {
int *_a, *_b;
_a = (int *) a;
_b = (int *) b;
return ((*_a) - (*_b));
}
int compare_string(void *a, void *b) {
char *_a, *_b;
_a = (char *) a;
_b = (char *) b;
return strcmp(_a,_b);
}
/* =========================================================================================================*/
/** Copy
*/
void * copy_int(void *a) {
int * _a;
if ( ( _a = malloc(sizeof(int) ) ) == NULL ) return NULL;
*_a = * (int * ) a;
return (void *) _a;
}
void * copy_string(void * a) {
char * _a;
if ( ( _a = strdup(( char * ) a ) ) == NULL ) return NULL;
return (void *) _a;
}
/* =========================================================================================================*/
*/
void print_List(list_t * q){
elem_t* p;
for(p = q->head;p !=NULL;p=p->next){
printf("%p ", p->key);
}
}
/* =========================================================================================================*/
/** Crea una hasTable_t
*/
hashTable_t * createHashTable(int size){
hashTable_t* hs;
EC_NL(( hs = new_hashTable(size,compare_string,copy_string,copy_int,hash_string)),"Error createHash");
return hs;
}
/** ******************************** M A I N ***************************************************************************** */
int main(int argc, char *argv[]){
/* FILE DESCRIPTOR */
FILE *fd = NULL;
const int namelen = 256;
char* buf= (char*)malloc(sizeof(char)*namelen);
if (buf ==NULL){ perror("mallocerror!");}
int i;
for (i = 0; i<namelen; i++){ buf[i] = '-';}
/* TABELLA HASH */
hashTable_t* hs = createHash(256);
printf("File argomento : %s\n",argv[1]);
EC_NL((fd = fopen(argv[1],"r")), "Err Apertura file");
while (( buf = fgets(buf,namelen-1,fd)) !=NULL)
{
add_hashElement(hs,buf, buf );
printf("%s",buf);
}
fclose(fd);
return 0;
}
ed il makefile che sto utilizzando:
CC = gcc
CFLAGS = -Wall -pedantic
LIBDIR = ../lib
LIBNAME = libmsg.a
LIBS = -L$(LIBDIR)
objects = msgserv.o
msgserv: msgserv.o comsock.o
$(CC) $(CFLAGS) -o msgserv msgserv.o comsock.o
msgserv.o: msgserv.c
$(CC) $(CFLAGS) msgserv.c $(LIBS)
#serverut.o: serverut.c serverut.h
# $(CC) $(CFLAGS) serverut.c $(LIBNAME)
comsock.o: comsock.c comsock.h
$(CC) $(CFLAGS) comsock.c
Non riesco proprio a capire, ho controllato se avevo scritto i nomi della libreria per bene e sembrano uguali