I'm running Matlab on Ubuntu 12.04. I have written a C++ function simulation.cpp using the mex format. I've defined some of my functions in a separate header file that is located in the same directory as simulation.cpp. I read on the web that to compile a .cpp file with header files, I need to use -l and provide the path of the header files. When I run the following:
mex -l"/media/.../folder_containing_header_files" simulation.cpp
I get the following error
/usr/bin/ld: cannot find -l/media/.../folder_containing_header_files/ collect2: ld returned 1 exit status
mex: link of ' "simulation.mexglx"' failed.
Incidentally, all my header files are located in the same directory as simulation.cpp, which is also my working directory in matlab.
Does anybody know what the problem is?
You used the "-l" (lower-case L) option; you need to use "-I" (upper-case I). "I" for "include".
Also you might need to use a space between the option and its value.
If your current directly is the directory that contains simulation.cpp and its associated header files, doesn't simply "mex simulation.cpp" work at the command line?
There should be no space between the switch and the directory. So can you try:
mex -I./ gateway.c
mex -I "./" gateway.c
Thank You all for your help.
James: I do have all my header files in one folder. When I tried without the -I as you suggested, I was getting an undefined reference error for all functions declared in my header file and defined in a separate cpp file (with the same name as the header file). Some web-searching revealed that I shouldn't be doing just
mex simulation.cpp header.cpp
This worked. Sorry if this is well-known, I wasn't aware of this - I don't have a CS or compilers background.
Thanks again James, Walter and Ryan!