Comment utiliser un makefile lors de l’appel des fonctions MATLAB en C ++

J’ai eu du mal à comstackr une application que je modifie lorsque j’essaie d’appeler les fonctions MATLAB à l’intérieur. J’ai pu télécharger et exécuter le engdemo.c qui démontre l’utilisation de MATLAB en C ++, mais en essayant d’étendre ce que j’ai pu apprendre de cette démo, je n’arrive pas à comstackr les choses. Je pense qu’un problème est que j’ai un fichier makefile, et je ne suis pas sûr de savoir où placer une ligne pour indiquer à GCC où sont les bibliothèques MATLAB. Il semble que d’autres aient eu du mal à implémenter des connexions à MATLAB à l’aide de makefiles, alors j’espère que cette question sera utile.

Quelques informations pertinentes:

  • J’utilise Fedora
  • J’utilise GCC 4.9.2
  • J’utilise MATLAB R2015b

Voici mon makefile jusqu’ici:

EXECUTABLE:= ../bin/linux/ccmd intel: CC = icpc intel: LD = icpc gnu: CC = g++ gnu: LD = g++ C_SRCS := $(wildcard *.c) CXX_SRCS := $(wildcard *.cpp) # program_CU_SRCS := $(wildcard *.cu) C_OBJS := ${C_SRCS:.c=.o} CXX_OBJS := ${CXX_SRCS:.cpp=.o} # program_CU_OBJS := ${program_CU_SRCS:.cu=.o} OBJS := $(C_OBJS) $(CXX_OBJS) BUILD_DIR := ../build/linux/ OBJS := $(addprefix $(BUILD_DIR), $(OBJS)) VPATH = ./ BOOST_INCLUDE = /u/tps/crennick/boost_1_55_0 # root directory of MATLAB installation MATLABROOT="/usr/local/MATLAB/R2015b/bin/glnxa64" intel: INCLUDE_DIRS := $(BOOST_INCLUDE) $(MATLABROOT) ./include gnu: INCLUDE_DIRS := ./include $(MATLABROOT) intel: LIBRARY_DIR := -L/u/tps/crennick/boost_1_55_0/stage/lib/ LIBRARIES := -lboost_system-mt -lboost_thread-mt -lpthread -lpng -lz -d -leng /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so /usr/local/MATLAB/R2015b/bin/glnxa64/libmat.so CPPFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) intel: CPPFLAGS += -O3 -std=c++11 #gnu: CPPFLAGS += -Ofast -std=c++11 -march=native -ffast-math -flto #gnu: LDFLAGS += -Ofast -std=c++11 -march=native -ffast-math -flto gnu: CPPFLAGS += -Ofast -std=c++11 -march=native -ffast-math -flto -m64 -funroll-loops gnu: LDFLAGS += -Ofast -std=c++11 -march=native -ffast-math -flto -m64 -funroll-loops gnu: CPPFLAGS = -std=c++11 -g gnu: LDFLAGS = -std=c++11 #LIBRARY_PATH = $(foreach librarydir,$(LIBRARIES),$(librarydir)) .PHONY: all clean distclean gnu: $(EXECUTABLE) intel: $(EXECUTABLE) all: $(EXECUTABLE) $(EXECUTABLE): $(OBJS) # ar rc $@ $^ $(CC) -o $@ $^ $(LIBRARY_DIR) $(LIBRARIES) $(BUILD_DIR)%.o : %.cpp $(CC) -c $< -o $@ $(CPPFLAGS) # $(BUILD_DIR)bodysystemcuda.o: bodysystemcuda.cu bodysystemcuda.cpp include/bodysystemcuda.h # $(NVCC_PATH)/nvcc -O3 --include-path $(CUTIL_LIB) -c bodysystemcuda.cu -o $(BUILD_DIR)bodysystemcuda.o clean: @- $(RM) $(EXECUTABLE) @- $(RM) $(OBJS) distclean: clean 

Voici les erreurs que je reçois lors de la compilation:

  /usr/bin/ld: warning: libmwresource_core.so, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libmwi18n.so, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libut.so, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libmwfl.so, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libboost_date_time.so.1.49.0, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libboost_filesystem.so.1.49.0, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libboost_log.so.1.49.0, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libboost_signals.so.1.49.0, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libboost_system.so.1.49.0, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libboost_thread.so.1.49.0, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libmwcpp11compat.so, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libicudata.so.54, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libicuuc.so.54, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libicui18n.so.54, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libicuio.so.54, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmx.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libmx.so, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmat.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libhdf5_hl.so.8, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmat.so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libhdf5.so.8, needed by /usr/local/MATLAB/R2015b/bin/glnxa64/libmat.so, not found (try using -rpath or -rpath-link) ../build/linux/image.o: In function `Image::conv_1D(double*, int, double*, int)': 

Voici ce que j’ai essayé:

  • Taper les répertoires de chaque bibliothèque demandés exactement (inefficace, jette quand même les mêmes erreurs)
  • Vous avez tenté d’utiliser des caractères génériques pour inclure toutes les bibliothèques du répertoire / usr / local / MATLAB / R2015b / bin / glnxa64. Semble gaspiller, jette aussi des erreurs
  • Comme on peut le voir dans le code que j’ai inclus, j’ai essayé d’inclure le répertoire MATLABROOT dans la section INCLUDE_DIRS où je m’attendais à ce que le compilateur le souhaite. Cela n’a rien réparé non plus.

Merci pour votre aide, j’espère que cette question aidera peut-être les autres utilisateurs à construire des applications C ++ qui appellent les fonctions MATLAB à l’aide de makefiles, surtout si elles sont comme moi et ne comprennent pas bien GCC / UNIX / Makefiles!