2012-04-08 9 views
1

Ich arbeite daran, einige Dateien mit meiner make-Datei und C++ zu verknüpfen, und erhalte den folgenden Fehler beim Ausführen von make.Datei erstellen Linkproblem Undefiniertes Symbol für Architektur x86_64

g++ -bind_at_load `pkg-config --cflags opencv` -c -o compute_gist.o compute_gist.cpp 
g++ -bind_at_load `pkg-config --cflags opencv` -c -o gist.o gist.cpp 
g++ -bind_at_load `pkg-config --cflags opencv` -c -o standalone_image.o standalone_image.cpp 
g++ -bind_at_load `pkg-config --cflags opencv` -c -o IplImageConverter.o IplImageConverter.cpp 
g++ -bind_at_load `pkg-config --cflags opencv` -c -o GistCalculator.o GistCalculator.cpp 
g++ -bind_at_load `pkg-config --cflags opencv` `pkg-config --libs opencv` compute_gist.o gist.o standalone_image.o IplImageConverter.o GistCalculator.o -o rungist 
Undefined symbols for architecture x86_64: 
    "color_gist_scaletab(color_image_t*, int, int, int const*)", referenced from: 
    _main in compute_gist.o 
ld: symbol(s) not found for architecture x86_64 
collect2: ld returned 1 exit status 
make: *** [rungist] Error 1 

Mein Make-Datei ist wie folgt (Beachten Sie, ich brauche nicht opencv Bindungen noch, wird aber in opencv später Codierung.

CXX = g++ 
CXXFLAGS = -bind_at_load `pkg-config --cflags opencv` 
LFLAGS = `pkg-config --libs opencv` 

SRC = \ 
compute_gist.cpp \ 
gist.cpp \ 
standalone_image.cpp \ 
IplImageConverter.cpp \ 
GistCalculator.cpp 

OBJS = $(SRC:.cpp=.o) 

rungist: $(OBJS) 
$(CXX) $(CXXFLAGS) $(LFLAGS) $(OBJS) -o [email protected] 
all: rungist 

clean: 
rm -rf $(OBJS) rungist 

Verfahren Header in gist.h befindet

float *color_gist_scaletab(color_image_t *src, int nblocks, int n_scale, const int *n_orientations); 

und das Verfahren ist

float *color_gist_scaletab(color_image_t *src, int w, int n_scale, const int *n_orientation) { 
in gist.cpp definiert

Und schließlich die compute_gist.cpp (Hauptdatei)

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 


#include "gist.h" 


static color_image_t *load_ppm(const char *fname) { 
    FILE *f=fopen(fname,"r"); 
    if(!f) { 
    perror("could not open infile"); 
    exit(1); 
    } 
    int width,height,maxval; 
    if(fscanf(f,"P6 %d %d %d",&width,&height,&maxval)!=3 || maxval!=255) { 
    fprintf(stderr,"Error: input not a raw PPM with maxval 255\n"); 
    exit(1);  
    } 
    fgetc(f); /* eat the newline */ 
    color_image_t *im=color_image_new(width,height); 

    int i; 
    for(i=0;i<width*height;i++) { 
    im->c1[i]=fgetc(f); 
    im->c2[i]=fgetc(f); 
    im->c3[i]=fgetc(f);  
    } 

    fclose(f); 
    return im; 
} 


static void usage(void) { 
    fprintf(stderr,"compute_gist options... [infilename]\n" 
     "infile is a PPM raw file\n" 
     "options:\n" 
     "[-nblocks nb] use a grid of nb*nb cells (default 4)\n" 
     "[-orientationsPerScale o_1,..,o_n] use n scales and compute o_i orientations for scale i\n" 
    ); 

    exit(1); 
} 




int main(int argc,char **args) { 

const char *infilename="/dev/stdin"; 
int nblocks=4; 
int n_scale=3; 
int orientations_per_scale[50]={8,8,4}; 


while(*++args) { 
    const char *a=*args; 

    if(!strcmp(a,"-h")) usage(); 
    else if(!strcmp(a,"-nblocks")) { 
    if(!sscanf(*++args,"%d",&nblocks)) { 
     fprintf(stderr,"could not parse %s argument",a); 
     usage(); 
    } 
    } else if(!strcmp(a,"-orientationsPerScale")) { 
    char *c; 
    n_scale=0; 
    for(c=strtok(*++args,",");c;c=strtok(NULL,",")) { 
     if(!sscanf(c,"%d",&orientations_per_scale[n_scale++])) { 
     fprintf(stderr,"could not parse %s argument",a); 
     usage();   
     } 
    } 
    } else { 
    infilename=a; 
    } 
} 

color_image_t *im=load_ppm(infilename); 

//Here's the method call -> :(
float *desc=color_gist_scaletab(im,nblocks,n_scale,orientations_per_scale); 

int i; 

int descsize=0; 
//compute descriptor size 
for(i=0;i<n_scale;i++) 
    descsize+=nblocks*nblocks*orientations_per_scale[i]; 

    descsize*=3; // color 

    //print descriptor 
    for(i=0;i<descsize;i++) 
    printf("%.4f ",desc[i]); 

    printf("\n"); 

    free(desc); 

    color_image_delete(im); 

    return 0; 
} 

Jede Hilfe wäre sehr dankbar. Ich hoffe, das ist genug Info. Lass mich wissen, wenn ich mehr hinzufügen muss.

+0

Sie sagen, 'color_gist_scaletab' ist in' gist.cpp' definiert, aber was Sie dann zeigen, heißt 'color_gist', nicht' color_gist_scaletab'. – geekosaur

+0

Sorry! Ich habe es bearbeitet. color_gist_scaletab und color_gist sind beide in gist.cpp. – user1035839

Antwort

0

Ich vermute, dass color_gist_scaletab sollte als extern "C" in Ihrer Header-Datei deklariert werden:

extern "C" { 
    float *color_gist_scaletab(color_image_t *src, int nblocks, int n_scale, const int *n_orientations); 
} 
+0

Ich fügte hinzu: 'extern" C "{ float * color_gist_scaletab (color_image_t * src, int nblöcke, int n_scale, const int * n_orientations_); } ' bekam aber den Fehler: undefinierte Symbole für Architektur x86_64: "_color_gist_scaletab", verweist von: _main in compute_gist.o "_color_image_delete", verweist von: _main in compute_gist.o "_color_image_new" , bezogen von: load_ppm (char const *) in compute_gist.o ld: Symbol (e) nicht für die Architektur x86_64 collect2 gefunden: ld ergab 1 Exit-Status make: *** [rungist] Fehler 1 – user1035839

0

Ihre Link-Befehlszeile nicht korrekt ist. Siehe this answer.

Dies ist jedoch wahrscheinlich nicht das Problem, das Sie hier sehen.

Wie werden die folgenden Befehle gedruckt?

file gist.o 
nm gist.o | grep color_gist_scaletab 

Ich sehe auch this sehr ähnliche Frage. Aber dort kommt color_gist_scaletab von gist.c, nicht gist.cpp. Du hast nicht einfach gist.c in gist.cpp umbenannt, oder? Tun Sie nicht dass.

+0

Datei Kern. o druckt gist.o: Mach-O 64-Bit-Objekt x86_64 und nm gist.o | grep color_gist_scaletab druckt nm: keine Namensliste – user1035839

+0

Russion. Nein, ich habe die Dateien nicht umbenannt.Ich habe die Gist-Bibliothek aus zwei verschiedenen Quellen heruntergeladen und versuche, sie in mein Projekt aufzunehmen – user1035839

Verwandte Themen