I have received a .h file to be used as part of a c++ program. I tried every method to link it, yet the undefined reference error is occurring. I'm using NetBeans in ubuntu.
The .h file contains the functions I'm trying to use. And yet the compiler is unable to find the function.
Here's a snippet of the fwlib32.h file since it is too big to insert the whole file:
FWLIBAPI short WINAPI cnc_allclibhndl3( const char *, unsigned short, long, unsigned short * );
FWLIBAPI short WINAPI cnc_upstart3( unsigned short, short, long, long ) ;
FWLIBAPI short WINAPI cnc_upstart3_f( unsigned short, short, char *, char * ) ;
FWLIBAPI short WINAPI cnc_statinfo( unsigned short, ODBST * ) ;
FWLIBAPI short WINAPI cnc_upload3( unsigned short, long *, char * ) ;
FWLIBAPI short WINAPI cnc_upend3( unsigned short ) ;
FWLIBAPI short WINAPI cnc_freelibhndl( unsigned short ) ;
Here's my program file:
#include "fwlib32.h"
#include<pthread.h>
#include<stdio.h>
#include<string.h>
#define BUFSIZE 1280
static unsigned short H;
struct conn_data
{
char ip[100];
short prt;
long tmo;
long pnum;
};
void conn(char *ipadd, short port, long tmout )
{
unsigned short h;
short ret;
ODBST buf;
ret = cnc_allclibhndl3( ipadd, port, tmout, &h ) ;
if ( !ret ) {
cnc_statinfo( h, &buf ) ;
H=h;
}
else
printf( "ERROR!(%d)\n", ret ) ;
}
short upld( long prgnum )
{
unsigned short h=H;
char buf[BUFSIZE+1] ;
short ret ;
long len;
ret = cnc_upstart3( h, 0, prgnum, prgnum ) ;
if ( ret ) return ( ret ) ;
do {
len = BUFSIZE ;
ret = cnc_upload3( h, &len, buf ) ;
if ( ret == EW_BUFFER ) {
continue ;
}
if ( ret == EW_OK ) {
buf[len] = '\0' ;
printf( "%s", buf ) ;
}
if ( buf[len-1] == '%' ) {
break ;
}
} while ( ret == EW_OK ) ;
ret = cnc_upend3( h ) ;
return ( ret ) ;
pthread_exit(&ret);
}
void* start_thread(void * dat)
{
struct conn_data *data;
data = (struct conn_data *)dat;
conn(data->ip, data->prt, data->tmo);
upld(data->pnum);
}
int main()
{
struct conn_data data;
char ip[100];
short prt;
long tmo,pnum;
pthread_t thread1;
int *ptr;
printf("\nEnter the IP address\n");
scanf("%s",ip);
strcpy(data.ip,ip);
printf("\nEnter the port number\n");
scanf("%hd",&prt);
data.prt=prt;
printf("\nEnter the timeout period in seconds\n");
scanf("%ld",&tmo);
data.tmo=tmo;
printf("Enter the program number\n");
scanf("%ld",&pnum);
data.pnum=pnum;
pthread_create(&thread1, NULL, start_thread, (void*)&data);
pthread_join(thread1, (void **) &ptr);
cnc_freelibhndl( H ) ;
return 0;
}
and these are the contents of the compiler window in NetBeans:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux-x86/amit1
make[1]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
CLEAN SUCCESSFUL (total time: 56ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/amit1
make[2]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/connect.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/connect.o.d -o build/Debug/GNU-Linux-x86/connect.o connect.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/amit1 build/Debug/GNU-Linux-x86/connect.o -lpthread
build/Debug/GNU-Linux-x86/connect.o: In function `conn(char*, short, long)':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:22: undefined reference to `cnc_allclibhndl3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:24: undefined reference to `cnc_statinfo'
build/Debug/GNU-Linux-x86/connect.o: In function `upld(long)':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:37: undefined reference to `cnc_upstart3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:41: undefined reference to `cnc_upload3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:53: undefined reference to `cnc_upend3'
build/Debug/GNU-Linux-x86/connect.o: In function `main':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:88: undefined reference to `cnc_freelibhndl'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/amit1] Error 1
make[2]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 220ms)
I looked at other similar questions and tried to add the library file in the project properties option, or to just create a -lfwlib32 option in the g++ statement. None of them caused any change. The program would still not build. Can anyone please help me?
-lfwlib32last on the linker command line shown.