Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ld error on macOS #99

Open
dmeoli opened this issue Dec 1, 2024 · 2 comments
Open

ld error on macOS #99

dmeoli opened this issue Dec 1, 2024 · 2 comments

Comments

@dmeoli
Copy link

dmeoli commented Dec 1, 2024

hello,

I wrote this bash script to install coin on Linux os:

  // Install COIN-OR CoinUtils and Osi/Clp
  echo "Installing COIN-OR CoinUtils and Osi/Clp..."
  if [ "$HAS_SUDO" -eq 1 ]; then
    apt-get install -y -q coinor-libcoinutils-dev libbz2-dev liblapack-dev libopenblas-dev
  fi
  CoinOr_ROOT="${INSTALL_ROOT}/coin-or"
  if [ ! -d "$CoinOr_ROOT" ]; then
    cd "$INSTALL_ROOT"
    curl -O https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
    chmod u+x coinbrew
    # Build CoinUtils
    ./coinbrew build CoinUtils --latest-release --skip-dependencies --prefix="$CoinOr_ROOT" --tests=none
    # Build Osi with or without CPLEX
    osi_build_flags=(
      "--latest-release"
      "--skip-dependencies"
      "--prefix=$CoinOr_ROOT"
      "--tests=none"
    )
    if [ "$install_cplex" -eq 0 ]; then
      osi_build_flags+=("--without-cplex")
    else
      osi_build_flags+=(
        "--with-cplex"
        "--with-cplex-lib=-L${CPLEX_ROOT}/cplex/lib/x86-64_linux/static_pic -lcplex -lpthread -lm"
        "--with-cplex-incdir=${CPLEX_ROOT}/cplex/include/ilcplex"
      )
    fi
    # Build Osi with or without Gurobi
    if [ "$install_gurobi" -eq 0 ]; then
      osi_build_flags+=("--without-gurobi")
    else
      osi_build_flags+=(
        "--with-gurobi"
        "--with-gurobi-lib=-L${GUROBI_ROOT}/linux64/lib -lgurobi100"
        "--with-gurobi-incdir=${GUROBI_ROOT}/linux64/include"
      )
    fi
    ./coinbrew build Osi "${osi_build_flags[@]}"
    # Build Clp
    ./coinbrew build Clp --latest-release --skip-dependencies --prefix="$CoinOr_ROOT" --tests=none
    rm -Rf coinbrew build CoinUtils Osi Clp
    export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${CoinOr_ROOT}/lib"
    if [ "$HAS_SUDO" -eq 1 ]; then
      sh -c "echo '${CoinOr_ROOT}/lib' > /etc/ld.so.conf.d/coin-or.conf"
      ldconfig
    fi
  else
    echo "COIN-OR already installed."
  fi

and this perfectly works, then I tried to adapt this one for macOS:

  // Install COIN-OR CoinUtils and Osi/Clp
  echo "Installing COIN-OR CoinUtils and Osi/Clp..."
  CoinOr_ROOT="${INSTALL_ROOT}/coin-or"
  if [ ! -d "$CoinOr_ROOT" ]; then
    brew install coinutils lapack openblas
    cd "$INSTALL_ROOT"
    curl -O https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
    chmod u+x coinbrew
    # Build CoinUtils
    ./coinbrew fetch CoinUtils --no-prompt
    # Build Osi with or without CPLEX
    osi_build_flags=(
      "--prefix=$CoinOr_ROOT"
      "--no-prompt"
      "--tests=none"
    )
    if [ "$install_cplex" -eq 0 ]; then
      osi_build_flags+=("--without-cplex")
    else
      osi_build_flags+=(
        "--with-cplex"
        "--with-cplex-lib=-L${CPLEX_ROOT}/cplex/lib/x86-64_osx/static_pic -lcplex -lm"
        "--disable-cplex-libcheck"
        "--with-cplex-incdir=${CPLEX_ROOT}/cplex/include/ilcplex"
      )
    fi
    # Build Osi with or without Gurobi
    if [ "$install_gurobi" -eq 0 ]; then
      osi_build_flags+=("--without-gurobi")
    else
      osi_build_flags+=(
        "--with-gurobi"
        "--with-gurobi-lib=-L${GUROBI_ROOT}/macos_universal2/lib -lgurobi100"
        "--disable-gurobi-libcheck"
        "--with-gurobi-incdir=${GUROBI_ROOT}/macos_universal2/include"
      )
    fi
    ./coinbrew build Osi "${osi_build_flags[@]}"
    # Build Clp
    ./coinbrew build Clp --prefix="$CoinOr_ROOT" --tests=none
    rm -Rf coinbrew build CoinUtils Osi Clp
    export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}:${CoinOr_ROOT}/lib"
  else
    echo "COIN-OR already installed."
  fi

but I am obtaining this error:

. . .

OsiCpxSolverInterface::resolve() in libOsiCpx.1.13.11.dylib-master.o
OsiCpxSolverInterface::resolve() in libOsiCpx.1.13.11.dylib-master.o
OsiCpxSolverInterface::resolve() in libOsiCpx.1.13.11.dylib-master.o
...
"_CPXsolninfo", referenced from:
OsiCpxSolverInterface::getColSolution() const in libOsiCpx.1.13.11.dylib-master.o
OsiCpxSolverInterface::getColSolution() const in libOsiCpx.1.13.11.dylib-master.o
OsiCpxSolverInterface::getRowPrice() const in libOsiCpx.1.13.11.dylib-master.o
OsiCpxSolverInterface::getReducedCost() const in libOsiCpx.1.13.11.dylib-master.o
OsiCpxSolverInterface::getRowActivity() const in libOsiCpx.1.13.11.dylib-master.o
OsiCpxSolverInterface::getObjValue() const in libOsiCpx.1.13.11.dylib-master.o
OsiCpxSolverInterface::getIterationCount() const in libOsiCpx.1.13.11.dylib-master.o
...
"_CPXwriteprob", referenced from:
OsiCpxSolverInterface::writeMps(char const*, char const*, double) const in libOsiCpx.1.13.11.dylib-master.o
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [libOsiCpx.la] Error 1
make: *** [all-recursive] Error 1

does anyone help me to understand what am I wrong?

@svigerske
Copy link
Member

You build for arm64, but try to link a CPLEX library for x86_64. Replace x86-64_osx.

@mapgccv
Copy link

mapgccv commented Dec 3, 2024

Hello there, I have a question that is loosely related to this: is it possible to obtain universal binaries for Cbc using coinbrew?
I'm not using CPLEX or Gurobi, i'm relying on a default CBC build using coinbrew.

I have tried by specifying the architectures as CXX/linker additional parameters (e.g.:

export CFLAGS="-arch x86_64 -arch arm64"
export CXXFLAGS="-arch x86_64 -arch arm64"
export LDFLAGS="-arch x86_64 -arch arm64"

but I get a lot of linker errors of the kind:

Undefined symbols for architecture x86_64:
  "ClpMain0(ClpSimplex*)", referenced from:
      _main in ClpMain.o

Note that I get the same kind of errors if I try to compile only Intel binaries on an ARM Apple (by specifying only x86_64 in the flags above), so I believe i might be doing something wrong.

I'd appreciate any hint/insight, and I apologize if I didn't post this in the correct place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants