-
June 6th, 2011, 06:38 AM
#1
undefined reference to `lzo1z_decompress'
Hello,
I am trying to decompress a data buffer through LZO decompression algorithm.
But it throws an error while building the code.
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory `/root/NetBeansProjects/Projects/CFNORawServer'
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cfnorawserver
gmake[2]: Entering directory `/root/NetBeansProjects/Projects/CFNORawServer'
gmake[2]: Warning: File `Include/lzoconf.h' has modification time 3.7e+04 s in the future
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
gcc -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.c
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/cfnorawserver build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function `main':
/root/NetBeansProjects/Projects/CFNORawServer/main.c:127: undefined reference to `lzo1z_decompress'
collect2: ld returned 1 exit status
gmake[2]: *** [dist/Debug/GNU-Linux-x86/cfnorawserver] Error 1
gmake[2]: Leaving directory `/root/NetBeansProjects/Projects/CFNORawServer'
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory `/root/NetBeansProjects/Projects/CFNORawServer'
gmake: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 331ms)
MY CODE IS :
memset(recv_str,0,sizeof(recv_str));
from_len = sizeof(from_addr);
memset(&from_addr,0,from_len);
if((recv_len = recvfrom(sock, recv_str, 1024, 0, (struct sockaddr*)&mc_addr, &from_len)) < 0)
{
perror("recvfrom() failed");
exit(1);
}
short compLen=0;
short NOP=0;
memcpy(&compLen,recv_str+4,2);
compLen = ntohs(compLen);
if(compLen > 0)
{
memcpy(&NOP,recv_str+2,2);
NOP=ntohs(NOP);
int i=0;
for(i=0;i<NOP;i++)
{
unsigned char src[compLen];
memcpy(&src,recv_str+6,compLen);
short src_len = compLen;
unsigned int dst_len = 1024;
unsigned char dst[1024];
int rCode;
unsigned int eCode=0;
rCode = lzo1z_decompress((lzo_bytep) src ,(lzo_uint)src_len ,(lzo_bytep) dst ,lzo_uintp)&dst_len ,0);
}
}
-
June 6th, 2011, 10:11 AM
#2
Re: undefined reference to `lzo1z_decompress'
gcc -o dist/Debug/GNU-Linux-x86/cfnorawserver build/Debug/GNU-Linux-x86/main.o
Where is lzo1z_decompress function defined? You need to add the library with this function to the linking command line, something like:
gcc -o dist/Debug/GNU-Linux-x86/cfnorawserver build/Debug/GNU-Linux-x86/main.o -llzo
(I don't know exact library name, just guess)
-
June 6th, 2011, 10:45 PM
#3
Re: undefined reference to `lzo1z_decompress'
Hello,
lzo1z_decompress is defined in the header file lzo1z.h
My complete code is:
Code:
/*
* File: main.c
* Author: root
*
* Created on May 17, 2011, 1:51 PM
*/
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "Include/lzo1z.h"
#define MAX_LEN 1024;
int main(int argc, char **argv)
{
int sock;
int flag_on = 1;
struct sockaddr_in mc_addr;
unsigned char recv_str[1024];
int recv_len;
struct ip_mreq mc_req;
char* mc_addr_str;
unsigned short mc_port;
struct sockaddr_in from_addr;
unsigned int from_len;
mc_addr_str = "233.1.1.11";
mc_port = 34330;
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
{
perror("socket() failed");
exit(1);
}
if ((setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flag_on, sizeof(flag_on))) < 0)
{
perror("setsockopt() failed");
exit(1);
}
memset(&mc_addr,0,sizeof(mc_addr));
mc_addr.sin_family = AF_INET;
mc_addr.sin_addr.s_addr = htonl(INADDR_ANY);
mc_addr.sin_port = htons(mc_port);
if((bind(sock,(struct sockaddr *) &mc_addr,sizeof(mc_addr))) < 0)
{
perror("bind() failed");
exit(1);
}
mc_req.imr_multiaddr.s_addr = inet_addr(mc_addr_str);
mc_req.imr_interface.s_addr = htonl(INADDR_ANY);
if((setsockopt(sock,IPPROTO_IP,IP_ADD_MEMBERSHIP,(void*) &mc_req,sizeof(mc_req))) < 0)
{
perror("setsockopt() failed");
exit(1);
}
for(;;)
{
memset(recv_str,0,sizeof(recv_str));
from_len = sizeof(from_addr);
memset(&from_addr,0,from_len);
if((recv_len = recvfrom(sock, recv_str,1024,0,(struct sockaddr*)&mc_addr, &from_len))<0)
{
perror("recvfrom() failed");
exit(1);
}
short compLen=0;
short NOP=0;
memcpy(&compLen,recv_str+4,2);
compLen = ntohs(compLen);
if(compLen > 0)
{
memcpy(&NOP,recv_str+2,2);
NOP=ntohs(NOP);
int i=0;
for(i=0;i<NOP;i++)
{
unsigned char src[compLen];
memcpy(&src,recv_str+6,compLen);
short src_len = compLen;
unsigned int dst_len = 1024;
unsigned char dst[1024];
int rCode;
unsigned int eCode=0;
rCode = lzo1z_decompress((lzo_bytep) src,(lzo_uint)src_len,(lzo_bytep) dst,(lzo_uintp)&dst_len,0);
}
}
}
if((setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP,(void*)&mc_req, sizeof(mc_req))) < 0)
{
perror("setsocketopt() failed");
exit(1);
}
close(sock);
return 0;
}
Hardik.
-
June 6th, 2011, 10:51 PM
#4
Re: undefined reference to `lzo1z_decompress'
My header file lzo1z.h contains following code:
Code:
/* lzo1z.h -- public interface of the LZO1Z compression algorithm
This file is part of the LZO real-time data compression library.
*/
#ifndef __LZO1Z_H_INCLUDED
#define __LZO1Z_H_INCLUDED
#ifndef __LZOCONF_H_INCLUDED
#include "lzoconf.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************
//
************************************************************************/
/* Memory required for the wrkmem parameter.
* When the required size is 0, you can also pass a NULL pointer.
*/
#define LZO1Z_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t))
#define LZO1Z_MEM_DECOMPRESS (0)
#define LZO1Z_MEM_OPTIMIZE (0)
/* decompression */
LZO_EXTERN(int)
lzo1z_decompress ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
/* safe decompression with overrun testing */
LZO_EXTERN(int)
lzo1z_decompress_safe ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
/***********************************************************************
//
************************************************************************/
#if 0
/* not yet implemented */
LZO_EXTERN(int)
lzo1z_1_compress ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
#endif
/***********************************************************************
// better compression ratio at the cost of more memory and time
************************************************************************/
#define LZO1Z_999_MEM_COMPRESS ((lzo_uint32) (14 * 16384L * sizeof(short)))
LZO_EXTERN(int)
lzo1z_999_compress ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
/***********************************************************************
//
************************************************************************/
LZO_EXTERN(int)
lzo1z_999_compress_dict ( const lzo_bytep in , lzo_uint in_len,
lzo_bytep out, lzo_uintp out_len,
lzo_voidp wrkmem,
const lzo_bytep dict, lzo_uint dict_len );
LZO_EXTERN(int)
lzo1z_999_compress_level ( const lzo_bytep in , lzo_uint in_len,
lzo_bytep out, lzo_uintp out_len,
lzo_voidp wrkmem,
const lzo_bytep dict, lzo_uint dict_len,
lzo_callback_p cb,
int compression_level );
LZO_EXTERN(int)
lzo1z_decompress_dict_safe ( const lzo_bytep in, lzo_uint in_len,
lzo_bytep out, lzo_uintp out_len,
lzo_voidp wrkmem /* NOT USED */,
const lzo_bytep dict, lzo_uint dict_len );
/***********************************************************************
// optimize a compressed data block
************************************************************************/
#if 0
/* not yet implemented */
LZO_EXTERN(int)
lzo1z_optimize ( lzo_bytep in , lzo_uint in_len,
lzo_bytep out, lzo_uintp out_len,
lzo_voidp wrkmem /* NOT USED */ );
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* already included */
/* vim:set ts=4 et: */
Hardik.
-
June 7th, 2011, 12:33 AM
#5
Re: undefined reference to `lzo1z_decompress'
This is only function forward declaration, without implementation. You need function implementation. If function is implemented in some c/cpp file, add this file to the project. If function is implemented in some library, add this library to the linking command line.
-
June 22nd, 2011, 01:05 AM
#6
Re: undefined reference to `lzo1z_decompress'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|