필터 지우기
필터 지우기

Compiling mex file that depends on external libraries with extension .so.n

조회 수: 8 (최근 30일)
Michael Mathew
Michael Mathew 2016년 5월 26일
답변: Albert Hofkamp 2017년 11월 21일
I have written a file myprog.cpp and is to be compiled in MATLAB. The program has external library dependencies libnewfile1.so and libnewfile2.so.3. I compiled using following instruction from MATLAB command window.
mex myprog.cpp -lnewfile1.so -lnewfile2.so.3 -L"path to library folder"
I get he following error while compiling.
Error using mex
/usr/bin/ld: cannot find -lnewfile1
/usr/bin/ld: cannot find -lnewfile2.so.3
collect2: error: ld returned 1 exit status
Could anyone please tell me how to compile a cpp file that has external library dependencies?
Later I tried adding the path to LD_LIBRARY_PATH using setenv and getenv shows the above path in LD_LIBRARY_PATH. But still I get the same error.
  댓글 수: 3
Michael Mathew
Michael Mathew 2016년 5월 27일
편집: Michael Mathew 2016년 5월 27일
No I still get the error:
Error using mex
/usr/bin/ld: cannot find -llibnewfile1.so
/usr/bin/ld: cannot find -llibnewfile2.so.3
collect2: error: ld returned 1 exit status
Michael Mathew
Michael Mathew 2016년 5월 28일
I did solve it. The problem was Matlab does not recognise libraries with extensions other than .so; Hence I renamed the library to .so and that solved the issue.

댓글을 달려면 로그인하십시오.

답변 (1개)

Albert Hofkamp
Albert Hofkamp 2017년 11월 21일
Bit late to the party, but the answer is that -l adds a "lib" prefix and a ".so" suffix to its argument, so linking with -Lpath/to/library/dir -lnewfile1 -lnewfile2 will do the trick.
Note that Matlab may add requirements to library-files such as position-independent code, which may or may not have been used while compiling the library.

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by