Matlab C-gateway and Fortran-source mixed mex function on 2014a - c

Up to version 2013a I had no problem to compile, link and run my C-gateway and Fortran-source mixed mex functions (Windows, Linux and Mac). Compiling and linking went ok on R2014a-maci64 but when I try to run the resulting mex function I received the following msg:
Invalid MEX-file '/Users/name/MATLAB/mexaci64_R2014a/xxxx.mexmaci64':
dlopen(/Users/name/MATLAB/mexaci64_R2014a/xxxx.mexmaci64, 6): Symbol not found:
__gfortran_transfer_character_write
Referenced from: /Users/name/MATLAB/mexaci64_R2014a/xxxx.mexmaci64
Expected in: /Applications/MATLAB_R2014a.app/sys/os/maci64/libgfortran.3.dylib
in /Users/name/MATLAB/mexaci64_R2014a/xxxx.mexmaci64
The first thing I have found out is that libgfortran.3.dylib that comes with matlab does not seem to have __gfortran_transfer_character_write (Could someone check this too, please?), since the command
nm libgfortran.3.dylib | grep __gfortran_transfer_character_write
showns nothing.
I have replaced the entire maci64 dir with new libraries (say from gfortran 4.9.1 or 4.8.2) to get
nm libgfortran.3.dylib | grep __gfortran_transfer_character_write
00000000000c7210 T __gfortran_transfer_character_write
which means there is something there ("T" The symbol is in the text (code) section). However if I re-compile my mixed mex function again (of course with the new gfortran compiler and the right paths), the error msg is still there.
Fortran write command (example write(6,*)) seems to be the problem since all other mixed mex functions that do not have a fortran write work.
Can someone point out what I am doing wrong?
Thank you very much
Ed
gfortran -c -I/Applications/MATLAB_2014a.app/extern/include -I/Applications/MATLAB_2014a.app/simulink/include -fexceptions -m64 -fbackslash -DMX_COMPAT_32 -O sourcef1.f
gfortran -c -I/Applications/MATLAB_2014a.app/extern/include -I/Applications/MATLAB_2014a.app/simulink/include -fexceptions -m64 -fbackslash -DMX_COMPAT_32 -O sourcef2.f
mex -v -O -compatibleArrayDims sourcef1g.c sourcef1.o correl.o -L/Users/name/Downloads/tmp/usr/local/lib -lgfortran -L/Users/name/Downloads/tmp/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0 -lgfortranbegin
Verbose mode is on.
... Looking for compiler 'Xcode with Clang' ...
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer' ...Yes.
... Executing command 'which xcrun' ...Yes ('/usr/bin/xcrun').
... Looking for folder '/usr/bin' ...Yes.
... Executing command 'defaults read com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...No.
... Executing command 'defaults read /Library/Preferences/com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...Yes ('5.1').
... Executing command '
agreed=5.1
if echo $agreed | grep -E '[\.\"]' >/dev/null; then
lhs=`expr "$agreed" : '\([0-9]*\)[\.].*'`
rhs=`expr "$agreed" : '[0-9]*[\.]\(.*\)$'`
if echo $rhs | grep -E '[\."]' >/dev/null; then
rhs=`expr "$rhs" : '\([0-9]*\)[\.].*'`
fi
if [ $lhs -gt 4 ] || ( [ $lhs -eq 4 ] && [ $rhs -ge 3 ] ); then
echo $agreed
else
exit 1
fi
fi' ...Yes ('5.1').
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' ...Yes.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' ...Yes.
... Executing command 'echo /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk | rev | cut -c1-10 | rev | egrep -oh '[0-9]+\.[0-9]+'' ...Yes ('10.8').
Found installed compiler 'Xcode with Clang'.
Options file details
-------------------------------------------------------------------
Compiler location: /Applications/Xcode.app/Contents/Developer
Options file: /Users/name/.matlab/R2014a/mex_C_maci64.xml
CMDLINE100 : /usr/bin/xcrun -sdk macosx10.8 clang -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2014a.app/extern/include" -I"/Applications/MATLAB_R2014a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.8 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -O2 -DNDEBUG /Users/name/MATLAB/mexaci64_R2014a/sourcef1g.c -o /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
CMDLINE200 : /usr/bin/xcrun -sdk macosx10.8 clang -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.8 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o sourcef1.o correl.o -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" -lgfortran -lgfortranbegin -L/Users/name/Downloads/tmp/usr/local/lib -L/Users/name/Downloads/tmp/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0 -L"/Applications/MATLAB_R2014a.app/bin/maci64" -lmx -lmex -lmat -lstdc++ -o sourcef1g.mexmaci64
CMDLINE300 : rm -f /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
CC : /usr/bin/xcrun -sdk macosx10.8 clang
DEFINES : -DMX_COMPAT_32 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CFLAGS : -fno-common -arch x86_64 -mmacosx-version-min=10.8 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
INCLUDE : -I"/Applications/MATLAB_R2014a.app/extern/include" -I"/Applications/MATLAB_R2014a.app/simulink/include"
COPTIMFLAGS : -O2 -DNDEBUG
CDEBUGFLAGS : -g
LD : /usr/bin/xcrun -sdk macosx10.8 clang
LDFLAGS : -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.8 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map"
LDBUNDLE : -bundle
LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map"
LINKLIBS : -lgfortran -lgfortranbegin -L/Users/name/Downloads/tmp/usr/local/lib -L/Users/name/Downloads/tmp/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0 -L"/Applications/MATLAB_R2014a.app/bin/maci64" -lmx -lmex -lmat -lstdc++
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexmaci64
XCODE_DIR : /Applications/Xcode.app/Contents/Developer
XCRUN_DIR : /usr/bin
XCODE_AGREED_VERSION : 5.1
ISYSROOT : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
SDKVER : 10.8
MATLABROOT : /Applications/MATLAB_R2014a.app
ARCH : maci64
SRC : /Users/name/MATLAB/mexaci64_R2014a/sourcef1g.c
OBJ : /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
OBJS : /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o sourcef1.o correl.o
SRCROOT : /Users/name/MATLAB/mexaci64_R2014a/sourcef1g
DEF : /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.def
EXP : sourcef1g.exp
LIB : sourcef1g.lib
EXE : sourcef1g.mexmaci64
ILK : sourcef1g.ilk
MANIFEST : sourcef1g.mexmaci64.manifest
TEMPNAME : sourcef1g
EXEDIR :
EXENAME : sourcef1g
OPTIM : -O2 -DNDEBUG
LINKOPTIM : -O
-------------------------------------------------------------------
Building with 'Xcode with Clang'.
/usr/bin/xcrun -sdk macosx10.8 clang -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2014a.app/extern/include" -I"/Applications/MATLAB_R2014a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.8 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -O2 -DNDEBUG /Users/name/MATLAB/mexaci64_R2014a/sourcef1g.c -o /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
/usr/bin/xcrun -sdk macosx10.8 clang -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.8 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o sourcef1.o correl.o -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" -lgfortran -lgfortranbegin -L/Users/name/Downloads/tmp/usr/local/lib -L/Users/name/Downloads/tmp/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0 -L"/Applications/MATLAB_R2014a.app/bin/maci64" -lmx -lmex -lmat -lstdc++ -o sourcef1g.mexmaci64
rm -f /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
MEX completed successfully.
mv -f sourcef1g.mexmaci64 sourcef1.mexmaci64

