Trouble using codegen with MATLAB

419 views
Skip to first unread message

heidi...@gmail.com

unread,
Apr 25, 2019, 9:39:38 AM4/25/19
to OSQP
Hi, I am having trouble using the codegen function in MATLAB. I have installed all the necessary things (cmake and C-compiler) but I am getting an error that cmake is not a recognized command, even though cmake is in the path.

Does anybody have any suggestions?

heidi...@gmail.com

unread,
Apr 25, 2019, 9:46:02 AM4/25/19
to OSQP
torsdag 25. april 2019 15.39.38 UTC+2 skrev heidi...@gmail.com følgende:
> Hi, I am having trouble using the codegen function in MATLAB 2018b. I have installed all the necessary things (cmake and C-compiler) but I am getting an error that cmake is not a recognized command, even though cmake is in the path.
>
> Does anybody have any suggestions?

I am also having trouble on another computer (with MATLAB 2015b). Which is that when I run "make_osqp" I get the error "Error configuring CMAKE environment" because "CMAKE_MAKE_PROGRAM" is not set. The internet says I should find the make fil associated with mingw-64 and set it as that, but that make file is not on my computer.

Bartolomeo Stellato

unread,
Apr 25, 2019, 9:51:15 AM4/25/19
to heidi...@gmail.com, OSQP
Hi,

Which operating system are you using? How did you install cmake? Did you add it to the PATH variable? If you type `cmake --version` in the terminal what do you see?

Bartolomeo


--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osqp/b9531871-3b11-421c-a63e-206a6c000865%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

heidi...@gmail.com

unread,
Apr 25, 2019, 9:53:48 AM4/25/19
to OSQP

> Which operating system are you using?

Windows 10

> How did you install cmake?

From here: https://cmake.org/

> Did you add it to the PATH variable?

CMake\bin is added to my PATH

> If you type `cmake --version` in the terminal what do you see?

cmake version 3.14.3

However in the MATLAB terminal I get "Undefined function 'cmake'"

Paul Goulart

unread,
Apr 25, 2019, 9:54:11 AM4/25/19
to OSQP
I suggest typing 

   !cmake --version

from the matlab prompt as well.   If it fails, then it is not on the path that is visible to matlab.


On Thursday, April 25, 2019 at 2:51:15 PM UTC+1, Bartolomeo Stellato wrote:
Hi,

Which operating system are you using? How did you install cmake? Did you add it to the PATH variable? If you type `cmake --version` in the terminal what do you see?

Bartolomeo


On Thu, Apr 25, 2019 at 9:46 AM <heidi...@gmail.com> wrote:
torsdag 25. april 2019 15.39.38 UTC+2 skrev heidi...@gmail.com følgende:
> Hi, I am having trouble using the codegen function in MATLAB 2018b. I have installed all the necessary things (cmake and C-compiler) but I am getting an error that cmake is not a recognized command, even though cmake is in the path.
>
> Does anybody have any suggestions?

I am also having trouble on another computer (with MATLAB 2015b). Which is that when I run "make_osqp" I get the error "Error configuring CMAKE environment" because "CMAKE_MAKE_PROGRAM" is not set. The internet says I should find the make fil associated with mingw-64 and set it as that, but that make file is not on my computer.

--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to os...@googlegroups.com.

heidi...@gmail.com

unread,
Apr 25, 2019, 9:55:12 AM4/25/19
to OSQP

> I suggest typing 
>
>
>    !cmake --version
>
>
> from the matlab prompt as well.   If it fails, then it is not on the path that is visible to matlab.

!cmake --version works in MATLAB!

Bartolomeo Stellato

unread,
Apr 25, 2019, 10:00:41 AM4/25/19
to heidi...@gmail.com, OSQP
Can you please send us:

1) the exact commands you are running and erros that you get

2) the output of `getenv('PATH')` from matlab?

3) The output of `!cmake --version` from matlab

It is hard for us to understand the errors without such information.

Bartolomeo


--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osqp/b28b8f07-2075-4fc4-8b13-0db5938bca39%40googlegroups.com.

heidi...@gmail.com

unread,
Apr 25, 2019, 10:06:35 AM4/25/19
to OSQP
Of course. I realize the original error I described was a previous one, my mistake! My problem now is not being able to run "make_osqp".

> Can you please send us:
>
>
> 1) the exact commands you are running and erros that you get

My path is /osqp-matlab/ and I run make_osqp.

Error: CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!



> 2) the output of `getenv('PATH')` from matlab?

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\MATLAB\R2015b\runtime\win64;C:\Program Files\MATLAB\R2015b\bin;C:\Program Files\MATLAB\R2015b\polyspace\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Common Files\Quanser\hardware\;C:\Program Files (x86)\Common Files\Quanser\hardware\;C:\Program Files\Quanser\QUARC\;C:\Program Files\Git\cmd;C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\bin;C:\Users\hisollie\AppData\Local\Microsoft\WindowsApps;C:\Program Files\CMake\bin

> 3) The output of `!cmake --version` from matlab

cmake version 3.14.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Bartolomeo Stellato

unread,
Apr 25, 2019, 10:17:19 AM4/25/19
to heidi...@gmail.com, OSQP

Have you checked you installed the compiler properly? Did you add the mingw binaries to your path/matlab path?

Bartolomeo


--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+uns...@googlegroups.com.

Paul Goulart

unread,
Apr 25, 2019, 10:17:50 AM4/25/19
to OSQP
Do you have a C compiler installed?  If so, which one?

If you are just trying to compile the standard matlab interface, you can just download a pre-compiled binary for Windows if you want.   See here.

On the same page linked above there is also a note about mingw paths.

heidi...@gmail.com

unread,
Apr 25, 2019, 10:26:23 AM4/25/19
to OSQP

> Do you have a C compiler installed?  If so, which one?

Yes, MinGW64, which I installed as a MATLAB support package.
>
> If you are just trying to compile the standard matlab interface, you can just download a pre-compiled binary for Windows if you want.   See here.

I did that earlier yes.

> Have you checked you installed the compiler properly?

I'm not sure if I've installed the compiler correctly, no. I just ran the .mlpkginstall (MATLAB package installer) file that I downloaded.

It seems the problem might be that I don't have this mingw64-make file.'

> Did you add the mingw binaries to your path/matlab path?
Yes I believe so. \R2015b\MW_MinGW_4_9\bin is in my path.

Paul Goulart

unread,
Apr 25, 2019, 10:35:16 AM4/25/19
to OSQP
It seems like the problem is possibly unrelated to matlab.   Can you build vanilla osqp using cmake from sources, following the docs here?.

heidi...@gmail.com

unread,
Apr 25, 2019, 10:48:05 AM4/25/19
to OSQP

> It seems like the problem is possibly unrelated to matlab. Can you build vanilla osqp using cmake from sources, following the docs here?.

On step 3. Create Makefiles I run "cmake -G "MinGw Makefiles" ..
and get the error "The source directory does not appear to contain CMakeLists.txt.".

Paul Goulart

unread,
Apr 25, 2019, 10:53:38 AM4/25/19
to OSQP
CMakeLists.txt should be in root directory of the osqp source files.   Either it has been deleted somehow, or cmake is not being run in the right place.

Are you sure that it is being run from within <osqp>/build, and are you adding the ".." to the end of the cmake command, i.e.
cmake -G "MinGW Makefiles" ..

heidi...@gmail.com

unread,
Apr 25, 2019, 10:58:16 AM4/25/19
to OSQP

> CMakeLists.txt should be in root directory of the osqp source files.   Either it has been deleted somehow, or cmake is not being run in the right place.
>
I deleted the folder and downloaded it again.
Now I get the same error as earlier:

heidi...@gmail.com

unread,
Apr 25, 2019, 11:32:51 AM4/25/19
to OSQP
It worked now! Thanks guys! I had to download and install tdm-gcc and add the mingw32-make.exe file, which was in TDM-GCC-64/bin, to the path.

Bartolomeo Stellato

unread,
Apr 25, 2019, 12:40:41 PM4/25/19
to heidi...@gmail.com, OSQP
Good to hear. I believe TDM-GCC is the preferred option for compiler on Windows.

Have fun using OSQP! 

Bartolomeo


On Thu, Apr 25, 2019 at 11:32 AM <heidi...@gmail.com> wrote:
It worked now! Thanks guys! I had to download and install tdm-gcc and add the mingw32-make.exe file, which was in TDM-GCC-64/bin, to the path.

--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+uns...@googlegroups.com.

heidi...@gmail.com

unread,
Apr 26, 2019, 3:53:15 AM4/26/19
to OSQP
Good morning. The same error as earlier is popping up when using "codegen" in MATLAB.

When I run '!mingw32-make' in the MATLAB terminal I get "is not recognized as an internal or external command, operable program or batch file". However
'C:\TDM-GCC-64\bin' is in my MATLAB path, and I have checked that the mingw32-make.exe file is located there.

When I run 'mingw32-make' in the command prompt on Windows I get '** No targets specified and no makefile found. Stop.',so it's in the path there.

Any tips?

Paul Goulart

unread,
Apr 26, 2019, 4:02:46 AM4/26/19
to OSQP
Executing a command with a '!' (or using 'system') in matlab issues the command to your operating system, not to matlab, so the matlab search path doesn't do anything. It is possible that the system path is not what you think it is when running matlab.   Note in particular that the matlab search path and the MATLAB_PATH environment variable aren't the same thing.

heidi...@gmail.com

unread,
Apr 26, 2019, 4:18:13 AM4/26/19
to OSQP

> Does this link help?


Hm, I'm not sure. I _think_ I added the location to my MATLAB path
setenv('PATH', [getenv('PATH') 'C:\TDM-GCC-64\bin'])

and I got a new error, "'cmake' is not recognized as an internal or external command, operable program or batch file."

And when running '!mingw32-make.exe' in MATLAB, I also get "not recognized as an internal or external command, operable program or batch file."

heidi...@gmail.com

unread,
Apr 26, 2019, 4:30:12 AM4/26/19
to OSQP
I have checked and it looks like cmake is both in the MATLAB system path and the search path, aand added to the system variables PATH and user variables PATH. So I really can't figure out what the problem is.

Paul Goulart

unread,
Apr 26, 2019, 4:36:34 AM4/26/19
to OSQP
It's because cmake is not on your PATH, or at least Matlab does not think so.   Same with mingw32-make.   Possibly it is just not there, or the directory name is wrong, or you've not delimited the directories in the path correctly.

What does "getenv('PATH')" do?   Are the directories in PATH correctly separated, e.g. with a semicolon (in windows)?   The command you have written below does not include a semicolon where one is seemingly required.

Maybe try it this way instead?

heidi...@gmail.com

unread,
Apr 26, 2019, 4:52:29 AM4/26/19
to OSQP
> What does "getenv('PATH')" do? Are the directories in PATH correctly separated, e.g. with a semicolon (in windows)?

No, they were not. That was the problem, thanks!

Now, it's not working because it cannot find files

"CMake Error: File C:/../c_code/configure/osqp_configure.h.in does not exist"

even though this folder "c_code" is on the script makes to store the generated c-code.

Paul Goulart

unread,
Apr 26, 2019, 5:17:59 AM4/26/19
to OSQP
I don't think that "C:/../<anything>" can ever be a valid directory in windows, because you're asking it to look one directory up from "C:".  Perhaps I have misunderstood though.

heidi...@gmail.com

unread,
Apr 26, 2019, 5:19:53 AM4/26/19
to OSQP
Oh, sorry I just didn’t bother writing out the whole file path. The computer I’m working on doesn’t have internet right now so I have to write out all error messages on my laptop. But assume it’s a legitimate file path

Paul Goulart

unread,
Apr 26, 2019, 5:24:45 AM4/26/19
to OSQP
I'm not sure what to advise in that case.   I can only assume based on the error you get that either 1) the directory does not exist, or 2) the file osqp_configure.h.in is not in it.

heidi...@gmail.com

unread,
Apr 26, 2019, 5:26:46 AM4/26/19
to OSQP
It’s the latter. The file is not in that directory. But the directory is made when the script is run so there must be some mistake there.

Paul Goulart

unread,
Apr 26, 2019, 5:31:14 AM4/26/19
to OSQP
In that case I will need to leave you to either Goran or Bartolomeo, since I didn't write any of the codegen stuff.

mcia...@gmail.com

unread,
Apr 26, 2019, 6:23:26 AM4/26/19
to OSQP
The codegen system pulls the source files from inside codegen/sources. Can you please verify that your copy of that directory contains the following files:
└── sources
    ├── configure
    │   ├── osqp_configure.h.in
    │   └── qdldl_types.h.in
    ├── include
    │   ├── auxil.h
    │   ├── constants.h
    │   ├── glob_opts.h
    │   ├── kkt.h
    │   ├── lin_alg.h
    │   ├── osqp.h
    │   ├── proj.h
    │   ├── qdldl.h
    │   ├── qdldl_interface.h
    │   ├── scaling.h
    │   ├── types.h
    │   └── util.h
    └── src
        ├── auxil.c
        ├── kkt.c
        ├── lin_alg.c
        ├── osqp.c
        ├── proj.c
        ├── qdldl.c
        ├── qdldl_interface.c
        ├── scaling.c
        └── util.c

If any of these files are missing, run the command "make_osqp('codegen')" and that should recreate all the needed files.

On Friday, April 26, 2019 at 10:26:46 AM UTC+1, heidi...@gmail.com wrote:

heidi...@gmail.com

unread,
Apr 26, 2019, 7:31:20 AM4/26/19
to OSQP

> If any of these files are missing, run the command "make_osqp('codegen')" and that should recreate all the needed files.

Yes, all the qdldl files were missing so I ran the command and they showed up in under "codegen/sources".

Now I get an error using mex, specifically
"C:\Users\user\folder\osqp-matlab\osqp_mex.cpp : error C2440: 'type cast' : cannot convert from 'double' to 'linsys_solver_type' "

along with many warnings about conversion from 'c_int' to 'int', possible loss of data.

Is it the actual OSQP object it is having trouble with now?

heidi...@gmail.com

unread,
Apr 26, 2019, 9:54:06 AM4/26/19
to OSQP
And now I'm back to the same error as earlier without having changed anything about the directory. This is very frustrating...

Bartolomeo Stellato

unread,
Apr 26, 2019, 10:00:57 AM4/26/19
to heidi...@gmail.com, OSQP
Have you tried to install the interface using the binaries? https://osqp.org/docs/get_started/matlab.html We intentionally provide binaries to help.

I am sorry but if you just provide comments like "And now I'm back to the same error as earlier without having changed anything about the directory." it is extremely hard for us to help you. What changed? Something must have changed. Which error? Which compiler and Matlab version are you using now? How did you install OSQP?

If you are not more specific we cannot really help you.

Bartolomeo


On Fri, Apr 26, 2019 at 9:54 AM <heidi...@gmail.com> wrote:
And now I'm back to the same error as earlier without having changed anything about the directory. This is very frustrating...

--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+uns...@googlegroups.com.

heidi...@gmail.com

unread,
Apr 26, 2019, 10:06:16 AM4/26/19
to OSQP

> Have you tried to install the interface using the binaries? https://osqp.org/docs/get_started/matlab.html We intentionally provide binaries to help.

Thanks I'll try this.
>
>
> I am sorry but if you just provide comments like "And now I'm back to the same error as earlier without having changed anything about the directory." it is extremely hard for us to help you.

Totally understandable. :)

> What changed? Something must have changed. Which error? Which compiler and Matlab version are you using now? How did you install OSQP?

It was frustrating because I don't think anything changed, so I cannot explain why the outcome is different. I seemingly tried to do the same thing after a few hours break. Obviously, there has to be something different so I'll keep looking.

All your help so far has been invaluable.

Paul Goulart

unread,
Apr 26, 2019, 2:02:09 PM4/26/19
to OSQP
It would be helpful to know the matlab version.   If it is older than 2015b then we haven't tested it, so perhaps the problem is there.

Another possibility is that you are getting qdldl_interface.c but not qdldl.c (note "qdldl.c" specifically, not the associated .h file).   Are you sure that this file exists?   If not, perhaps the problem is that you have cloned the osqp directory but not cloned its submodules, which includes qdldl.

Perhaps "git submodule update --init --recursive" from the osqp-matlab directory will help?

heidi...@gmail.com

unread,
Apr 27, 2019, 7:25:25 AM4/27/19
to OSQP

> It would be helpful to know the matlab version.   If it is older than 2015b then we haven't tested it, so perhaps the problem is there.

I am using MATLAB 2015b.

> Another possibility is that you are getting qdldl_interface.c but not qdldl.c (note "qdldl.c" specifically, not the associated .h file).   Are you sure that this file exists?   If not, perhaps the problem is that you have cloned the osqp directory but not cloned its submodules, which includes qdldl.

> Perhaps "git submodule update --init --recursive" from the osqp-matlab directory will help?

Yes I think this could have been the problem.

Anyway, codegen works now. Thanks for all the help!
Reply all
Reply to author
Forward
0 new messages