繁体   English   中英

编译MEX文件时出现故障链接

[英]Trouble Linking when compiling a MEX file

我试图编译我编写的mex文件,以便在MATLAB中运行预先存在的C程序。 我收到以下错误:

>> mex src/main.c -Iinclude -I/Users/my_name/mpfr-3.1.1/src/ -I/Users/my_name/gmp-5.0.5 -Lsrc0 -output cpdetect_c
Undefined symbols for architecture x86_64:
  "_binomial_main", referenced from:
      _cpdetect in main.o
  "_gaussian1_main", referenced from:
      _cpdetect in main.o
  "_gaussianU_main", referenced from:
      _cpdetect in main.o
  "_mpfr_clears", referenced from:
      _cpdetect in main.o
  "_mpfr_exp10", referenced from:
      _cpdetect in main.o
  "_mpfr_inits2", referenced from:
      _cpdetect in main.o
  "_mpfr_set_d", referenced from:
      _cpdetect in main.o
  "_poisson_main", referenced from:
      _cpdetect in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

我很困惑,因为这些功能都是我在代码中#Include的文件的一部分。 我如何让编译器找到它们?

我在Mac OS X 10.8和Xcode 4.6.3上运行MATLAB R2013a。

感谢您的任何建议!

UPDATE1:

@Shai:我的src0文件夹的内容:

>> ls src0
Makefile            gaussian1.o         test_gaussian1.c        test_tools.c
Makefile.am         loadtraj.c          test_gaussian1_point_calc.c test_tools.o
Makefile.in         loadtraj.o          test_load           tools.c
binomial.c          main.c              test_load.c         tools.o
binomial.o          main.o              test_load.o
cpdetect            poisson.c           test_poisson.c
gaussian1.c         poisson.o           test_tools

这个C程序(最初是指要在命令行上运行)来自一个朋友,并且已经存在src0文件夹。 编写mex函数时,我修改了'src'文件夹中的代码文件,但没有触摸src0文件夹。

更新2:我意识到我指向mpfr的错误位置。 我现在正在使用以下编译命令:

>> mex src/main.c src/binomial.c src/gaussian1.c src/gaussianU.c src/poisson.c -Iinclude -I/usr/local/include -lmpfr -output cpdetect_c

它给出了以下错误:

Undefined symbols for architecture x86_64:
  "_mpfr_mul_d", referenced from:
      _gaussian1_calc_constant_part in gaussian1.o
      _gaussianU_calc_constant_part in gaussianU.o
  "_mpfr_printf", referenced from:
      _find_gaussian1_change_point in gaussian1.o
      _gaussian1_point_calc in gaussian1.o
      _gaussianU_calc_constant_part in gaussianU.o
      _find_gaussianU_change_point in gaussianU.o
      _find_poisson_change_point in poisson.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

    mex: link of ' "cpdetect_c.mexmaci64"' failed.

这很奇怪。 并不是说编译器找不到任何mpfr函数-似乎可以找到很多其他函数而没有任何麻烦(如果我故意省略-lmpfr标志,则会得到更长的未定义符号列表) 。 我确实确认mpfr_mul_d和mpfr_printf是我安装的mpfr发行版的一部分。 有任何想法吗? 谢谢。

答案是由Amro提供的-必须同时指向库的位置(在这种情况下使用标志-L / usr / local / lib),并告诉编译器链接到该库(使用标志-lmpfr )。 也感谢Shai协助解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM