I want to compile about 20 cpp files using the same include and library directories. For this reason, I want to define the directories once and then use them as variables in the mex calls. If I have
mex file1.cpp -LC:/folder1 -LC:/folder2 -LC:/folder3
mex file2.cpp -LC:/folder1 -LC:/folder2 -LC:/folder3
mex file3.cpp -LC:/folder1 -LC:/folder2 -LC:/folder3
I would instead like to write
FOLDER1='C:/folder1'
FOLDER2='C:/folder2'
FOLDER3='C:/folder3'
mex file1.cpp -LFOLDER1-LFOLDER2 -LFOLDER3
mex file2.cpp -LFOLDER1-LFOLDER2 -LFOLDER3
mex file3.cpp -LFOLDER1-LFOLDER2 -LFOLDER3
but it does not seem to work?

 Accepted Answer

Anders - the way you are doing this is probably leading to some warnings such as
ld: warning: directory not found for option '-LFOLDER1'
ld: warning: directory not found for option '-LFOLDER2'
ld: warning: directory not found for option '-LFOLDER3'
Try using the sprintf and eval functions to build a command (string) and then evaluate it.
FOLDER1='C:/folder1';
FOLDER2='C:/folder2';
FOLDER3='C:/folder3';
for k=1:20
cmd = sprintf('mex file%d.cpp -L%s -L%s -L%s',k,FOLDER1,FOLDER2,FOLDER3);
eval(cmd);
end
Note that each iteration of the loop will build a string such as
'mex file1.cpp -LC:/folder1 -LC:/folder2 -LC:/folder3'
which has the folder variables "built" in to the command string.

More Answers (1)

Categories

Asked:

on 5 Oct 2014

Answered:

on 5 Oct 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!