C++ makefile will compile only first 3 entries - c++

Good day,
recently i switched from jamfile to makefile. The reason of this switch is that i think that jamfile does not really cooperate with armadillo and openmp libraries. I have code divided into multiple *.h and *.cpp files.
# makefile for my PhD thesis
# Created by Michal Buday, no copyrights
# Datum: 01.07.2016
SHELL := /bin/sh
SRC := methods
BIN := bin
CXX := g++ # GNU C++ compiler
CXXFLAGS := -Wall
ARMAF := -larmadillo # ARMADILLO matrix library
OPT := -O
# GGG := -g # for debugging
# bash$ gdp ${program name} core
# ===============================================================================================
# standard stuff
all: coord_trans.o geodetic_functions.o geo_models.o interpolations.o \
legendre.o loadpoints.o physical_constants.o sphere_int.o \
3Dtransformations.o
LIBOBJ = coord_trans.o geodetic_functions.o geo_models.o interpolations.o \
legendre.o loadpoints.o physical_constants.o sphere_int.o \
3Dtransformations.o #topo_corrections.o
geodetic_functions.o: $(SRC)/geodetic_functions.h
$(CXX) $(OPT) -c $(SRC)/geodetic_functions.h -o $(BIN)/$#
geo_models.o: $(SRC)/geo_models.h $(SRC)/legendre.h $(SRC)/geodetic_functions.h \
$(SRC)/physical_constants.h
$(CXX) $(OPT) -c $(SRC)/geo_models.h -o $(BIN)/$#
interpolations.o: $(SRC)/interpolations.cpp $(SRC)/interpolations.h
$(CXX) $(OPT) -c $(SRC)/interpolations.cpp -o $(BIN)/$#
legendre.o: $(SRC)/legendre.h
$(CXX) $(OPT) -c $(SRC)/legendre.h -o $(BIN)/$#
loadpoints.o: $(SRC)/loadpoints.h
$(CXX) $(OPT) -c $(SRC)/loadpoints.h -o $(BIN)/$#
sphere_int.o: $(SRC)/sphere_int.h $(SRC)/sphere_int.cpp
$(CXX) $(OPT) -c $(SRC)/sphere_int.cpp $(ARMAF) -o $(BIN)/$#
#topo_corrections.o: $(SRC)/topo_corrections.h $(SRC)/geodetic_functions.h
# $(CXX) $(OPT) -c $(SRC)/topo_corrections.h $(ARMAF)
3Dtransformations.o: $(SRC)/3Dtransformations.h $(SRC)/3Dtransformations.cpp
$(CXX) $(OPT) -c $(SRC)/3Dtransformations.cpp $(ARMAF) -o $(BIN)/$#
coord_trans.o: $(SRC)/coord_trans.h $(SRC)/geodetic_functions.h
$(CXX) $(OPT) -c $(SRC)/coord_trans.h -o $(BIN)/$#
main.o: $(LIBOBJ)
$(CXX) $(OPT) $(BIN)/$(LIBOBJ) -o $# $(ARMAF)
# ======================================================================== #
#
clean:
rm *.o
The dependencies are:
# coord_trans.h << geodetic_functions.h
# geodetic_functions.h << armadillo
# geo_models.h << legendre.h geodetic_functions.h physical_constants.h
# interpolations.h << std
# legendre.h << std
# loadpoints.h << std
# physical_constants.h << define only
# sphere_int.h << armadillo
# topo_corrections.h << geodetic_functions.h
# 3Dtransformations.h << armadillo
But when i call
make
in terminal it creates only the first 3 entries in makefile and also the size of binary files is over 107 MB (the code itself has 100k or less). What am i missing?
Thank you for any advices.

First of all, you may want to use $< (first dependancie) for your -c argument instead of repeating it.
Also, I would advise to build the list of object files given the cpp files (wildcard function?).
Finally, you may want to try to replace $(BIN)/$(LIBOBJ) by $(FULLPATH_LIBOBJ) constructed using:
FULLPATH_LIBOBJ = $(addprefix $(BIN)/, $(LIBOBJ))
Not sure this changes anything, but your makefile looks complicated to me, whereas it should be much simpler!
Also, it is hard to help you compiling the project without the project itself.

Related

ERROR: packagename-0.1-r0 do_compile: Function failed: do_compile