Actually, MATLAB (or MEX) does not support gfortran with version higher than 4.3.x, according to this page: Supported and Compatible Compilers – Release 2014a.
I have met exactly the same problem before. After I switched to gfortran-mp-4.3, problem solved.

Related

Simulink cross-compilation succeeded, application not working

I am currently trying to compile a Simulink model for a SoC board that is running a Linux OS. I am able to compile and run applications successfully for this board making my own makefiles, which are really very simple.
The cross-compiler I am using is the
environment-setup-cortexa8hf-vfp-neon-poky-linux-gnueabi
Also, generating c code from a Simulink model and applying my makefile works as well. (With very simple simulink models)
The problem is when I try to generate code and also compile the simulink model with the following options:
ert.tcl
toolchain: automatic (GNU)
for: faster builds
This generates a binary that is working but I have to modify the makefile in order to compile the code with my cross-compiler. The cross-compilation works but when I try to run the application in the SoC board I get the following error:
-sh. ./application file not found
Here is the makefile:
###########################################################################
## Makefile generated for Simulink model 'simmod'.
##
## Makefile : simmod.mk
## Generated on : Tue Sep 11 14:57:43 2018
## MATLAB Coder version: 4.0 (R2018a)
##
## Build Info:
##
## Final product: $(RELATIVE_PATH_TO_ANCHOR)/simmod
## Product type : executable
## Build type : Top-Level Standalone Executable
##
###########################################################################
###########################################################################
## MACROS
###########################################################################
# Macro Descriptions:
# PRODUCT_NAME Name of the system to build
# MAKEFILE Name of this makefile
# COMPUTER Computer type. See the MATLAB "computer" command.
PRODUCT_NAME = simmod
MAKEFILE = simmod.mk
COMPUTER = GLNXA64
MATLAB_ROOT = /opt/MATLAB/R2018a
MATLAB_BIN = /opt/MATLAB/R2018a/bin
MATLAB_ARCH_BIN = $(MATLAB_BIN)/glnxa64
MASTER_ANCHOR_DIR =
START_DIR = /home/hector/Documents/Qt/DA_AMiRo/Devices/Reflective_Operator/Matlab_Reflective_Operator/temp
ARCH = glnxa64
SOLVER =
SOLVER_OBJ =
CLASSIC_INTERFACE = 0
TGT_FCN_LIB = ISO_C
MODEL_HAS_DYNAMICALLY_LOADED_SFCNS = 0
MODELREF_LINK_RSPFILE_NAME = simmod_ref.rsp
RELATIVE_PATH_TO_ANCHOR = ..
C_STANDARD_OPTS = -mfloat-abi=hard -std=gnu99 -pedantic -fwrapv #-std=c99
CPP_STANDARD_OPTS = -fwrapv
###########################################################################
## TOOLCHAIN SPECIFICATIONS
###########################################################################
# Toolchain Name: GNU gcc/g++ v4.4.x | gmake (64-bit Linux)
# Supported Version(s): 4.4.x
# ToolchainInfo Version: R2018a
# Specification Revision: 1.0
#
#-------------------------------------------
# Macros assumed to be defined elsewhere
#-------------------------------------------
# C_STANDARD_OPTS
# CPP_STANDARD_OPTS
#-----------
# MACROS
#-----------
WARN_FLAGS = -Wall -W -Wwrite-strings -Winline -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Wcast-align
WARN_FLAGS_MAX = $(WARN_FLAGS) -Wcast-qual -Wshadow
CPP_WARN_FLAGS = -Wall -W -Wwrite-strings -Winline -Wpointer-arith -Wcast-align
CPP_WARN_FLAGS_MAX = $(CPP_WARN_FLAGS) -Wcast-qual -Wshadow
TOOLCHAIN_SRCS =
TOOLCHAIN_INCS =
TOOLCHAIN_LIBS =
#------------------------
# BUILD TOOL COMMANDS
#------------------------
# C Compiler: GNU C Compiler
CC = arm-poky-linux-gnueabi-gcc #gcc
# Linker: GNU Linker
LD = arm-poky-linux-gnueabi-g++ #g++
# C++ Compiler: GNU C++ Compiler
CPP = arm-poky-linux-gnueabi-g++ #g++
# C++ Linker: GNU C++ Linker
CPP_LD = arm-poky-linux-gnueabi-g++ #g++
# Archiver: GNU Archiver
AR = ar
# MEX Tool: MEX Tool
MEX_PATH = $(MATLAB_ARCH_BIN)
MEX = "$(MEX_PATH)/mex"
# Download: Download
DOWNLOAD =
# Execute: Execute
EXECUTE = $(PRODUCT)
# Builder: GMAKE Utility
MAKE_PATH = %MATLAB%/bin/glnxa64
MAKE = "$(MAKE_PATH)/gmake"
#-------------------------
# Directives/Utilities
#-------------------------
CDEBUG = -g
C_OUTPUT_FLAG = -o
LDDEBUG = -g
OUTPUT_FLAG = -o
CPPDEBUG = -g
CPP_OUTPUT_FLAG = -o
CPPLDDEBUG = -g
OUTPUT_FLAG = -o
ARDEBUG =
STATICLIB_OUTPUT_FLAG =
MEX_DEBUG = -g
RM = #rm -f
ECHO = #echo
MV = #mv
RUN =
#----------------------------------------
# "Faster Builds" Build Configuration
#----------------------------------------
ARFLAGS = ruvs
CFLAGS = -c $(C_STANDARD_OPTS) -fPIC \
-O0
CPPFLAGS = -c $(CPP_STANDARD_OPTS) -fPIC \
-O0
CPP_LDFLAGS = -Wl,-rpath,"$(MATLAB_ARCH_BIN)",-L"$(MATLAB_ARCH_BIN)"
CPP_SHAREDLIB_LDFLAGS = -shared -Wl,-rpath,"$(MATLAB_ARCH_BIN)",-L"$(MATLAB_ARCH_BIN)" -Wl,--no-undefined
DOWNLOAD_FLAGS =
EXECUTE_FLAGS =
LDFLAGS = -Wl,-rpath,"$(MATLAB_ARCH_BIN)",-L"$(MATLAB_ARCH_BIN)"
MEX_CPPFLAGS = -R2018a -MATLAB_ARCH=$(ARCH) $(INCLUDES) \
\
CXXOPTIMFLAGS="$(C_STANDARD_OPTS) \
-O0 \
$(DEFINES)" \
\
-silent
MEX_CPPLDFLAGS = LDFLAGS=='$$LDFLAGS'
MEX_CFLAGS = -R2018a -MATLAB_ARCH=$(ARCH) $(INCLUDES) \
\
COPTIMFLAGS="$(C_STANDARD_OPTS) \
-O0 \
$(DEFINES)" \
\
-silent
MEX_LDFLAGS = LDFLAGS=='$$LDFLAGS'
MAKE_FLAGS = -f $(MAKEFILE)
SHAREDLIB_LDFLAGS = -shared -Wl,-rpath,"$(MATLAB_ARCH_BIN)",-L"$(MATLAB_ARCH_BIN)" -Wl,--no-undefined
#--------------------
# File extensions
#--------------------
H_EXT = .h
OBJ_EXT = .o
C_EXT = .c
EXE_EXT =
SHAREDLIB_EXT = .so
HPP_EXT = .hpp
OBJ_EXT = .o
CPP_EXT = .cpp
EXE_EXT =
SHAREDLIB_EXT = .so
STATICLIB_EXT = .a
MEX_EXT = .mexa64
MAKE_EXT = .mk
###########################################################################
## OUTPUT INFO
###########################################################################
PRODUCT = $(RELATIVE_PATH_TO_ANCHOR)/simmod
PRODUCT_TYPE = "executable"
BUILD_TYPE = "Top-Level Standalone Executable"
###########################################################################
## INCLUDE PATHS
###########################################################################
INCLUDES_BUILDINFO = -I$(START_DIR) -I$(START_DIR)/simmod_ert_rtw -I$(MATLAB_ROOT)/extern/include -I$(MATLAB_ROOT)/simulink/include -I$(MATLAB_ROOT)/rtw/c/src -I$(MATLAB_ROOT)/rtw/c/src/ext_mode/common -I$(MATLAB_ROOT)/rtw/c/ert
INCLUDES = $(INCLUDES_BUILDINFO)
###########################################################################
## DEFINES
###########################################################################
DEFINES_BUILD_ARGS = -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTERMFCN=1 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0
DEFINES_IMPLIED = -DTID01EQ=0
DEFINES_STANDARD = -DMODEL=simmod -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -DUNIX
DEFINES = $(DEFINES_BUILD_ARGS) $(DEFINES_IMPLIED) $(DEFINES_STANDARD)
###########################################################################
## SOURCE FILES
###########################################################################
SRCS = $(START_DIR)/simmod_ert_rtw/simmod.c
MAIN_SRC = $(START_DIR)/simmod_ert_rtw/ert_main.c
ALL_SRCS = $(SRCS) $(MAIN_SRC)
###########################################################################
## OBJECTS
###########################################################################
OBJS = simmod.o
MAIN_OBJ = ert_main.o
ALL_OBJS = $(OBJS) $(MAIN_OBJ)
###########################################################################
## PREBUILT OBJECT FILES
###########################################################################
PREBUILT_OBJS =
###########################################################################
## LIBRARIES
###########################################################################
LIBS =
###########################################################################
## SYSTEM LIBRARIES
###########################################################################
SYSTEM_LIBS = -lm
###########################################################################
## ADDITIONAL TOOLCHAIN FLAGS
###########################################################################
#---------------
# C Compiler
#---------------
CFLAGS_BASIC = $(DEFINES) $(INCLUDES)
CFLAGS += $(CFLAGS_BASIC)
#-----------------
# C++ Compiler
#-----------------
CPPFLAGS_BASIC = $(DEFINES) $(INCLUDES)
CPPFLAGS += $(CPPFLAGS_BASIC)
###########################################################################
## INLINED COMMANDS
###########################################################################
###########################################################################
## PHONY TARGETS
###########################################################################
.PHONY : all build buildobj clean info prebuild download execute
all : build
#echo "### Successfully generated all binary outputs."
build : prebuild $(PRODUCT)
buildobj : prebuild $(OBJS) $(PREBUILT_OBJS)
#echo "### Successfully generated all binary outputs."
prebuild :
download : build
execute : download
#echo "### Invoking postbuild tool "Execute" ..."
$(EXECUTE) $(EXECUTE_FLAGS)
#echo "### Done invoking postbuild tool."
###########################################################################
## FINAL TARGET
###########################################################################
#-------------------------------------------
# Create a standalone executable
#-------------------------------------------
$(PRODUCT) : $(OBJS) $(PREBUILT_OBJS) $(MAIN_OBJ)
#echo "### Creating standalone executable "$(PRODUCT)" ..."
$(LD) $(LDFLAGS) -o $(PRODUCT) $(OBJS) $(MAIN_OBJ) $(SYSTEM_LIBS) $(TOOLCHAIN_LIBS)
#echo "### Created: $(PRODUCT)"
###########################################################################
## INTERMEDIATE TARGETS
###########################################################################
#---------------------
# SOURCE-TO-OBJECT
#---------------------
%.o : %.c
$(CC) $(CFLAGS) -o "$#" "$<"
%.o : %.cpp
$(CPP) $(CPPFLAGS) -o "$#" "$<"
%.o : $(RELATIVE_PATH_TO_ANCHOR)/%.c
$(CC) $(CFLAGS) -o "$#" "$<"
%.o : $(RELATIVE_PATH_TO_ANCHOR)/%.cpp
$(CPP) $(CPPFLAGS) -o "$#" "$<"
%.o : $(MATLAB_ROOT)/rtw/c/src/%.c
$(CC) $(CFLAGS) -o "$#" "$<"
%.o : $(MATLAB_ROOT)/rtw/c/src/%.cpp
$(CPP) $(CPPFLAGS) -o "$#" "$<"
%.o : $(MATLAB_ROOT)/simulink/src/%.c
$(CC) $(CFLAGS) -o "$#" "$<"
%.o : $(MATLAB_ROOT)/simulink/src/%.cpp
$(CPP) $(CPPFLAGS) -o "$#" "$<"
%.o : $(START_DIR)/%.c
$(CC) $(CFLAGS) -o "$#" "$<"
%.o : $(START_DIR)/%.cpp
$(CPP) $(CPPFLAGS) -o "$#" "$<"
%.o : $(START_DIR)/simmod_ert_rtw/%.c
$(CC) $(CFLAGS) -o "$#" "$<"
%.o : $(START_DIR)/simmod_ert_rtw/%.cpp
$(CPP) $(CPPFLAGS) -o "$#" "$<"
###########################################################################
## DEPENDENCIES
###########################################################################
$(ALL_OBJS) : $(MAKEFILE) rtw_proj.tmw
###########################################################################
## MISCELLANEOUS TARGETS
###########################################################################
info :
#echo "### PRODUCT = $(PRODUCT)"
#echo "### PRODUCT_TYPE = $(PRODUCT_TYPE)"
#echo "### BUILD_TYPE = $(BUILD_TYPE)"
#echo "### INCLUDES = $(INCLUDES)"
#echo "### DEFINES = $(DEFINES)"
#echo "### ALL_SRCS = $(ALL_SRCS)"
#echo "### ALL_OBJS = $(ALL_OBJS)"
#echo "### LIBS = $(LIBS)"
#echo "### MODELREF_LIBS = $(MODELREF_LIBS)"
#echo "### SYSTEM_LIBS = $(SYSTEM_LIBS)"
#echo "### TOOLCHAIN_LIBS = $(TOOLCHAIN_LIBS)"
#echo "### CFLAGS = $(CFLAGS)"
#echo "### LDFLAGS = $(LDFLAGS)"
#echo "### SHAREDLIB_LDFLAGS = $(SHAREDLIB_LDFLAGS)"
#echo "### CPPFLAGS = $(CPPFLAGS)"
#echo "### CPP_LDFLAGS = $(CPP_LDFLAGS)"
#echo "### CPP_SHAREDLIB_LDFLAGS = $(CPP_SHAREDLIB_LDFLAGS)"
#echo "### ARFLAGS = $(ARFLAGS)"
#echo "### MEX_CFLAGS = $(MEX_CFLAGS)"
#echo "### MEX_CPPFLAGS = $(MEX_CPPFLAGS)"
#echo "### MEX_LDFLAGS = $(MEX_LDFLAGS)"
#echo "### MEX_CPPLDFLAGS = $(MEX_CPPLDFLAGS)"
#echo "### DOWNLOAD_FLAGS = $(DOWNLOAD_FLAGS)"
#echo "### EXECUTE_FLAGS = $(EXECUTE_FLAGS)"
#echo "### MAKE_FLAGS = $(MAKE_FLAGS)"
clean :
$(ECHO) "### Deleting all derived files..."
$(RM) $(PRODUCT)
$(RM) $(ALL_OBJS)
$(ECHO) "### Deleted all derived files."

