Question

I'm currently writing a MEX file in MATLAB that uses the CPLEX API in C to solve linear programming problems.

Unfortunately, I run into a "symbol(s) not found for architecture x86_64" problem when I attempt to compile and I have no idea of how to solve it. I included a copy of the (MATLAB) output below. What do I need to do to compile successfully?

There are also lots of linker 'could not create compact unwind' errors related to register assignments and saved. So many that I deleted 80% of them to make it more readable. Could these be related? Are they a cause for concern?

Some other information that might be helpful:

  • I can compile yprime.c and other MEX files that do not use the CPLEX API
  • I am using MATLAB 2011b on Mac OSX 10.7.2
  • I am using the GCC 4.2 package included in XCode 4.2.
  • I already applied the XCode 4.2 Patch for MATLAB

Here is the (MATLAB) output:

----------------------------------------------------------------
->    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.

ISSUE RESOLVED:

For future reference, the warning messages are not an issue when using CPLEX. The actual issue were the missing symbols which are usually bundled in CoreFoundation and IOKit frameworks which are included in XCode 4.2. Usually one can include them by using the -framework CoreFoundation and -framework IOKit flags, but the mex command in MATLAB does not support this feature. Luckily, however, you can add custom based flags for the linking process, using LDFLAGS='\$LDFLAGS -framework CoreFoundation -framework IOKit'...

Was it helpful?

Solution

The basic problem is that linker, whose job is to match-up all of the function calls among the compiled bits of your code and shared libraries can't find some of the functions it needs to create the full executable. If the undefined symbol list (the list of missing functions and other missing items) included the name of a function that you forgot to write, then you would need to write it.

However, in this case the missing symbols all seem to be things you would expect to be defined by some form of standard library. (The _ and __ prefix suggest this). In which case you need to add the correct library to the linker's search path using the -l option. In your related post, the -lcplex option did just that for the cplex library, which then allowed the linker to find the missing CPLEX functions.

I don't recognize the specific symbols, but chances are a bit of searching around with google can help you find the required libraries. As a starting point, according to this somewhat dated post, some of the missing symbols appear to be CoreFoundation (MACOSX) symbols, which you should be able to find in one of the /Library/Frameworks folder.

There is also some chance that the CPLEX libraries were built using a different (older?) version of the OSX files. If this is the case, you might look for updated (Lion specific?) library files from CPLEX, and/or seeing if MATLAB/gcc has a backward compatibility option to force using the older OSX frameworks.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top