I am working on IMX7(Phytec zeta board) with yocto linux. On already working helloworld recipe(named as imx7-2110) I added some application source files(C, C++, h, hpp), created a make file and edited .bb files accordingly. on compilation I am getting error that one of the .hpp file(PktDriverAbstractionLayer.hpp) is not found, although it present in source directory and corresponding path is given to .bb file.
What could be the reason? I tried some suggestion available on internet forums but it didn't help.
Details of error are here:
[root#localhost build]# bitbake imx7-2110
Loading cache: 100% |###########################################| ETA:
00:00:00
Loaded 2800 entries from dependency cache.
Parsing recipes: 100% |#########################################| Time:
00:00:00
Parsing of 2223 .bb files complete (2222 cached, 1 parsed). 2799 targets,
220 skipped, 5 masked, 0 errors.
WARNING: No bb files matched BBFILE_PATTERN_phytec '^/opt/PHYTEC_BSPs
/yocto_imx7/sources/meta-phytec/common/'
NOTE: Resolving any missing task queue dependencies
Build Configuration:
BB_VERSION = "1.30.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "CentOSLinux-7.4.1708"
TARGET_SYS = "arm-poky-linux-gnueabi"
MACHINE = "imx7d-phyboard-zeta-001"
DISTRO = "fsl-imx-x11"
DISTRO_VERSION = "4.1.15-2.0.1"
TUNE_FEATURES = "arm armv7ve vfp neon callconvention-hard
cortexa7"
TARGET_FPU = "hard"
meta
meta-yocto = "HEAD:f5da2a5913319ad6ac2141438ba1aa17576326ab"
meta-oe
meta-multimedia = "HEAD:247b1267bbe95719cd4877d2d3cfbaf2a2f4865a"
meta-fsl-arm = "HEAD:be78894e4682f111575470fb23e51e6ba523508d"
meta-fsl-arm-extra = "HEAD:3dfb82fc7e703eae9891b3ffda0e9393701f2396"
meta-fsl-demos = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
meta-bsp
meta-sdk = "HEAD:90399d99af8a2660ebe50b49752e95b210239fd9"
meta-browser = "HEAD:77736988073a5d90fcff9d0005c8477332ede387"
meta-gnome
meta-networking
meta-python
meta-filesystems = "HEAD:247b1267bbe95719cd4877d2d3cfbaf2a2f4865a"
meta-qt5 = "HEAD:ccae79be69c5268df3b47e4e14cea0591c39a531"
meta-phytec
meta-phytec-fsl = "HEAD:0b1de01225a2ec0debf71eb13be403baa9f4919f"
meta-imx7-2110 = "<unknown>:<unknown>"
NOTE: Preparing RunQueue
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: imx7-2110-0.1-r0 do_compile: Function failed: do_compile (log file
is located at /opt/PHYTEC_BSPs/yocto_imx7/build/tmp/work/cortexa7hf-
neon-poky-linux-gnueabi/imx7-2110/0.1-r0/temp/log.do_compile.7235)
ERROR: Logfile of failure stored in: /opt/PHYTEC_BSPs/yocto_imx7/build
/tmp/work/cortexa7hf-neon-poky-linux-gnueabi/imx7-2110/0.1-r0
/temp/log.do_compile.7235
Log data follows:
| DEBUG: Executing shell function do_compile
| arm-poky-linux-gnueabi-g++ -march=armv7ve -mfpu=neon -mfloat-abi=hard
-mcpu=cortex-a7 --sysroot=/opt/PHYTEC_BSPs/yocto_imx7/build/tmp/sysroots
/imx7d-phyboard-zeta-001 -c -pthread -std=c++11 -O2 -pipe -g
-feliminate-unused-debug-types -fdebug-prefix-map=/opt/PHYTEC_BSPs
/yocto_imx7/build/tmp/work/cortexa7hf-neon-poky-linux-gnueabi/imx7-2110
/0.1-r0=/usr/src/debug/imx7-2110/0.1-r0 -fdebug-prefix-map=/opt
/PHYTEC_BSPs/yocto_imx7/build/tmp/sysroots/x86_64-linux= -fdebug-prefix-
map=/opt/PHYTEC_BSPs/yocto_imx7/build/tmp/sysroots/imx7d-phyboard-
zeta-001= -fvisibility-inlines-hidden -g -c -Wall -Wextra -pthread
-std=c++0x pcieman_client.cpp -o pcieman_client.o
| In file included from pcieman_client.cpp:45:0:
| PktDriverUDPManager.hpp:18:41: fatal error:
PktDriverAbstractionLayer.hpp: No such file or directory
| compilation terminated.
| make: *** [pcieman_client.o] Error 1
| WARNING: /opt/PHYTEC_BSPs/yocto_imx7/build/tmp/work/cortexa7hf-
neon-poky-linux-gnueabi/imx7-2110/0.1-r0/temp/run.do_compile.7235:1 exit 2
from 'make'
| ERROR: Function failed: do_compile (log file is located at
/opt/PHYTEC_BSPs/yocto_imx7/build/tmp/work/cortexa7hf-neon-poky-linux-
gnueabi/imx7-2110/0.1-r0/temp/log.do_compile.7235)
ERROR: Task 6 (/opt/PHYTEC_BSPs/yocto_imx7/sources/meta-imx7-2110/recipes-
example/example/imx7-2110_0.1.bb, do_compile) failed with exit code '1'
NOTE: Tasks Summary: Attempted 351 tasks of which 346 didn't need to be
rerun and 1 failed.
No currently running tasks (351 of 358)
Summary: 1 task failed:
/opt/PHYTEC_BSPs/yocto_imx7/sources/meta-imx7-2110/recipes-example
/example/imx7-2110_0.1.bb, do_compile
Summary: There was 1 WARNING message shown.
Summary: There was 1 ERROR message shown, returning a non-zero exit code.
[root#localhost build]#
Update with recipe:
#
# This file was derived from the 'Hello World!' example recipe in the
# Yocto Project Development Manual.
#
SUMMARY = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}
/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://build/build.tar.gz \
file://src/src.tar.gz \
file://include/include.tar.gz \
file://xpcie.h \
"
S = "${WORKDIR}"
#EXTRA_OEMAKE += "CPPFLAGS='-c -pthread -std=c++11'"
#EXTRA_OEMAKE += "CXXFLAGS='-g -c -Wall -Wextra -pthread -std=c++0x'"
do_compile() {
make
}
do_install() {
install -d ${D}${bindir}
install -m 0755 pcieman_client ${D}${bindir}
}
Here is also make with supplementary Info:
# Define Compiler to use
CC=g++
# Define default compiler options
# Flags passed to the preprocessor.
CPPFLAGS=-c -pthread -std=c++11
CXXFLAGS += -g -c -Wall -Wextra -pthread -std=c++0x
LFLAGS=-Bsymbolic
all: pcieman_client
pcieman_client: pcieman_client.o parser.o udp_socket_class.o
ds_api_class.o syn1588_class.o tr03_class.o pio_class.o search_api_class.o
packet_proc_class.o socket_tools.o crc_calc.o stdafx.o transaction_class.o
lpq_api_class.o fileIn_class.o vip_Rx_udp.o vip_Tx_udp.o
PktDriverAbstractionLayer.o PktDriverUDPManager.o StateMachine.o
MessageEvent.o appl_menu.o
$(CC) $(LFLAGS) -lpthread pcieman_client.o parser.o udp_socket_class.o
ds_api_class.o syn1588_class.o tr03_class.o pio_class.o search_api_class.o
packet_proc_class.o socket_tools.o crc_calc.o stdafx.o transaction_class.o
lpq_api_class.o fileIn_class.o vip_Rx_udp.o vip_Tx_udp.o
PktDriverAbstractionLayer.o PktDriverUDPManager.o StateMachine.o
appl_menu.o MessageEvent.o -o pcieman_client
pcieman_client.o: version.h udp_socket_class.h socket_tools.h
packet_proc_class.h transaction_class.h parser_params.h parser.h
pcieman_client.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) pcieman_client.cpp -o pcieman_client.o
udp_socket_class.o: udp_socket_class.h udp_socket_class.cpp
$(CC) $(CPPFLAGS) udp_socket_class.cpp -o udp_socket_class.o
appl_menu.o: appl_menu.hpp appl_menu.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) appl_menu.cpp -o appl_menu.o
ds_api_class.o: ds_api_class.h ds_api_class.cpp
$(CC) $(CPPFLAGS) ds_api_class.cpp -o ds_api_class.o
search_api_class.o: crc_calc.h search_api_class.h search_api_class.cpp
$(CC) $(CPPFLAGS) search_api_class.cpp -o search_api_class.o
pio_class.o: crc_calc.h pio_class.h pio_class.cpp
$(CC) $(CPPFLAGS) pio_class.cpp -o pio_class.o
syn1588_class.o: RxTx_settings.h syn1588_class.h syn1588_class.cpp
$(CC) $(CPPFLAGS) syn1588_class.cpp -o syn1588_class.o
tr03_class.o: RxTx_settings.h tr03_class.h tr03_class.cpp
$(CC) $(CPPFLAGS) tr03_class.cpp -o tr03_class.o
packet_proc_class.o: packet_proc_class.h packet_proc_class.cpp
$(CC) $(CPPFLAGS) packet_proc_class.cpp -o packet_proc_class.o
socket_tools.o: socket_tools.h socket_tools.cpp
$(CC) $(CPPFLAGS) socket_tools.cpp -o socket_tools.o
crc_calc.o: crc_calc.h crc_calc.cpp
$(CC) $(CPPFLAGS) crc_calc.cpp -o crc_calc.o
stdafx.o: stdafx.h stdafx.cpp
$(CC) $(CPPFLAGS) stdafx.cpp -o stdafx.o
transaction_class.o: packet_proc_class.h transaction_class.h
transaction_class.cpp
$(CC) $(CPPFLAGS) transaction_class.cpp -o transaction_class.o
lpq_api_class.o: lpq_api_class.h lpq_api_class.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) lpq_api_class.cpp -o lpq_api_class.o
fileIn_class.o: fileIn_class.h fileIn_class.cpp
$(CC) $(CPPFLAGS) fileIn_class.cpp -o fileIn_class.o
vip_Rx_udp.o: vip_Rx_settings.h RxTx_settings.h ds_api_class.h
syn1588_class.h tr03_class.h pio_class.h lpq_api_class.h
search_api_class.h PktDriverUDPManager.hpp vip_Rx_udp.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) vip_Rx_udp.cpp -o vip_Rx_udp.o
vip_Tx_udp.o: vip_Tx_settings.h RxTx_settings.h PktDriverUDPManager.hpp
vip_Tx_udp.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS)vip_Tx_udp.cpp -o vip_Tx_udp.o
parser.o: parser_params.h parser.h parser.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) parser.cpp -o parser.o
IGMPTimerManager.o: IGMPTimerManager.hpp IGMPTimerManager.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) IGMPTimerManager.cpp -o IGMPTimerManager.o
IGMPManager.o: IGMPManager.hpp IGMPManager.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) IGMPManager.cpp -o IGMPManager.o
IGMPNetworkManager.o: IGMPNetworkManager.hpp IGMPNetworkManager.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) IGMPNetworkManager.cpp -o
IGMPNetworkManager.o
IGMPHostEvent.o: IGMPHostEvent.hpp IGMPHostEvent.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) IGMPHostEvent.cpp -o IGMPHostEvent.o
IGMPMulticastHost.o: IGMPMulticastHost.hpp IGMPStateMachine.hpp
IGMPMulticastHost.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) IGMPMulticastHost.cpp -o
IGMPMulticastHost.o
StateMachine.o: StateMachine.hpp StateMachine.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) StateMachine.cpp -o StateMachine.o
MessageEvent.o: MessageEvent.hpp MessageEvent.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) MessageEvent.cpp -o MessageEvent.o
IGMPV2StateMachine.o: IGMPStateMachine.hpp IGMPV2StateMachine.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) IGMPV2StateMachine.cpp -o
IGMPV2StateMachine.o
IGMPV3StateMachine.o: IGMPStateMachine.hpp IGMPV3StateMachine.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) IGMPV3StateMachine.cpp -o
IGMPV3StateMachine.o
IGMPStateMachine.o: IGMPStateMachine.hpp IGMPStateMachine.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) IGMPStateMachine.cpp -o IGMPStateMachine.o
PktDriverAbstractionLayer.o: PktDriverAbstractionLayer.hpp
PktDriverAbstractionLayer.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) PktDriverAbstractionLayer.cpp -o
PktDriverAbstractionLayer.o
PktDriverUDPManager.o: PktDriverUDPManager.hpp PktDriverUDPManager.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) PktDriverUDPManager.cpp -o
PktDriverUDPManager.o
clean:
rm -rf *.o pcieman_client
configuration file local.conf is here:
MACHINE ??= 'imx7d-phyboard-zeta-001'
DISTRO ?= 'fsl-imx-x11'
PACKAGE_CLASSES ?= "package_rpm"
EXTRA_IMAGE_FEATURES = "debug-tweaks"
IMAGE_INSTALL_append=" xyzlayer"
IMAGE_INSTALL +="boost"
USER_CLASSES ?= "buildstats image-mklibs phytec-mirrors"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS = "\
STOPTASKS,${TMPDIR},1G,100K \
STOPTASKS,${DL_DIR},1G,100K \
STOPTASKS,${SSTATE_DIR},1G,100K \
STOPTASKS,/tmp,100M,100K \
ABORT,${TMPDIR},100M,1K \
ABORT,${DL_DIR},100M,1K \
ABORT,${SSTATE_DIR},100M,1K \
ABORT,/tmp,10M,1K"
PACKAGECONFIG_append_pn-qemu-native = " sdl"
PACKAGECONFIG_append_pn-nativesdk-qemu = " sdl"
ASSUME_PROVIDED += "libsdl-native"
CONF_VERSION = "1"
BB_NUMBER_THREADS = "8"
PARALLEL_MAKE = "-j 4"
DL_DIR ?= "/opt/PHYTEC_BSPs/yocto_dl"
ACCEPT_FSL_EULA = "1"
bblayer file bblayers.conf is here:
# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BSPDIR := "${#os.path.abspath(os.path.dirname(d.getVar('FILE', True)) +
'/../..')}"
BBFILES ?= ""
BBLAYERS = " \
${BSPDIR}/sources/poky/meta \
${BSPDIR}/sources/poky/meta-poky \
\
${BSPDIR}/sources/meta-openembedded/meta-oe \
${BSPDIR}/sources/meta-openembedded/meta-multimedia \
\
${BSPDIR}/sources/meta-fsl-arm \
${BSPDIR}/sources/meta-fsl-arm-extra \
${BSPDIR}/sources/meta-fsl-demos \
${BSPDIR}/sources/meta-fsl-bsp-release/imx/meta-bsp \
${BSPDIR}/sources/meta-fsl-bsp-release/imx/meta-sdk \
\
${BSPDIR}/sources/meta-browser \
${BSPDIR}/sources/meta-openembedded/meta-gnome \
${BSPDIR}/sources/meta-openembedded/meta-networking \
${BSPDIR}/sources/meta-openembedded/meta-python \
${BSPDIR}/sources/meta-openembedded/meta-filesystems \
${BSPDIR}/sources/meta-qt5 \
\
${BSPDIR}/sources/meta-phytec \
${BSPDIR}/sources/meta-phytec/meta-phytec-fsl \
${BSPDIR}/sources/meta-xyzlayer \
${BSPDIR}/sources/meta-testlayer \
"
What I see missing in the arm-poky-linux-gnueabi-g++ command line is the "-I" option for include path. Since the bitbake environment variables override the Makefile variables, it maybe required to explicitly specify the include paths using the following (in your recipe file before the do_compile() task):
TARGET_CFLAGS += " -I${S}"
Assuming that the header files are in the same folder as the source files.

How to write make files with auto dependancy generator

In expansion to my previous question how to write a makefile for structured file system:
The file structure:
.
├── Headers
│   ├── function.h
│   └── test.h
├── makefile
├── README.md
└── Sources
├── function.c
├── main.c
└── test.c
I'm trying to write a makefile that reads the #include<...> on any given source file and compile as required.
Originally I used to have a make file that looked like this:
INC_DIR = Headers
SRC_DIR = Sources
OBJ_DIR = Objects
#CXXFLAGS = -c -Wall -I. -IHeaders
CXXFLAGS = -c -Wall -I. -IHeaders
CC = gcc
SRCS = $(SRC_DIR)/*.c
OBJS = $(OBJ_DIR)/*.o
#The wildcard and patsubt commads will come handy
DEPS = $(INC_DIR)/*.h
#need to use an automatic dependency generator
output: $(OBJ_DIR)/main.o $(OBJ_DIR)/function.o
$(CC) $^ -o $#
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(DEPS)
$(CC) $(CXXFLAGS) $< -o $#
run: output
./output
clean:
rm $(OBJ_DIR)/*.o
rm output
-#echo "Clean completed"
That meant that for every source file that output was dependent on i had to add that object to this line.
output: $(OBJ_DIR)/main.o $(OBJ_DIR)/function.o $(OBJ_DIR)/test.o
$(CC) $^ -o $#
And is any other source file was dependent on one or more sources additional rules had to be added.
To solve this:
here is what I have gathered from Auto-Dependency Generation and 4.14 Generating Prerequisites Automatically
As mentioned by the community members, I have a mixed understanding of dependency generation and how to make use of the files generated.
DEP_DIR = .d
$(shell mkdir -p $(DEP_DIR) >/dev/null)
DEPFLAGS = -MT $# -MMD -MP -MF $(DEP_DIR)/$*.Td
INC_DIR = Headers
SRC_DIR = Sources
OBJ_DIR = Objects
$(shell mkdir -p $(OBJ_DIR) >/dev/null)
CXXFLAGS = -c -Wall -I. -IHeaders
CC = gcc
SRCS = $(SRC_DIR)/*.c
OBJS = $(OBJ_DIR)/*.o
#The wildcard and patsubt commads will come handy
#DEPS = $(INC_DIR)/*.h
MAKEDEPEND = $(CC) $(CXXFLAGS) $< \
| sed -n 's/^\# *[0-9][0-9]* *"\([^"]*\)".*/$*.o: \1/p' \
| sort | uniq > $*.Td
COMPILE.c = $(CC) $(DEPFLAGS) $(CXXFLAGS)
#need to use an automatic dependency generator
#%.d: %.c
# #set -e; rm -f $#; \
# $(CC) -MP -MD $(CXXFLAGS) $< > $#.$$$$; \
# sed 's,\($*\)\.o[ :]*,\1.o $# : ,g' < $#.$$$$ > $#; \
# rm -f $#.$$$$
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(DEP_DIR)/%.d
#$(MAKEDEPEND); \
cp $*.Td $*.d; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $*.Td >> $*.d; \
rm -f $*.Td
#$(COMPILE.c) -o $# $<
$(CC) $(CXXFLAGS) $(DEPFLAGS) $< -o $#
-include $(SRCS:.c=.d)
$(DEP_DIR)/%.d: ;
.PRECIOUS: $(DEP_DIR)/%.d
output: $(OBJS)
$(CC) $^ -o $#
run: output
./output
clean:
rm -r $(OBJ_DIR)
rm -r $(DEP_DIR)
rm output
-#echo "Clean completed"
The error when make is executed is:
$ make
gcc -c -Wall -I. -IHeaders -MT Objects/*.o -MMD -MP -MF .d/*.Td Sources/function.c -o Objects/*.o
gcc Objects/*.o -o output
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
makefile:48: recipe for target 'output' failed
make: *** [output] Error 1
So, I'm hoping to achieve the auto dependency detection and compilation. I think the error is in the way that the dependencies are detected and the way they are generated for a given source file.
It looks to me like you're trying to combine multiple different ways of generating dependency info, and that can't work. The advanced post talks about multiple ways to solve the problem: you need to pick one not try to use them all together.
If you want to use the advanced method then use it as described in the "TL;DR" section at the top, or else in the "Combining Compilation and Dependency Generation" section at the bottom. If you're using GCC there's no need for MAKEDEPEND, sed, etc.
The advanced post says that your rule should look like this:
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
%.o : %.c
%.o : %.c $(DEPDIR)/%.d
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(POSTCOMPILE)
That's it.

CMake compile-time defines

I am new to using CMake and am attempting to transfer our previous Makefiles into CMakeLists. I have one file, *dsplink_defines.txt* that has the following compile-time defines.
*-DOS_LINUX -DMAX_DSPS=1 -DMAX_PROCESSORS=2 -DID_GPP=1 -DOMAPL1XX -DPROC_COMPONENT -DPOOL_COMPONENT -DNOTIFY_COMPONENT -DMPCS_COMPONENT -DRINGIO_COMPONENT -DMPLIST_COMPONENT -DMSGQ_COMPONENT -DMSGQ_ZCPY_LINK -DCHNL_COMPONENT -DCHNL_ZCPY_LINK -DZCPY_LINK -DKFILE_DEFAULT -DDA8XXGEM -DDA8XXGEM_PHYINTERFACE=SHMEM_INTERFACE -DGPP_SWI_MODE -D_REENTRANT -DVERIFY_DATA -DDDSP_DEBUG*
Our previous Makefile took care of this in the following manner and took care of this by using shell cat starting on line 8:
BIN = ../../build/bin
TMP = build
BUILD_DEF = -DBUILD=$(BUILD_VERSION) -DBUILD_DATE=$(BUILD_DATE)
# these files are captured from the DSPLink Sample build directory (and the named changed)
# they contain the appropriate includes and flags to build a dsplink application.
DSPLINK_INCLUDES = $(shell cat ../dsplink_config/dsplink_includes.txt)
DSPLINK_FLAGS = $(shell cat ../dsplink_config/dsplink_flags.txt)
DSPLINK_DEFINES = $(shell cat ../dsplink_config/dsplink_defines.txt)
DSPLINK_LIBS = $(DSPLINK_PACKAGE_DIR)/dsplink/gpp/export/BIN/Linux/OMAPL1XX/RELEASE/dsplink.lib
#Our project variables
INCLUDE = -I../framework -I../io_master -I../logging -I../../dsp/include - I../flagDictionary
#TOOLCHAIN = ${FACTORY_DIR}/build_armv5l-timesys-linux-uclibcgnueabi/toolchain/bin
TOOLCHAIN = /OMAP-L137/timesys/SDK/omapl137_evm/toolchain/bin
PLATFORM=armv5l-timesys-linux-uclibcgnueabi
#Compile Options
CC=$(TOOLCHAIN)/$(PLATFORM)-g++
LINKER=$(TOOLCHAIN)/$(PLATFORM)-g++
CFLAGS+= $(BUILD_DEF) $(INCLUDE) $(DSPLINK_DEFINES) $(DSPLINK_FLAGS) $(DSPLINK_INCLUDES)
DEBUG = -O
#list of things to compile.
FW_BUILD_DIR=../framework/build
LOG_BUILD_DIR=../logging/build
FLAG_DICT_BUILD_DIR=../flagDictionary/build
FRAMEWORK_OBJECTS= $(FW_BUILD_DIR)/com.o \
$(FW_BUILD_DIR)/application.o \
$(FW_BUILD_DIR)/memoryManagerBase.o \
$(FW_BUILD_DIR)/memoryManager.o \
$(FW_BUILD_DIR)/arguments.o \
$(FW_BUILD_DIR)/lockManager.o \
$(FW_BUILD_DIR)/controlCom.o \
$(FW_BUILD_DIR)/paths.o \
$(LOG_BUILD_DIR)/subsystemLogMasks.o \
$(LOG_BUILD_DIR)/logger.o
FLAG_DICT_OBJECTS= $(FLAG_DICT_BUILD_DIR)/flagEntry.o \
$(FLAG_DICT_BUILD_DIR)/flagDictionary.o
OBJECTS = spidev_test.o sysMon.o
EXES = sysMon
all: $(OBJECTS) $(EXES)
.c.o:
mkdir -p build
$(CC) -c $(CFLAGS) $(DEBUG) -o $(TMP)/$# $<
.cpp.o:
mkdir -p build
$(CC) -c $(CFLAGS) $(DEBUG) -o $(TMP)/$# $<
spidev_test: $(FRAMEWORK_OBJECTS) spidev_test.o
$(LINKER) -lpthread -lc -o $(BIN)/$# $(DSPLINK_LIBS) build/spidev_test.o $(FRAMEWORK_OBJECTS)
sysMon: $(FRAMEWORK_OBJECTS) sysMon.o
$(LINKER) -lpthread -lc -o $(BIN)/$# $(DSPLINK_LIBS) build/sysMon.o $(FLAG_DICT_OBJECTS) $(FRAMEWORK_OBJECTS)
deploy:
../../build/deploy
How do I pass these in using a CMakeList
This should work:
file(READ path/to/dsplink_defines.txt defines) #read file into variable 'defines'
string(REPLACE " " ";" defines "${defines}") #turn space separation into CMake list
add_definitions(${defines})
Of course, if you have full control of the file and can change its format to use semicolons for separation instead of spaces, you can do that and skip the string() line (probably speeding up your CMake processing a little bit by this).

No rule to make target ***

I am currently trying to build Face Tracker (by Jason Saragih) with "make" in my Windows 7 x64, but all I'm getting is: "No rule to make target src/lib/IO.o, needed by bin/face_tracker".
Does anyone have any idea of what is happening, please?
This is the makefile (also available in Jason Saragih's page):
# Paths
OPENCV_PATH=/OpenCV246/
# Programs
CC=
CXX=g++
# Flags
ARCH_FLAGS=-arch x86_64
CFLAGS=-Wextra -Wall -pedantic-errors $(ARCH_FLAGS) -O3
LDFLAGS=$(ARCH_FLAGS)
DEFINES=
INCLUDES=-I$(OPENCV_PATH)/include -Iinclude/
LIBRARIES=-L$(OPENCV_PATH)/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_objdetect
# Files which require compiling
SOURCE_FILES=\
src/lib/IO.cc\
src/lib/PDM.cc\
src/lib/Patch.cc\
src/lib/CLM.cc\
src/lib/FDet.cc\
src/lib/PAW.cc\
src/lib/FCheck.cc\
src/lib/Tracker.cc
# Source files which contain a int main(..) function
SOURCE_FILES_WITH_MAIN=src/exe/face_tracker.cc
# End Configuration
SOURCE_OBJECTS=$(patsubst %.cc,%.o,$(SOURCE_FILES))
ALL_OBJECTS=\
$(SOURCE_OBJECTS) \
$(patsubst %.cc,%.o,$(SOURCE_FILES_WITH_MAIN))
DEPENDENCY_FILES=\
$(patsubst %.o,%.d,$(ALL_OBJECTS))
all: bin/face_tracker
%.o: %.cc Makefile
## Make dependecy file
$(CXX) -MM -MT $# -MF $(patsubst %.cc,%.d,$<) $(CFLAGS) $(DEFINES) $(INCLUDES) $<
## Compile
$(CXX) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $# $<
-include $(DEPENDENCY_FILES)
bin/face_tracker: $(ALL_OBJECTS)
$(CXX) $(LDFLAGS) $(LIBRARIES) -o $# $(ALL_OBJECTS)
.PHONY: clean
clean:
#echo "Cleaning"
#for pattern in '*~' '*.o' '*.d' ; do \
find . -name "$$pattern" | xargs rm ; \
done
Thanks,
Fabio

Makefile with different compiler flags for source files

How do I use different compiler flags for different source files in a Makefile? For example, I'd like a Makefile that will produce:
g++ -c -COMPILER_FLAGS_1 -g source1.cpp -o source1.o
g++ -c -COMPILER_FLAGS_2 -g source2.cpp -o source2.o
g++ -c -COMPILER_FLAGS_2 -g source3.cpp -o source3.o
g++ -c -COMPILER_FLAGS_2 -g source4.cpp -o source4.o
g++ -c -COMPILER_FLAGS_3 -g source5.cpp -o source5.o
g++ -c -COMPILER_FLAGS_3 -g source6.cpp -o source6.o
g++ -c -COMPILER_FLAGS_3 -g source7.cpp -o source7.o
g++ -g -o output source1.o source2.o source3.o source4.o source5.o source6.o source7.o
At the moment I've got about 20 source files (and that's expected to grow), so an easy to maintain file would be nice.
Thanks in advance.
You could do something like the following (untested, so the syntax might be slightly off):
OBJS_1 := source1.o
OBJS_2 := source2.o source3.o source4.o
OBJS_3 := source5.o source6.o source7.o
OBJS := $(OBJS_1) $(OBJS_2) $(OBJS_3)
output: $(OBJS)
$(CXX) -g -o $# $^
$(OBJS_1): CXXFLAGS := $(COMPILER_FLAGS_1)
$(OBJS_2): CXXFLAGS := $(COMPILER_FLAGS_2)
$(OBJS_3): CXXFLAGS := $(COMPILER_FLAGS_3)
$(OBJS): %.o: %.cpp
$(CXX) -c $(CXXFLAGS) -g $< -o $#
Here is UNIX/LINUX makefile which I wrote and tested on Solaris LINUX to handle different compilation flags for different sections of a GNUmakefile. Please let me know if it can be improved. Thank you
# GNUmakefile
#
# makefile for mdRightFielder
#
# Builds:
# libmdRightFielder.so or libmdRightFielder.sl
ifndef SUB
include ../header.mk
else
VPATH=../Source:../Source/PCRE:../Source/SQLite:../../cpswindows/Source:../../util/mdLicense
INCL=-I../Include -I../Include/PCRE -I../Include/SQLite -I../../cpswindows/Include -I ../../util -I../../util/mdLicense
APIOBJ=cGlobalDataDestructor.o cPCRE.o CppInterface.o cRightFielder-FillTokenGaps.o
PCREOBJ=pcre_chartables.o pcre_compile.o pcre_exec.o pcre_fullinfo.o pcre_get.o pcre_globals.o pcre_newline.o \
pcre_tables.o pcre_try_flipped.o
SQLITEOBJ=sqlite3.o
CPSWINDOWSOBJ=BinarySearch.o cConfigFile.o cCriticalSection.o cDateTime.o cException.o cFile.o cSQLite.o \
QuickSort.o StringFunctions.o
MDLICENSEOBJ=CBigNum.o mdLicense.o RSA.o
ifeq ($(CPU),sparc)
ifdef workshop
CALIGN=-xmemalign=1s
ifdef release
CXXALIGN=-Qoption cg -xmemalign=1s
else
CXXALIGN=-Qoption ccfe -y-xmemalign=1s
endif
endif
endif
COMPILER_FLAGS_1=-D_NO_GUI
COMPILER_FLAGS_2=-D_NO_GUI -DHAVE_CONFIG_H
CXXFLAGS+=-DPCRE_STATIC -DUSE_STATIC
CFLAGS+=-D_NO_GUI -DHAVE_CONFIG_H -DPCRE_STATIC -DUSE_STATIC
DEPFLAGS+=-DLINK_SIZE=2 -D_NO_GUI -DHAVE_CONFIG_H -DPCRE_STATIC -DUSE_STATIC
.PHONY: all clean
all: libmdRightFielder.so
cp -fp ../Include/mdRightFielder.h ../../util/mdEnums.h libmdRightFielder.so $(SHIP)
if [ `uname` = HP-UX ] ; \
then \
/bin/mv -f $(SHIP)/libmdRightFielder.so $(SHIP)/libmdRightFielder.sl ; \
fi
clean:
rm -f *.o *.so *.sl deps
rm -f core core.[0-9]*
$(APIOBJ): CXXFLAGS+=$(COMPILER_FLAGS_1)
$(PCREOBJ): CXXFLAGS+=$(COMPILER_FLAGS_2)
MARYOBJS = $(APIOBJ) $(PCREOBJ)
libmdRightFielder.so: \
$(MARYOBJS)
-$(CXX) $(CXXFLAGS) $(INCL) $(SHARED) $^ -o $# $(LDLIBS)
mary:
%.o : %.cpp # cancel implicit CPP compilation rule
%.o : %.cpp
$(CXX) $(CXXFLAGS) $(INCL) $(PIC) $< -o $# -c
%.o : %.c # cancel implicit C compilation rule
%.o : %.c
$(CC) $(CFLAGS) $(INCL) $(PIC) $< -o $# -c
endif