Create makefile which iterate through directory

$project
|
+------------+----------------+----------------+
| | | |
gestore/ tipoA/ tipoB/ shared/
| | | |
+ + + +
| | | +--------|------------------+
gestore.c tipoA.c tipoB.c/ funzioni.c/.h sem.c/.h gF.c./
Hello, I would like to create a makefile for this project, which does these commands:
Step 1 in SHARED FOLDER:
gcc -c -o gestioneFile gestioneFile.c
gcc -c -o sem sem.c
gcc -c -o funzioni funzioni.c
Step 2 in tipoA FOLDER:
gcc -o tipoA tipoA.c ../shared/funzioni ../shared/sem ../shared/gestioneFile
Step 3 in tipoB FOLDER:
gcc -o tipoB tipoB.c ../shared/funzioni ../shared/sem ../shared/gestioneFile
Step 4 in gestore FOLDER:
gcc -o gestore gestore.c ../shared/funzioni ../shared/sem ../shared/gestioneFile
./gestore
This is my makefile but it doesn't works:
#Makefile
cc=gcc
./gestore/gestore: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o ./tipoA/tipoA.o ./tipoB/tipoB.o ./gestore/gestore.o
./gestore/gestore
./shared/gestioneFile.o:
cc -c -o ./shared/gestioneFile ./shared/gestioneFile.c
./shared/sem.o:
cc -c -o ./shared/sem ./shared/sem.c
./shared/functions.o:
cc -c -o ./shared/funzioni ./shared/funzioni.c
./tipoA/tipoA.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoA/tipoA ./tipoA/tipoA.c ./shared/funzioni ./shared/sem ./shared/gestioneFile
./tipoB/tipoB.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoB/tipoB ./tipoB/tipoB.c ../shared/funzioni ../shared/sem ../shared/gestioneFile
./gestore/gestore.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./gestore/gestore ./gestore/gestore.c ./shared/funzioni ./shared/sem ./shared/gestioneFile
EDIT:
#HardcoreHenry This is my makefile now, but it gives the error: ***** Missing separator.**
#Makefile
cc=gcc
./gestore/gestore: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o ./tipoA/tipoA.o ./tipoB/tipoB.o ./gestore/gestore.o
./gestore/gestore
./shared/gestioneFile.o:
cc -c -o ./shared/gestioneFile.o ./shared/gestioneFile.c
./shared/sem.o:
cc -c -o ./shared/sem.o ./shared/sem.c
./shared/funzioni.o:
cc -c -o ./shared/funzioni.o ./shared/funzioni.c
./tipoA/tipoA.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoA/tipoA.o ./tipoA/tipoA.c ./shared/funzioni.o ./shared/sem.o ./shared/gestioneFile.o
./tipoB/tipoB.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoB/tipoB.o ./tipoB/tipoB.c ../shared/funzioni.o ../shared/sem.o ../shared/gestioneFile.o
./gestore/gestore.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./gestore/gestore.o ./gestore/gestore.c ./shared/funzioni.o ./shared/sem.o ./shared/gestioneFile.o
SOLVED (even if the first rule does not execute the file):
./gestore/gestore: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o ./tipoA/tipoA ./tipoB/tipoB ./gestore/gestore
./gestore/gestore
./shared/gestioneFile.o:
gcc -c -o ./shared/gestioneFile ./shared/gestioneFile.c
./shared/sem.o:
gcc -c -o ./shared/sem ./shared/sem.c
./shared/funzioni.o:
gcc -c -o ./shared/funzioni ./shared/funzioni.c
./tipoA/tipoA: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
gcc -o ./tipoA/tipoA ./tipoA/tipoA.c ./shared/gestioneFile ./shared/sem ./shared/funzioni
./tipoB/tipoB: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
gcc -o ./tipoB/tipoB ./tipoB/tipoB.c ./shared/gestioneFile ./shared/sem ./shared/funzioni
./gestore/gestore: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
gcc -o ./gestore/gestore ./gestore/gestore.c ./shared/gestioneFile ./shared/sem ./shared/funzioni
The following line would give you those errors:
./tipoA/tipoA.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoA/tipoA ./tipoA/tipoA.c ./shared/funzioni ./shared/sem ./shared/gestioneFile
First, you are outputting to ./tipoA/tipoA instead of ./tipoA/tipoA.o as #Nonyme pointed out. This would not cause your compile failure though.
What would cause a failure is that it is trying to use ./shared/funzioni as an input -- that file does not exist. (notice the makefile target depends on ./shared/funzioni.o, which must be built before this recipe is invoked, but it does not generate shared/funzioni (without the .o)
You need to add the .o's to the target and sources of your cc commands.
I would also suggest using $(CC), and lookup automatic variables -- specifically $# and $^ for your recipes. Much neater and less error prone that way.
./tipoA/tipoA.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
$(CC) -o $# $^

Make: "The system cannot find the path specified" only when compiling with makefile?

I have a C-application that i'm trying to build with a makefile. When I call make I get:
Compiling file: nrf_drv_rtc.c
arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -mabi=aapcs --std=gnu99 -Wall -O0 -g3 -mfloat-abi=soft -ffunction-sections -fdata-sections -fno-strict-aliasing -c -o build/nrf_drv_rtc.o nrf51_sdk/drivers_nrf/rtc/nrf_drv_rtc.c
"C:/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q1/bin/arm-none-eabi-gcc" -mcpu=cortex-m0 -mthumb -mabi=aapcs --std=gnu99 -Wall -O0 -g3 -mfloat-abi=soft -ffunction-sections -fdata-sections -fno-strict-aliasing -c -o build/nrf_drv_rtc.o nrf51_sdk/drivers_nrf/rtc/nrf_drv_rtc.c
The system cannot find the path specified.
make[1]: *** [build/nrf_drv_rtc.o] Error 1
And true enough no "build/nrf_drv_rtc.o" file is build. Strange thing is that if i copy the line:
arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -mabi=aapcs --std=gnu99 -Wall -O0 -g3 -mfloat-abi=soft -ffunction-sections -fdata-sections -fno-strict-aliasing -c -o build/nrf_drv_rtc.o nrf51_sdk/drivers_nrf/rtc/nrf_drv_rtc.c
to cmd and runs it, it compiles fine and generate "build/nrf_drv_rtc.o"?
Here's my makefile:
PROJECT_NAME := ble_app_hrs_s110_pca10028
export OUTPUT_FILENAME
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
TEMPLATE_PATH = nrf51_sdk/toolchain/gcc
ifeq ($(OS),Windows_NT)
include $(TEMPLATE_PATH)/Makefile.windows
else
include $(TEMPLATE_PATH)/Makefile.posix
endif
MK := mkdir
RM := rm -rf
#echo suspend
ifeq ("$(VERBOSE)","1")
NO_ECHO :=
else
NO_ECHO := #
endif
# Toolchain commands
CC := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
AS := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as"
AR := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r
LD := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
NM := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm"
OBJDUMP := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump"
OBJCOPY := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy"
SIZE := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size"
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
#source common to all targets
C_SOURCE_FILES += \
nrf51_sdk/drivers_nrf/rtc/nrf_drv_rtc.c \
Drivers/NRF51_BLEDriver.c \
(..... a lot more files ....)
#assembly files common to all targets
ASM_SOURCE_FILES = nrf51_sdk/toolchain/gcc/gcc_startup_nrf51.s
#includes common to all targets
INC_PATHS = -I Application/
(..... a lot more include paths.......)
OBJECT_DIRECTORY = _build
LISTING_DIRECTORY =$(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY =$(OBJECT_DIRECTORY)
# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
#flags common to all targets
CFLAGS = -DSOFTDEVICE_PRESENT
CFLAGS += -DNRF51
CFLAGS += -DS110
CFLAGS += -DBOARD_PCA10028
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -O0 -g3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
#CFLAGS += -flto -fno-builtin
# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys
# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DNRF51
ASMFLAGS += -DS110
ASMFLAGS += -DBOARD_PCA10028
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
#default target - first one defined
#default: clean nrf51422_xxac_s110
#building all targets
all: #clean
#$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac_s110
#target for printing all targets
help:
#echo following targets are available:
#echo nrf51422_xxac_s110
#echo flash_softdevice
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
nrf51422_xxac_s110: OUTPUT_FILENAME := nrf51422_xxac_s110
nrf51422_xxac_s110: LINKER_SCRIPT=ble_app_hrs_gcc_nrf51.ld
nrf51422_xxac_s110: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
## Create build directories
$(BUILD_DIRECTORIES):
echo $(MAKEFILE_NAME)
$(MK) $#
# Create objects from C SRC files
$(OBJECT_DIRECTORY)/%.o: %.c
#echo Compiling file: $(notdir $<)
#echo arm-none-eabi-gcc $(CFLAGS) $(INC_PATHS) -c -o $# $<
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $# $<
# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
#echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $# $<
# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
## Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
finalize: genbin genhex echosize
genbin:
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
genhex:
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
echosize:
-#echo ""
$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
-#echo ""
clean:
$(RM) $(BUILD_DIRECTORIES)
cleanobj:
$(RM) $(BUILD_DIRECTORIES)/*.o
flash: $(MAKECMDGOALS)
#echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex)
## Flash softdevice
flash_softdevice:
#echo Flashing: s110_softdevice.hex
nrfjprog --reset --program nrf51_sdk/softdevice/s110/hex/s110_softdevice.hex
Turns out, that the include: include $(TEMPLATE_PATH)/Makefile.windows defined the GNU_INSTALL_ROOT variable as a compiler version that wasn't installed on my computer. So I corrected it, and everything works like a charm .

Make error: make (e=2): The system cannot find the file specified

I am trying to compile a c project on a new windows PC, but when I run make I get:
D:\Eclipse_Workspace\project>make
##make -f makefile -C ./ -e cleanobj
process_begin: CreateProcess(NULL, ##make -f makefile -C ./ -e cleanobj, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [all] Fejl 2
On my other PC the project is compiling just fine.
Also "Fejl 2" is danish for "Error 2", have no idea why that is in danish when the rest is english.
EDIT:
Here is the makefile (it's rather long)
PROJECT_NAME := ble_app_hrs_s110_pca10028
export OUTPUT_FILENAME
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
TEMPLATE_PATH = nrf51_sdk/toolchain/gcc
ifeq ($(OS),Windows_NT)
include $(TEMPLATE_PATH)/Makefile.windows
else
include $(TEMPLATE_PATH)/Makefile.posix
endif
MK := mkdir
RM := rm -rf
#echo suspend
ifeq ("$(VERBOSE)","1")
NO_ECHO :=
else
NO_ECHO := #
endif
# Toolchain commands
CC := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
AS := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as"
AR := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r
LD := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
NM := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm"
OBJDUMP := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump"
OBJCOPY := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy"
SIZE := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size"
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
#source common to all targets
C_SOURCE_FILES += \
nrf51_sdk/drivers_nrf/rtc/nrf_drv_rtc.c \
Drivers/NRF51_BLEDriver.c \
(..... a lot more files ....)
#assembly files common to all targets
ASM_SOURCE_FILES = nrf51_sdk/toolchain/gcc/gcc_startup_nrf51.s
#includes common to all targets
INC_PATHS = -I Application/
(..... a lot more include paths.......)
OBJECT_DIRECTORY = _build
LISTING_DIRECTORY =$(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY =$(OBJECT_DIRECTORY)
# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
#flags common to all targets
CFLAGS = -DSOFTDEVICE_PRESENT
CFLAGS += -DNRF51
CFLAGS += -DS110
CFLAGS += -DBOARD_PCA10028
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -O0 -g3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
#CFLAGS += -flto -fno-builtin
# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys
# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DNRF51
ASMFLAGS += -DS110
ASMFLAGS += -DBOARD_PCA10028
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
#default target - first one defined
#default: clean nrf51422_xxac_s110
#building all targets
all: #clean
#$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac_s110
#target for printing all targets
help:
#echo following targets are available:
#echo nrf51422_xxac_s110
#echo flash_softdevice
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
nrf51422_xxac_s110: OUTPUT_FILENAME := nrf51422_xxac_s110
nrf51422_xxac_s110: LINKER_SCRIPT=ble_app_hrs_gcc_nrf51.ld
nrf51422_xxac_s110: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
## Create build directories
$(BUILD_DIRECTORIES):
echo $(MAKEFILE_NAME)
$(MK) $#
# Create objects from C SRC files
$(OBJECT_DIRECTORY)/%.o: %.c
#echo Compiling file: $(notdir $<)
#echo arm-none-eabi-gcc $(CFLAGS) $(INC_PATHS) -c -o $# $<
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $# $<
# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
#echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $# $<
# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
## Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
finalize: genbin genhex echosize
genbin:
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
genhex:
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
echosize:
-#echo ""
$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
-#echo ""
clean:
$(RM) $(BUILD_DIRECTORIES)
cleanobj:
$(RM) $(BUILD_DIRECTORIES)/*.o
flash: $(MAKECMDGOALS)
#echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex)
## Flash softdevice
flash_softdevice:
#echo Flashing: s110_softdevice.hex
nrfjprog --reset --program nrf51_sdk/softdevice/s110/hex/s110_softdevice.hex
In make, every line indented by a TAB character (in a "recipe context") will be passed as a command to the shell. Nothing about such a line will be interpreted by make, except for $.
In particular for you, the # character is not special to make in this context and doesn't introduce a make comment line. So in this rule:
all: #clean
#$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac_s110
the first line is not commented out; it's a command line that begins with a # character and make will ask the system to run that command. Clearly such a command doesn't exist on your system.
If you want to comment out recipe lines in make, you should always put the comment character at the beginning of the line not after the TAB:
all: #clean
# $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac_s110
Just a comment - I struggled for a very long time until I realised RM was set to rm -f and there was no way that works on Windows. Set it to del and all was fine

Linking protobuf library using GNU makefile on Linux

I know that the protobuf library must be linked using GNU makefile flags -lprotobuf -lpthread or maybe -l:libprotobuf.so -lpthread; however when I make with -Wl,--verbose I see the following output:
attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libprotobuf.a failed
attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libprotobuf.a failed
attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libprotobuf.a failed
attempt to open /lib/../lib64/libprotobuf.a failed
attempt to open /usr/lib/../lib64/libprotobuf.a failed
attempt to open /usr/x86_64-redhat-linux/lib64/libprotobuf.a failed
attempt to open /usr/local/lib64/libprotobuf.a failed
attempt to open /lib64/libprotobuf.a failed
attempt to open /usr/lib64/libprotobuf.a failed
attempt to open /usr/x86_64-redhat-linux/lib/libprotobuf.a failed
attempt to open /usr/lib64/libprotobuf.a failed
attempt to open /usr/local/lib/libprotobuf.a failed
attempt to open /lib/libprotobuf.a failed
attempt to open /usr/lib/libprotobuf.a failed
/usr/bin/ld: cannot find -lprotobuf
collect2: ld returned 1 exit status
make: *** [playfun] Error 1
and using -l:libprotobuf.so -lpthread instead:
/usr/bin/ld: cannot find -l:libprotobuf.so
collect2: ld returned 1 exit status
make: *** [playfun] Error 1
and I know I have the Google protobuf library installed:
$ locate libprotobuf
/usr/lib/libprotobuf.so
/usr/lib/libprotobuf.so.6
/usr/lib/libprotobuf.so.6.0.0
/usr/lib64/libprotobuf.so
/usr/lib64/libprotobuf.so.6
/usr/lib64/libprotobuf.so.6.0.0
The code in question is the "tasbot" (learnfun/playfun) project found at http://tom7misc.svn.sourceforge.net/viewvc/tom7misc/trunk/tasbot/ ; here is the makefile which I've tried to customize for my build (CentOS 5.8) and trim down to an SSCCE:
# Makefile made by tom7.
default: playfun learnfun
# tasbot
# emu_test
all: playfun tasbot emu_test objective_test learnfun weighted-objectives_test
CXXFLAGS=-Wall -Wno-deprecated -Wno-sign-compare -I/usr/local/include -fno-strict-aliasing
CXX=g++
CC=gcc
SDLARCH=x64
PROTOC=protoc
PROTO_HEADERS=marionet.pb.h
PROTO_OBJECTS=marionet.pb.o
# If you don't have SDL, you can leave these out, and maybe it still works.
#CCNETWORKING= -DMARIONET=1 -I SDL/include -I SDL_net
CCNETWORKING= -I /usr/include/SDL
#LINKSDL= -mno-cygwin -lm -luser32 -lgdi32 -lwinmm -ldxguid
LINKSDL= -lSDL
#LINKNETWORKING= $(LINKSDL) -lwsock32 -liphlpapi
#LINKNETWORKING= $(LINKSDL) -lprotobuf -lpthread
LINKNETWORKING= $(LINKSDL) -l:libprotobuf.so -lpthread
SDLOPATH=SDL/build
NETWORKINGOBJECTS= netutil.o $(PROTO_OBJECTS)
# PROFILE=-pg
PROFILE=
OPT=-O2
INCLUDES=-I "../cc-lib" -I "../cc-lib/city"
CPPFLAGS= $(CCNETWORKING) -DPSS_STYLE=1 -DDUMMY_UI -DHAVE_ASPRINTF -Wno-write-strings -m64 $(OPT) -DHAVE_ALLOCA -DNOWINSTUFF $(INCLUDES) $(PROFILE) $(FLTO)
CCLIBOBJECTS=../cc-lib/util.o ../cc-lib/arcfour.o ../cc-lib/base/stringprintf.o ../cc-lib/city/city.o ../cc-lib/textsvg.o
MAPPEROBJECTS=fceu/mappers/24and26.o fceu/mappers/51.o fceu/mappers/69.o fceu/mappers/77.o fceu/mappers/40.o fceu/mappers/6.o fceu/mappers/71.o fceu/mappers/79.o fceu/mappers/41.o fceu/mappers/61.o fceu/mappers/72.o fceu/mappers/80.o fceu/mappers/42.o fceu/mappers/62.o fceu/mappers/73.o fceu/mappers/85.o fceu/mappers/46.o fceu/mappers/65.o fceu/mappers/75.o fceu/mappers/emu2413.o fceu/mappers/50.o fceu/mappers/67.o fceu/mappers/76.o fceu/mappers/mmc2and4.o
# utils/unzip.o removed -- needs lz
UTILSOBJECTS=fceu/utils/ConvertUTF.o fceu/utils/general.o fceu/utils/memory.o fceu/utils/crc32.o fceu/utils/guid.o fceu/utils/endian.o fceu/utils/md5.o fceu/utils/xstring.o fceu/utils/unzip.o
# main binary
# PALETTESOBJECTS=palettes/conv.o
BOARDSOBJECTS=fceu/boards/01-222.o fceu/boards/32.o fceu/boards/gs-2013.o fceu/boards/103.o fceu/boards/33.o fceu/boards/h2288.o fceu/boards/106.o fceu/boards/34.o fceu/boards/karaoke.o fceu/boards/108.o fceu/boards/3d-block.o fceu/boards/kof97.o fceu/boards/112.o fceu/boards/411120-c.o fceu/boards/konami-qtai.o fceu/boards/116.o fceu/boards/43.o fceu/boards/ks7012.o fceu/boards/117.o fceu/boards/57.o fceu/boards/ks7013.o fceu/boards/120.o fceu/boards/603-5052.o fceu/boards/ks7017.o fceu/boards/121.o fceu/boards/68.o fceu/boards/ks7030.o fceu/boards/12in1.o fceu/boards/8157.o fceu/boards/ks7031.o fceu/boards/15.o fceu/boards/82.o fceu/boards/ks7032.o fceu/boards/151.o fceu/boards/8237.o fceu/boards/ks7037.o fceu/boards/156.o fceu/boards/830118C.o fceu/boards/ks7057.o fceu/boards/164.o fceu/boards/88.o fceu/boards/le05.o fceu/boards/168.o fceu/boards/90.o fceu/boards/lh32.o fceu/boards/17.o fceu/boards/91.o fceu/boards/lh53.o fceu/boards/170.o fceu/boards/95.o fceu/boards/malee.o fceu/boards/175.o fceu/boards/96.o fceu/boards/mmc1.o fceu/boards/176.o fceu/boards/99.o fceu/boards/mmc3.o fceu/boards/177.o fceu/boards/__dummy_mapper.o fceu/boards/mmc5.o fceu/boards/178.o fceu/boards/a9711.o fceu/boards/n-c22m.o fceu/boards/179.o fceu/boards/a9746.o fceu/boards/n106.o fceu/boards/18.o fceu/boards/ac-08.o fceu/boards/n625092.o fceu/boards/183.o fceu/boards/addrlatch.o fceu/boards/novel.o fceu/boards/185.o fceu/boards/ax5705.o fceu/boards/onebus.o fceu/boards/186.o fceu/boards/bandai.o fceu/boards/pec-586.o fceu/boards/187.o fceu/boards/bb.o fceu/boards/sa-9602b.o fceu/boards/189.o fceu/boards/bmc13in1jy110.o fceu/boards/sachen.o fceu/boards/193.o fceu/boards/bmc42in1r.o fceu/boards/sc-127.o fceu/boards/199.o fceu/boards/bmc64in1nr.o fceu/boards/sheroes.o fceu/boards/208.o fceu/boards/bmc70in1.o fceu/boards/sl1632.o fceu/boards/222.o fceu/boards/bonza.o fceu/boards/smb2j.o fceu/boards/225.o fceu/boards/bs-5.o fceu/boards/subor.o fceu/boards/228.o fceu/boards/cityfighter.o fceu/boards/super24.o fceu/boards/230.o fceu/boards/dance2000.o fceu/boards/supervision.o fceu/boards/232.o fceu/boards/datalatch.o fceu/boards/t-227-1.o fceu/boards/234.o fceu/boards/deirom.o fceu/boards/t-262.o fceu/boards/235.o fceu/boards/dream.o fceu/boards/tengen.o fceu/boards/244.o fceu/boards/edu2000.o fceu/boards/tf-1201.o fceu/boards/246.o fceu/boards/famicombox.o fceu/boards/transformer.o fceu/boards/252.o fceu/boards/fk23c.o fceu/boards/vrc2and4.o fceu/boards/253.o fceu/boards/ghostbusters63in1.o fceu/boards/vrc7.o fceu/boards/28.o fceu/boards/gs-2004.o fceu/boards/yoko.o
INPUTOBJECTS=fceu/input/arkanoid.o fceu/input/ftrainer.o fceu/input/oekakids.o fceu/input/suborkb.o fceu/input/bworld.o fceu/input/hypershot.o fceu/input/powerpad.o fceu/input/toprider.o fceu/input/cursor.o fceu/input/mahjong.o fceu/input/quiz.o fceu/input/zapper.o fceu/input/fkb.o fceu/input/mouse.o fceu/input/shadow.o
FCEUOBJECTS=fceu/asm.o fceu/cart.o fceu/cheat.o fceu/conddebug.o fceu/config.o fceu/debug.o fceu/drawing.o fceu/emufile.o fceu/fceu.o fceu/fds.o fceu/file.o fceu/filter.o fceu/ines.o fceu/input.o fceu/movie.o fceu/netplay.o fceu/nsf.o fceu/oldmovie.o fceu/palette.o fceu/ppu.o fceu/sound.o fceu/state.o fceu/unif.o fceu/video.o fceu/vsuni.o fceu/wave.o fceu/x6502.o
# fceu/drivers/common/config.o fceu/drivers/common/configSys.o
DRIVERS_COMMON_OBJECTS=fceu/drivers/common/args.o fceu/drivers/common/nes_ntsc.o fceu/drivers/common/cheat.o fceu/drivers/common/scale2x.o fceu/drivers/common/scale3x.o fceu/drivers/common/scalebit.o fceu/drivers/common/hq2x.o fceu/drivers/common/vidblit.o fceu/drivers/common/hq3x.o
EMUOBJECTS=$(FCEUOBJECTS) $(MAPPEROBJECTS) $(UTILSOBJECTS) $(PALLETESOBJECTS) $(BOARDSOBJECTS) $(INPUTOBJECTS) $(DRIVERS_COMMON_OBJECTS)
#included in all tests, etc.
BASEOBJECTS=$(CCLIBOBJECTS) $(NETWORKINGOBJECTS) $(PROTOBUFOBJECTS)
TASBOT_OBJECTS=headless-driver.o config.o simplefm2.o emulator.o basis-util.o objective.o weighted-objectives.o motifs.o util.o
OBJECTS=$(BASEOBJECTS) $(EMUOBJECTS) $(TASBOT_OBJECTS)
%.pb.cc: %.proto
$(PROTOC) $< --cpp_out=.
%.pb.h: %.proto
$(PROTOC) $< --cpp_out=.
# without static, can't find lz or lstdcxx maybe?
#LFLAGS = -m64 -Wl,--subsystem,console $(LINKNETWORKING) -lz $(OPT) $(FLTO) $(PROFILE) -static
LFLAGS = -m64 -Wl,--verbose $(LINKNETWORKING) -lz $(OPT) $(FLTO) $(PROFILE) -static
# -Wl,--subsystem,console
# -static -fwhole-program
# -static
learnfun : $(OBJECTS) learnfun.o
$(CXX) $^ -o $# $(LFLAGS)
# XXX never implemented this.
showfun : $(OBJECTS) showfun.o
$(CXX) $^ -o $# $(LFLAGS)
tasbot : $(OBJECTS) tasbot.o
$(CXX) $^ -o $# $(LFLAGS)
playfun : $(OBJECTS) playfun.o
$(CXX) $^ -o $# $(LFLAGS)
emu_test : $(OBJECTS) emu_test.o
$(CXX) $^ -o $# $(LFLAGS)
objective_test : $(BASEOBJECTS) objective.o objective_test.o
$(CXX) $^ -o $# $(LFLAGS)
weighted-objectives_test : $(BASEOBJECTS) weighted-objectives.o weighted-objectives_test.o util.o
$(CXX) $^ -o $# $(LFLAGS)
test : emu_test objective_test weighted-objectives_test
time ./emu_test
time ./objective_test
time ./weighted-objectives_test
clean :
rm -f learnfun playfun showfun *_test *.o $(EMUOBJECTS) $(CCLIBOBJECTS) gmon.out
veryclean : clean cleantas
cleantas :
rm -f prog*.fm2 deepest.fm2 heuristicest.fm2
First, I don't know why you have -l:libprotobuf.so here:
LINKNETWORKING= $(LINKSDL) -l:libprotobuf.so -lpthread
Shouldn't that just be -lprotobuf ?
Second, you have added the -static flag to your link line, which means your application will try to link statically. That's why it's looking for libprotobuf.a, a static library. But, as you show in your list of files, you don't have a static version of the protobuf library installed, only shared libraries.

Resources