我目前正在MATLAB中编写MEX文件,该文件使用C语言中的CPLEX API来解决线性编程问题。
不幸的是,当我尝试编译并且我不知道如何解决它时,我遇到了“找不到架构x86_64的符号”问题。我在下面提供了(MATLAB)输出的副本。如何成功编译需要做什么?
链接器的批次无法创建与寄存器分配相关并保存的紧凑展开错误。这么多,我删除了80%,使其更具可读性。这些可以相关吗?他们是否值得关注?
其他一些可能有用的信息:
这是(MATLAB)输出:
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB_R2011b.app
-> CC = llvm-gcc-4.2
-> CC flags:
CFLAGS = -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -fexceptions
CDEBUGFLAGS = -g
COPTIMFLAGS = -O2 -DNDEBUG
CLIBS = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = llvm-g++-4.2
-> CXX flags:
CXXFLAGS = -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O2 -DNDEBUG
CXXLIBS = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -m64 -fbackslash
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -L -lgfortran -L -lgfortranbegin
arguments = -DMX_COMPAT_32
-> LD = llvm-gcc-4.2
-> Link flags:
LDFLAGS = -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2011b.app/extern/lib/maci64/mexFunction.map
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexmaci64
arguments = -L/Users/berk/Applications/IBM/ILOG/CPLEX_Studio_Academic123/cplex/lib/x86-64_darwin9_gcc4.0/static_pic -lilocplex -lcplex
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments = -L/Users/berk/Applications/IBM/ILOG/CPLEX_Studio_Academic123/cplex/lib/x86-64_darwin9_gcc4.0/static_pic -lilocplex -lcplex
----------------------------------------------------------------
-> llvm-gcc-4.2 -c -I/Users/berk/Applications/IBM/ILOG/CPLEX_Studio_Academic123/cplex/include/ -I/Applications/MATLAB_R2011b.app/extern/include -I/Applications/MATLAB_R2011b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -fexceptions -DMX_COMPAT_32 -g "addcutsmx.c"
-> llvm-gcc-4.2 -g -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2011b.app/extern/lib/maci64/mexFunction.map -o "addcutsmx.mexmaci64" addcutsmx.o -L/Users/berk/Applications/IBM/ILOG/CPLEX_Studio_Academic123/cplex/lib/x86-64_darwin9_gcc4.0/static_pic -lilocplex -lcplex -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
ld: warning: could not create compact unwind for _CPXLmsg: register 12 saved somewhere other that in frame
ld: warning: could not create compact unwind for _CPXsetbranchcallbackfunc: register saved more than once (might be shrink wrap)
Undefined symbols for architecture x86_64:
"_kCFAllocatorDefault", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_kIOMasterPortDefault", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_IOServiceMatching", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_IOServiceGetMatchingService", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"___CFStringMakeConstantString", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_IORegistryEntryCreateCFProperty", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_CFGetTypeID", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_CFStringGetTypeID", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_CFStringGetCString", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_CFDataGetTypeID", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_CFDataGetLength", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_CFDataGetBytePtr", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_CFRelease", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
"_IOObjectRelease", referenced from:
_ilm_fun_000 in libcplex.a(env.o)
_ilm_fun_121 in libcplex.a(env.o)
_ilm_api_004 in libcplex.a(env.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
mex: link of ' "addcutsmx.mexmaci64"' failed.
Error using mex (line 206)
Unable to complete successfully.
问题已解决:
为了将来参考,使用CPLEX时警告消息不是问题。实际问题是缺少的符号,它们通常捆绑在CoreFoundation和IOKit框架中,这些框架包含在XCode 4.2中。通常可以使用-framework CoreFoundation和-framework IOKit标志来包含它们,但MATLAB中的mex命令不支持此功能。幸运的是,您可以使用LDFLAGS ='\ $ LDFLAGS -framework CoreFoundation -framework IOKit'为链接过程添加基于自定义的标志...