使文件链接为体系结构x86_64发出未定义的符号 我正在使用我的make文件和C++获取一些文件链接在一起,并且在运行make时,我会遇到以下错误。p> 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

使文件链接为体系结构x86_64发出未定义的符号 我正在使用我的make文件和C++获取一些文件链接在一起,并且在运行make时,我会遇到以下错误。p> 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,c++,linker,makefile,undefined-symbol,C++,Linker,Makefile,Undefined Symbol,我的makefile如下所示:注意,我还不需要opencv绑定,但稍后将在opencv中编码 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.cp

我的makefile如下所示:注意,我还不需要opencv绑定,但稍后将在opencv中编码

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 $@
all: rungist

clean:
rm -rf $(OBJS) rungist
方法标题位于gist.h中

float *color_gist_scaletab(color_image_t *src, int nblocks, int n_scale, const int *n_orientations);
方法在gist.cpp中定义

float *color_gist_scaletab(color_image_t *src, int w, int n_scale, const int *n_orientation) {
最后是compute_gist.cpp主文件

#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; 
}
任何帮助都将不胜感激。我希望这是足够的信息。如果需要添加更多内容,请告诉我。

我怀疑应该在头文件中将color\u gist\u scaletab声明为extern C:

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

您的链接命令行不正确。看

然而,这可能不是你在这里看到的问题

以下命令打印什么

file gist.o
nm gist.o | grep color_gist_scaletab

我也看到了非常类似的问题。但是在这里,color\u gist\u scaletab来自gist.c,而不是gist.cpp。您并没有将gist.c重命名为gist.cpp,是吗?不要这样做。

你说颜色是在gist.cpp中定义的,但你随后显示的是名为颜色,而不是颜色。对此,我很抱歉!我编辑了它。color_gist_scaletab和color_gist都在gist.cpp.file gist.o打印gist.o:Mach-o 64位对象x86_64和nm gist.o|grep color_gist_scaletab打印nm:no name listrusion。不,我没有重命名这些文件。我从两个不同的来源下载了Gist库,并试图在我的项目中添加外部C{float*color\u Gist\u scaletabcolor\u image\u t*src,int nblocks,int n\u scale,const int*n\u orientations\u6},但得到了错误:架构x86\u 64的未定义符号:\u color\u Gist\u scaletab,引用自:_mainin compute\u gist.o_color\u image\u delete,引用自:_mainin compute\u gist.o_color\u image\u new,引用自:load\u ppmchar const*in compute\u gist.o ld:未找到架构x86\u 64集合的符号2:ld返回1退出状态make:**[rungist]错误1