Makefile: Converting C-code to mex code (Linking error)

大憨熊 提交于 2019-12-01 16:25:32

The problem is that all of the object files listed in $(OBJS_tsnnls0) (or, at the very least, libtsnnls_la-taucs_ccs_order.o) have been compiled without the -fPIC gcc compiler option. The gcc man page says for -fPIC

Generate position-independent code ( PIC ) suitable for use in a shared library

Note that MEX-files are shared libraries. Thus, all the object code links perfectly fine into a standalone executable (which does not require PIC), but it is just not compiled right to link into a MEX-file (or any shared library). If you have the original source files, you should be able to recompile them with the right switches by running

$(MEX) -c -o filename.o filename.c

for each of the source files.

You have a circular dependency on tsnnls_test_DKU.o because OBJS_tsnnlsAll expands to include OBJS_tsnnls1 which is defined as tsnnls_test_DKU.o in the first line of the Makefile.

Also you don't have a rule to build OBJS_tsnnlsAll. You are just passing the names of all the object files to the compiler which is ignoring them because of the -c flag.

You should remove $(OBJS_tsnnlsALL) from the tsnnls_test_DKU.o rule, and remove the tsnnls_test_DKU.o from the final target so last two rules look like this:

# CHANGED FROM HERE     # mex
tsnnls_test_DKU.o: tsnnls_test_DKU.c  Include_4_TSNNLS.c $(OBJS_ADD)
    $(CXX) $(CFLAGS) $(INCLUDE)  -c $^

# Final linking
$(TARGET): $(OBJS_tsnnlsALL)  $(OBJS_ADD)   $(LIBS) 
    $(MEX) $(MEXFLAGS)  -output $(TARGET_WO_EXTN) $^      -largeArrayDims
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!