2014-01-14 3 views
0

MATLAB에서 기존 C 프로그램을 실행하기 위해 작성한 mex 파일을 컴파일하려고합니다. 나는 다음과 같은 오류가 점점 오전 :이 기능은 파일의 일부이기 때문에MEX 파일을 컴파일 할 때 문제가 발생했습니다.

>> 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를 실행하고 있습니다.

어떤 조언을 주셔서 감사합니다!

갱신 1 :

@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 배포본의 일부라는 것을 확인했다. 어떤 아이디어? 감사.

+0

'src0'폴더에있는 라이브러리 (컴파일 된 파일)는 무엇입니까? – Shai

+0

"#include"함수는 공유 라이브러리로 컴파일됩니까? 그들의 소스 코드는 어디에 있습니까? 그 소스 코드를 컴파일 했습니까? – Shai

+0

#included 함수의 소스 코드는 명령 줄에서 '-Iinclude'로 지정한 하위 폴더 "include"에 있습니다. 별도로 컴파일해야합니까? 나는 mex가 main 함수와 함께 #included 소스를 자동으로 컴파일 할 것이라고 생각했다. – dannyhmg

답변

0

대답은 Amro에서 제공했습니다.이 경우에는 -L/usr/local/lib 플래그를 사용하여 라이브러리의 위치를 ​​가리키고 컴파일러에 연결하도록 (예 : 플래그 -lmpfr). Shai에게이 문제를 해결하는 데 도움을 주셔서 감사합니다.

관련 문제