我目前正在 MATLAB 中编写一个 MEX 文件,该文件使用 C 中的 CPLEX API 来解决线性规划问题。
不幸的是,当我尝试编译时遇到了“未找到架构 x86_64 的符号”问题,但我不知道如何解决它。我在下面包含了(MATLAB)输出的副本。我需要做什么才能成功编译?
还有很多与寄存器分配和保存相关的链接器“无法创建紧凑展开”错误。太多了,我删除了其中的 80% 以使其更具可读性。这些有关系吗?他们是否值得关注?
其他一些可能有用的信息:
- 我可以编译 yprime.c 和其他不使用 CPLEX API 的 MEX 文件
- 我在 Mac OSX 10.7.2 上使用 MATLAB 2011b
- 我正在使用 XCode 4.2 中包含的 GCC 4.2 包。
- 我已经为 MATLAB 应用了 XCode 4.2 补丁
这是(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 时不是问题。实际问题是缺少符号,这些符号通常捆绑在 XCode 4.2 中的 CoreFoundation 和 IOKit 框架中。通常可以通过使用 -framework CoreFoundation 和 -framework IOKit 标志来包含它们,但 MATLAB 中的 mex 命令不支持此功能。不过幸运的是,您可以使用 LDFLAGS='\$LDFLAGS -framework CoreFoundation -framework IOKit' 为链接过程添加基于自定义的标志...