mex compilation - undefined reference to `main'

5 次查看(过去 30 天)
I am trying to compile Matlab interface of NOMAD algorithm (https://www.gerad.ca/nomad/Project/Home.html) in Ubuntu 14.04 using gcc-4.7.3.
After executing compilation script provided by algorithm manufacturer I get the following error:
>> GERAD_NOMAD_build
------------------------------------------------
NOMAD MEX FILE BUILD --- GERAD VERSION
Warning: Legacy MEX infrastructure is provided for compatibility; it will be removed in a future
version of MATLAB. For more information, consult the MEX release notes
http://www.mathworks.com/help/matlab/release-notes.html.
> In GERAD_NOMAD_build (line 145)
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /home/bkhusain/.matlab/R2015a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /usr/local/MATLAB/R2015a
-> CC = gcc
-> CC flags:
CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c99
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2015a/bin/glnxa64 -L/usr/local/MATLAB/R2015a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> CXX = g++
-> CXX flags:
CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2015a/bin/glnxa64 -L/usr/local/MATLAB/R2015a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2015a/bin/glnxa64 -L/usr/local/MATLAB/R2015a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments =
-> LD = g++
-> Link flags:
LDFLAGS = -Wl,-rpath,'/../lib/'
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments = -lut -lnomad -L/home/bkhusain/nomad.3.7.3/lib/
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments = -lut -lnomad -L/home/bkhusain/nomad.3.7.3/lib/
----------------------------------------------------------------
-> g++ -c -I. -I/home/bkhusain/nomad.3.7.3/src/ -I/usr/local/MATLAB/R2015a/extern/include -I/usr/local/MATLAB/R2015a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -O -DNDEBUG "nomadmex.cpp"
-> g++ -O -Wl,-rpath,'/../lib/' -o "/home/bkhusain/nomad.3.7.3/bin//nomad.mexa64" nomadmex.o -lut -lnomad -L/home/bkhusain/nomad.3.7.3/lib/ -Wl,-rpath-link,/usr/local/MATLAB/R2015a/bin/glnxa64 -L/usr/local/MATLAB/R2015a/bin/glnxa64 -lmx -lmex -lmat -lm
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
mex: link of ' "/home/bkhusain/nomad.3.7.3/bin//nomad.mexa64"' failed.
Error using GERAD_NOMAD_build (line 166)
Error Compiling NOMAD!
Unable to complete successfully.
The error is thrown after executing:
mex -v -largeArrayDims nomadmex.cpp LDFLAGS='$LDFLAGS -Wl,-rpath,''$ORIGIN/../lib/'' ' -I. -I/home/bkhusain/nomad.3.7.3/src/ -lut -lnomad -L/home/bkhusain/nomad.3.7.3/lib/ -output /home/bkhusain/nomad.3.7.3/bin//nomad.mexa64
I don't understand why linker is complaining about missing reference to 'main', since main function is not required for mex compilation.

采纳的回答

Bulat Khusainov
Bulat Khusainov 2016-12-14
The problem was solved by adding the directory of required *.so files to the path manually. In ~/.bashrc I added:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/bkhusain/Documents/MATLAB/nomad.3.7.3/lib
export LD_LIBRARY_PATH
Also when calling mex I removed LDFLAGS:
mex -v -largeArrayDims nomadmex.cpp -I. -I/home/bkhusain/nomad.3.7.3/src/ -lut -lnomad -L/home/bkhusain/nomad.3.7.3/lib/ -output /home/bkhusain/nomad.3.7.3/bin//nomad.mexa64
Still I do not understand why linker was looking for main() function. I will try to investigate this based on answer Jan Simon's answer

更多回答(1 个)

Jan
Jan 2016-12-14
I hesitate to register at the web page only to answer your question. The linker claims, that the function "main" is called from the function "_start". So either lokk in the source code to find explanations or ask the author.

类别

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