matlab - How to use mexsh to link non-.o object files into a mex executable? -


i'm using matlab 2015b on ubuntu 14.04, gcc 4.8.4.

i'm trying manage c , c++ code in 1 makefile.

the c , c++ code need use different compiler flags. solve problem i'm trying compile .cpp files .xo object files , .c files .o object files, can use different recipe .xo , .o respectively.

here's sample of makefile:

cc=gcc cxx=g++ mex=/usr/local/matlab/r2015b/bin/mexsh  cflags=-wall -fpic -std=gnu99 cxxflags=-wall -fpic -std=gnu++11  includes=/usr/include/boost  lflags=-lm -l/usr/lib -lboost_system -lboost_regex all: hello asio  hello: hello.o               # hello world example, c code, works fine     $(cc) -o $@ $^ $(lflags) asio:asio.xo                 # boost asio example, c++ code, works file     $(cxx) -o $@ $^ $(lflags) mexasio:asio.xo     $(mex) $^ $(lflags) ############  here, .xo files input                         ############  mex gives "no input file" error clean:     rm -f *.o     rm -f *.xo  %.o: %.c      $(cc) -c -o $@ $< $(cflags) -i$(includes) %.xo: %.cpp      $(cxx) -c -o $@ $< $(cxxflags) -i$(includes) 

gcc , g++ has no problem linking object files arbitrary extension, when try use mex link object files create mex executable, mex command accept .o files.

question:

1) there way make mex accept object files arbitrary extesnion?

2) there way compile c++ , c code different compiler flags rather using custom extension object file targets?

1) there way make mex accept object files arbitrary extension?

no, mex wrapper script other compilers , doesn't accept arbitrary extensions object files.

2) there way compile c++ , c code different compiler flags rather using custom extension object file targets?

you doing this

%.o: %.c      $(cc) -c -o $@ $< $(cflags) -i$(includes) %.xo: %.cpp      $(cxx) -c -o $@ $< $(cxxflags) -i$(includes) 

i change following in makefile:

  • %.xo: %.cpp -> %.o: %.cpp
  • asio:asio.xo -> asio:asio.o
  • mexasio:asio.xo -> mexasio:asio.o

you may need change $(mex) $^ $(lflags) $(mex) -cxx $^ $(lflags)


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -