未定义的函数错误引用

时间:2015-10-13 05:51:42

标签: c++ linux ubuntu netbeans

我收到了.h file作为c ++程序的一部分。我尝试了每种方法来链接它,但是未定义的引用错误正在发生。我在ubuntu中使用NetBeans。

.h file包含我尝试使用的功能。然而编译器无法找到该函数。

这里是fwlib32.h文件的一小段,因为它太大而无法插入整个文件:

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 ) ;

这是我的程序文件:

#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;
}

这些是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)

我查看了其他类似问题,并尝试在项目属性选项中添加库文件,或者只在g ++语句中创建-lfwlib32选项。他们都没有引起任何变化。该计划仍然没有建立。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:1)

结果是libfwlib32.so文件用于32位系统,而我的是64位系统。我将尝试在32位系统兼容性

中运行它