Howto: Use CasADi in Cpp using Visual Studio - casadi/casadi GitHub Wiki
Get Ipopt binaries
- Get the md variant from https://github.com/coin-or/Ipopt/releases/tag/releases%2F3.13.3
- Unpack into some place like
C:\Users\me\Ipopt-3.13.3-win64-msvs2019-md(this should contain a subfolder namedIpopt-3.13.3-win64-msvs2019-md)
Compile CasADi
Goal: get a VS-compatible IPOPT-enabled CasADi installation in C:\Users\me\casadi_install.
- Get a copy of CasADi source, e.g. from https://github.com/casadi/casadi/archive/refs/tags/3.5.5.zip and unpack it in a folder.
- In that same source folder (check that
README.mdexists to be sure you are in the correct folder), create arun.batwith the following contents:
@echo Must be run in a prompt context that defines vcvars.
@echo For example in 'x64 Native Tools Command Prompt for VS 2019'
cmake -G "Visual Studio 16 2019" -A x64 -B build -DWITH_IPOPT=ON -DIPOPT_LIBRARIES:FILEPATH="C:/Users/me/Ipopt-3.13.3-win64-msvs2019-md/Ipopt-3.13.3-win64-msvs2019-md/lib/ipopt.dll.lib" -DIPOPT_INCLUDE_DIRS:PATH="C:/Users/me/Ipopt-3.13.3-win64-msvs2019-md/Ipopt-3.13.3-win64-msvs2019-md/include/coin-or" -DCMAKE_INSTALL_PREFIX:PATH="C:/Users/me/casadi_install"
cmake --build build --config Release
cmake --install build
- Run this file inside a "x64 Native Tools Command Prompt for VS 2019" from within that same source folder.
Compile a CasADi C++ example
Goal: get a casadi_demo.exe to run succesfully.
- Make a local copy of https://github.com/casadi/casadi/tree/3.5.5/docs/examples/cplusplus/cmake_find_package
- Add an extra line
install(TARGETS casadi_demo RUNTIME DESTINATION . LIBRARY DESTINATION .)toCMakeLists.txtif absent. - Create a
run.batwith the following contents:
@echo Must be run in a prompt context that defines vcvars.
@echo For example in 'x64 Native Tools Command Prompt for VS 2019'
set CMAKE_PREFIX_PATH=C:\Users\me\casadi_install
cmake -G "Visual Studio 16 2019" -A x64 -B build -DCMAKE_INSTALL_PREFIX:PATH="."
cmake --build build --config Release
cmake --install build
set PATH=%PATH%;C:\Users\me\casadi_install\casadi;C:\Users\me\Ipopt-3.13.3-win64-msvs2019-md\Ipopt-3.13.3-win64-msvs2019-md\bin
casadi_demo.exe
- Run this file inside a "x64 Native Tools Command Prompt for VS 2019"