I am in the process of converting out previous build system (Makefiles) to CMake. I am trying to specify the Linker and Linker Flags for CMake and am not sure if I am using the correct syntax/variables. I have included my original Makefile (which compiles and genreates the executable) but when attempting to do the smae with CMake I am getting errors.
Here is the error:
Linking CXX executable discoveryService
/home/projects/OMAP- L137/timesys/SDK/omapl137_evm/toolchain/bin/../../toolchain/lib/crt1.o: In function `_start':
(.text+0x34): undefined reference to `main'
collect2: ld returned 1 exit status
make[2]: *** [arm/communications/discoveryService] Error 1
make[1]: *** [arm/communications/CMakeFiles/discoveryService.dir/all] Error 2
make: *** [all] Error 2
The original Makefile used three flags -lpthread -lc & -o If I am understanding correctly the -o just means to name the executable a specific name so with CMake *ADD_EXECUTABLE* I shouldn't need that since we specify the name of the executable there. I have included my 2 CMakeLists and the original Makefile for reference and any help is greatly appreciated since this has stumped me for the second day now..
Top Level CMakeList
INCLUDE(CMakeForceCompiler)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(633)
#this one is important
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
SET(FACTORY_CURRENT /home/projects/OMAP-L137/timesys/factory-current)
SET(DSPLINK_PATH ${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink- 1_65_01/DSPLink-1_65_01)
SET(DSPLINK_PACKAGE_DIR ${FACTORY_CURRENT}/${DSPLINK_PATH})
SET(TOOLCHAIN_LOC ${FACTORY_CURRENT}/build_armv5l-timesys-linux- uclibcgnueabi/toolchain/bin)
#read file into variable 'defines'
file(READ ${CMAKE_SOURCE_DIR}/arm/dsplink_config/dsplink_defines.txt defines)
#turn space separation into CMake list
string(REPLACE " " ";" defines "${defines}")
ADD_DEFINITIONS(${defines})
# specify the cross compiler
SET(CMAKE_C_COMPILER ${TOOLCHAIN_LOC}/armv5l-timesys-linux-uclibcgnueabi-g++ "-lpthread -lc")
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_LOC}/armv5l-timesys-linux-uclibcgnueabi-g++ "lpthread -lc")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -c ")
SET(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
#specify the linker
SET(CMAKE_C_LINK_EXECUTABLE "/OMAP-L137/timesys/SDK/omapl137_evm/toolchain/bin/armv5l- timesys-linux-uclibcgnueabi-g++ -lpthread -lc")
SET(CMAKE_CXX_LINK_EXECUTABLE "/OMAP-L137/timesys/SDK/omapl137_evm/toolchain/bin/armv5l-timesys-linux-uclibcgnueabi-g++ -lpthread -lc")
SET(CMAKE_LINKER "/OMAP-L137/timesys/SDK/omapl137_evm/toolchain/bin/armv5l-timesys-linux-uclibcgnueabi-g++ -lpthread -lc")
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /home/projects/OMAP-L137/timesys/factory-current)
SET(PROJECT_SOURCE_DIR /home/chrisk/633/)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
#SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/bin)
SET(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/bin)
ADD_SUBDIRECTORY(arm)
Second Level CMakeList:
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/arm/framework ${CMAKE_SOURCE_DIR}/arm/flagDictionary
${CMAKE_SOURCE_DIR}/arm/logging ${CMAKE_SOURCE_DIR}/dsp/include ${CMAKE_SOURCE_DIR}/arm/modbus ${CMAKE_SOURCE_DIR}/arm/expat)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux- uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/inc/usr)
INCLUDE_DIRECTORIES(/home/projects/OMAP-L137/timesys/factory-20120925-633/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/inc/usr)
INCLUDE_DIRECTORIES(/home/projects/OMAP-L137/timesys/factory-20120925-633/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/inc/sys/Linux)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/inc)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/inc/usr)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/inc/sys/Linux)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/inc/sys/Linux/2.6.18)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/src/samples/loop)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/src/samples/loop/Linux)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/src/samples/loop/Linux/2.6.18)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink-1_65_01/dsplink/gpp/BUILD/INCLUDE/USER)
INCLUDE_DIRECTORIES(${FACTORY_CURRENT}/build_armv5l-timesys-linux-uclibcgnueabi/DSPLink-1_65_01/DSPLink- 1_65_01/dsplink/gpp/export/INCLUDE/Linux/OMAPL1XX/internal)
INCLUDE_DIRECTORIES(${FACTORY_DIR}/build_armv5l-timesys-linux-uclibcgnueabi/toolchain/include)
SET(communications_SOURCES
discoveryService.cpp
httpService.cpp
modbusRTUService.cpp
modbusService.cpp
streamingService.cpp
trendMap.cpp
trendService.cpp
tripBuffer.cpp
tripReader.cpp
)
ADD_LIBRARY(communications ${communications_SOURCES})
SET(SET_TARGET_PROPERTIES(libcommunications.a PROPERTIES LINK_FLAGS "-lpthread -lc" ))
SET(SET_TARGET_PROPERTIES(libcommunications.a PROPERTIES LINKER_LANGUAGE CXX))
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/arm/flagDictionary ${CMAKE_SOURCE_DIR}/arm/framework ${CMAKE_SOURCE_DIR}/arm/communications
${DSPLINK_PACKAGE_DIR}/dsplink/gpp/export/BIN/Linux/OMAPL1XX/RELEASE/ "-lpthread -lc")
ADD_EXECUTABLE(discoveryService discoveryService.cpp)
TARGET_LINK_LIBRARIES(discoveryService flagDictionary framework communications dsplink.lib)
Original Makefile:
$(shell ../../build_environment.sh)
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. -I../framework -I../flagDictionary -I../logging -I../../dsp/include - I../modbus -I../expat
TOOLCHAIN = /OMAP-L137/timesys/SDK/omapl137_evm/toolchain/bin
#TOOLCHAIN = ${FACTORY_DIR}/build_armv5l-timesys-linux-uclibcgnueabi/toolchain/bin
PLATFORM=armv5l-timesys-linux-uclibcgnueabi
#Compile Options
CC=$(TOOLCHAIN)/$(PLATFORM)-g++
LINKER=$(TOOLCHAIN)/$(PLATFORM)-g++
CFLAGS+=$(BUILD_DEF) $(INCLUDE)
DEBUG =
#list of things to compile.
FW_BUILD_DIR=../framework/build
LOG_BUILD_DIR=../logging/build
XML_BUILD_DIR=../expat/build
MODBUS_BUILD_DIR=../modbus/build
FLAG_DICT_BUILD_DIR=../flagDictionary/build
CORE_FRAMEWORK_OBJECTS= $(FW_BUILD_DIR)/application.o \
$(FW_BUILD_DIR)/arguments.o \
$(FW_BUILD_DIR)/com.o \
$(FW_BUILD_DIR)/memoryManagerBase.o \
$(FW_BUILD_DIR)/memoryManager.o \
$(FW_BUILD_DIR)/lockManager.o \
$(FW_BUILD_DIR)/stopWatch.o \
$(FW_BUILD_DIR)/controlCom.o \
$(FW_BUILD_DIR)/status.o \
$(FW_BUILD_DIR)/paths.o \
$(LOG_BUILD_DIR)/subsystemLogMasks.o \
$(LOG_BUILD_DIR)/logger.o
# removed utils.o from CORE
NET_FRAMEWORK_OBJECTS= $(FW_BUILD_DIR)/message.o \
$(FW_BUILD_DIR)/chunk.o \
$(FW_BUILD_DIR)/multicastSocket.o \
$(FW_BUILD_DIR)/serverSocket.o \
$(FW_BUILD_DIR)/socket.o \
$(FW_BUILD_DIR)/tcpReader.o
CONF_FRAMEWORK_OBJECTS= $(FW_BUILD_DIR)/configuration.o \
$(FW_BUILD_DIR)/editConfig.o \
$(FW_BUILD_DIR)/parseConfig.o \
$(FW_BUILD_DIR)/xpath.o \
$(XML_BUILD_DIR)/xmlparse.o \
$(XML_BUILD_DIR)/xmlrole.o \
$(XML_BUILD_DIR)/xmltok.o
MODBUS_OBJECTS= $(MODBUS_BUILD_DIR)/modbus.o \
$(MODBUS_BUILD_DIR)/modbusFacade.o
MODBUS_RTU_OBJECTS= $(MODBUS_BUILD_DIR)/modbus.o \
$(MODBUS_BUILD_DIR)/rtuFacade.o
FLAG_DICT_OBJECTS= $(FLAG_DICT_BUILD_DIR)/flagEntry.o \
$(FLAG_DICT_BUILD_DIR)/flagDictionary.o
OBJECTS = discoveryService.o \
httpService.o \
modbusService.o \
streamingService.o \
trendMap.o \
trendService.o \
tripBuffer.o \
modbusRTUService.o \
tripReader.o
EXES = discoveryService httpService modbusService streamingService trendService tripReader modbusRTUService cmprXfr
all: $(OBJECTS) $(EXES)
.c.o:
mkdir -p build
$(CC) -c $(CFLAGS) $(DSPLINK_INCLUDES) $(DSPLINK_FLAGS) $(DSPLINK_DEFINES) $(DEBUG) -o $(TMP)/$# $<
.cpp.o:e
mkdir -p build
$(CC) -c $(CFLAGS) $(DSPLINK_INCLUDES) $(DSPLINK_FLAGS) $(DSPLINK_DEFINES) $(DEBUG) -o $(TMP)/$# $<
discoveryService: $(FRAMEWORK_OBJECTS) discoveryService.o
$(LINKER) -lpthread -lc -o $(BIN)/$# $(DSPLINK_LIBS) build/discoveryService.o $(FLAG_DICT_OBJECTS) $(CORE_FRAMEWORK_OBJECTS) $(NET_FRAMEWORK_OBJECTS) $(CONF_FRAMEWORK_OBJECTS)
Again, any and all help/suggestions will be greatly appreciated!
Related
I've built a number of projects with Veins on Omnet++ without issues at this stage, and I decided to implement CAM messages into a simulation. However, upon building I arrive at the following error:
12:41:23 **** Incremental Build of configuration release for project v2x ****
make MODE=release all
cd src && make make[1]: Entering directory '/home/veins/workspace.omnetpp/v2x/src'
Creating executable: ../out/clang-release/src/v2x /usr/bin/ld: cannot open output file ../out/clang-release/src/v2x: Is a directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]:
*** [Makefile:117: ../out/clang-release/src/v2x] Error 1 make[1]: Leaving directory '/home/veins/workspace.omnetpp/v2x/src'
make: *** [Makefile:2: all]
Error 2 "make MODE=release all" terminated with exit code 2.
Build might be incomplete.
12:41:24 Build Failed. 3 errors, 0 warnings. (took 549ms)
My Makefile reads:
#
# OMNeT++/OMNEST Makefile for v2x
#
# This file was generated with the command:
# opp_makemake -f --deep -KINET_PROJ=/home/veins/src/inet -KLTE_PROJ=/home/veins/src/simulte -KVEINS_INET_PROJ=/home/veins/src/veins/subprojects/veins_inet -KVEINS_PROJ=/home/veins/src/veins -DINET_IMPORT -DVEINS_IMPORT -DVEINS_INET_IMPORT -I$$\(INET_PROJ\)/src -I$$\(LTE_PROJ\)/src -I$$\(VEINS_INET_PROJ\)/src -I$$\(VEINS_PROJ\)/src -I. -L$$\(INET_PROJ\)/src -L$$\(LTE_PROJ\)/src -L$$\(VEINS_PROJ\)/src -L$$\(VEINS_INET_PROJ\)/src -lINET$$\(D\) -llte$$\(D\) -lveins$$\(D\) -lveins_inet$$\(D\)
#
# Name of target to be created (-o option)
TARGET_DIR = .
TARGET_NAME = v2x$(D)
TARGET = $(TARGET_NAME)$(EXE_SUFFIX)
TARGET_IMPLIB = $(TARGET_NAME)$(IMPLIB_SUFFIX)
TARGET_IMPDEF = $(TARGET_NAME)$(IMPDEF_SUFFIX)
TARGET_FILES = $(TARGET_DIR)/$(TARGET)
# User interface (uncomment one) (-u option)
USERIF_LIBS = $(ALL_ENV_LIBS) # that is, $(TKENV_LIBS) $(QTENV_LIBS) $(CMDENV_LIBS)
#USERIF_LIBS = $(CMDENV_LIBS)
#USERIF_LIBS = $(TKENV_LIBS)
#USERIF_LIBS = $(QTENV_LIBS)
# C++ include paths (with -I)
INCLUDE_PATH = -I$(INET_PROJ)/src -I$(LTE_PROJ)/src -I$(VEINS_INET_PROJ)/src -I$(VEINS_PROJ)/src -I.
# Additional object and library files to link with
EXTRA_OBJS =
# Additional libraries (-L, -l options)
LIBS = $(LDFLAG_LIBPATH)$(INET_PROJ)/src $(LDFLAG_LIBPATH)$(LTE_PROJ)/src $(LDFLAG_LIBPATH)$(VEINS_PROJ)/src $(LDFLAG_LIBPATH)$(VEINS_INET_PROJ)/src -lINET$(D) -llte$(D) -lveins$(D) -lveins_inet$(D)
# Output directory
PROJECT_OUTPUT_DIR = ../out
PROJECTRELATIVE_PATH = src
O = $(PROJECT_OUTPUT_DIR)/$(CONFIGNAME)/$(PROJECTRELATIVE_PATH)
# Object files for local .cc, .msg and .sm files
OBJS = \
$O/v2x/GeneralMessageSerializer.o \
$O/v2x/VeinsInetApplicationBase.o \
$O/v2x/VeinsInetManager.o \
$O/v2x/VeinsInetManagerBase.o \
$O/v2x/VeinsInetManagerForker.o \
$O/v2x/VeinsInetMobility.o \
$O/v2x/VeinsInetSampleApplication.o \
$O/v2x/VeinsInetSampleMessageSerializer.o \
$O/v2x/GeneralMessage_m.o \
$O/v2x/VeinsInetSampleMessage_m.o
# Message files
MSGFILES = \
v2x/GeneralMessage.msg \
v2x/VeinsInetSampleMessage.msg
# SM files
SMFILES =
# Other makefile variables (-K)
INET_PROJ=/home/veins/src/inet
LTE_PROJ=/home/veins/src/simulte
VEINS_INET_PROJ=/home/veins/src/veins/subprojects/veins_inet
VEINS_PROJ=/home/veins/src/veins
#------------------------------------------------------------------------------
# Pull in OMNeT++ configuration (Makefile.inc)
ifneq ("$(OMNETPP_CONFIGFILE)","")
CONFIGFILE = $(OMNETPP_CONFIGFILE)
else
CONFIGFILE = $(shell opp_configfilepath)
endif
ifeq ("$(wildcard $(CONFIGFILE))","")
$(error Config file '$(CONFIGFILE)' does not exist -- add the OMNeT++ bin directory to the path so that opp_configfilepath can be found, or set the OMNETPP_CONFIGFILE variable to point to Makefile.inc)
endif
include $(CONFIGFILE)
# Simulation kernel and user interface libraries
OMNETPP_LIBS = $(OPPMAIN_LIB) $(USERIF_LIBS) $(KERNEL_LIBS) $(SYS_LIBS)
ifneq ($(PLATFORM),win32.x86_64)
LIBS += -Wl,-rpath,$(abspath $(INET_PROJ)/src) -Wl,-rpath,$(abspath $(LTE_PROJ)/src) -Wl,-rpath,$(abspath $(VEINS_PROJ)/src) -Wl,-rpath,$(abspath $(VEINS_INET_PROJ)/src)
endif
COPTS = $(CFLAGS) $(IMPORT_DEFINES) -DINET_IMPORT -DVEINS_IMPORT -DVEINS_INET_IMPORT $(INCLUDE_PATH) -I$(OMNETPP_INCL_DIR)
MSGCOPTS = $(INCLUDE_PATH)
SMCOPTS =
# we want to recompile everything if COPTS changes,
# so we store COPTS into $COPTS_FILE (if COPTS has changed since last build)
# and make the object files depend on it
COPTS_FILE = $O/.last-copts
ifneq ("$(COPTS)","$(shell cat $(COPTS_FILE) 2>/dev/null || echo '')")
$(shell $(MKPATH) "$O")
$(file >$(COPTS_FILE),$(COPTS))
endif
#------------------------------------------------------------------------------
# User-supplied makefile fragment(s)
-include makefrag
#------------------------------------------------------------------------------
# Main target
all: $(TARGET_FILES)
$(TARGET_DIR)/% :: $O/%
#mkdir -p $(TARGET_DIR)
$(Q)$(LN) $< $#
ifeq ($(TOOLCHAIN_NAME),clang-msabi)
-$(Q)-$(LN) $(<:%.dll=%.lib) $(#:%.dll=%.lib) 2>/dev/null
endif
$O/$(TARGET): $(OBJS) $(wildcard $(EXTRA_OBJS)) Makefile $(CONFIGFILE)
#$(MKPATH) $O
#echo Creating executable: $#
$(Q)$(CXX) $(LDFLAGS) -o $O/$(TARGET) $(OBJS) $(EXTRA_OBJS) $(AS_NEEDED_OFF) $(WHOLE_ARCHIVE_ON) $(LIBS) $(WHOLE_ARCHIVE_OFF) $(OMNETPP_LIBS)
.PHONY: all clean cleanall depend msgheaders smheaders
.SUFFIXES: .cc
$O/%.o: %.cc $(COPTS_FILE) | msgheaders smheaders
#$(MKPATH) $(dir $#)
$(qecho) "$<"
$(Q)$(CXX) -c $(CXXFLAGS) $(COPTS) -o $# $<
%_m.cc %_m.h: %.msg
$(qecho) MSGC: $<
$(Q)$(MSGC) -s _m.cc -MD -MP -MF $O/$(basename $<)_m.h.d $(MSGCOPTS) $?
%_sm.cc %_sm.h: %.sm
$(qecho) SMC: $<
$(Q)$(SMC) -c++ -suffix cc $(SMCOPTS) $?
msgheaders: $(MSGFILES:.msg=_m.h)
smheaders: $(SMFILES:.sm=_sm.h)
clean:
$(qecho) Cleaning $(TARGET)
$(Q)-rm -rf $O
$(Q)-rm -f $(TARGET_FILES)
$(Q)-rm -f $(call opp_rwildcard, . , *_m.cc *_m.h *_sm.cc *_sm.h)
cleanall:
$(Q)$(CLEANALL_COMMAND)
$(Q)-rm -rf $(PROJECT_OUTPUT_DIR)
help:
#echo "$$HELP_SYNOPSYS"
#echo "$$HELP_TARGETS"
#echo "$$HELP_VARIABLES"
#echo "$$HELP_EXAMPLES"
# include all dependencies
-include $(OBJS:%=%.d) $(MSGFILES:%.msg=$O/%_m.h.d)
It's correct in saying that clang-release/src/v2x is a directory, but it has always been so (even before making the recent changes) and it hasn't produced this error.
Other than the MakeFile error, there is no other error in any of the scripts for the project.
You want to create the executable file clang-release/src/v2x but you can't because that file already exists and is a directory.
The name of the file you attempt to create is
v2x$(D)$(EXE_SUFFIX) and nowhere in your Makefile do you have Make variables D or EXE_SUFFIX defined, so they evaluate to empty strings.
Probably you want to make sure you have D and EXE_SUFFIX defined somewhere.
There is a $(CONFIGFILE) you are including, Make finds it but you did not provide the text of it, check if these variables should be defined in there but are not.
This is my makefile in linux
.SILENT:
.SUFFIXES: .cpp
FLAGS_CC = -c -fPIC -DUNIX -DLINUX -D_HNAREL_=500 -D_TARGET__REL=0 -D_TARGET__DEBUG=1 -D_ILS_MACROS -I$(cer_incl)
FLAGS_CPP = -c -Wno-deprecated -fPIC -frtti -finline-functions -DUNIX -DLINUX -D_HNAREL_=500 -D_TARGET__REL=0 -D_TARGET__DEBUG=1 -D_ILS_MACROS -I$(cer_incl)
FLAGS_LINK = -m32 -fPIC -lm -lc -lrt -lpthread -ldl
FLAGS_LINKSHR = -m32 -lm -lc -shared -Wl,-no-undefined -lrt -lpthread -ldl
CC = gcc $(FLAGS_CC) $(__define) $(__build)
CPP = g++ $(FLAGS_CPP) $(__define) $(__build)
LINK = g++ $(FLAGS_LINK)
LINKSHR = g++ $(FLAGS_LINKSHR)
PRINT = echo
##
## The following environment variables are defined for your convenience.
##-----
## __srcdir - Project directory that contains the makefile and source code.
## __objdir - Project subdirectory that stores objects for the given platform
## and target combination.
## __libdir - Public directory that contains objects and shareable libraries.
## __exedir - Public directory that contains executables.
##-----
## Please do not delete the following line!
###makefile###
###makedep###
#my_project.o
FLAGS__MY_PROJECT =
DEFINES__MY_PROJECT =
my_project.o: $(__objdir)/my_project.o
$(__objdir)/my_project.o: \
my_project.cpp \
$(cer_incl)/srvimpl.h \
$(PRINT) "compiling - my_project.cpp"
[[ -d $(__objdir) ]] || mkdir -p $(__objdir)
$(CPP) $(FLAGS__MY_PROJECT) $(DEFINES__MY_PROJECT) -o $(__objdir)/my_project.o my_project.cpp
#aps_s200061.o
FLAGS__APS_S200061 =
DEFINES__APS_S200061 =
aps_s200061.o: $(__objdir)/aps_s200061.o
$(__objdir)/aps_s200061.o: \
aps_s200061.cpp \
aps_s200061.h \
$(cer_incl)/srvimpl.h \
$(PRINT) "compiling - aps_s200061.cpp"
[[ -d $(__objdir) ]] || mkdir -p $(__objdir)
$(CPP) $(FLAGS__APS_S200061) $(DEFINES__APS_S200061) -o $(__objdir)/aps_s200061.o aps_s200061.cpp
###makedep###
FLAGS_CPP += -D__RHEL6
FLAGS__APS_S200061 =
objects: my_project.o aps_s200061.o
my_project : objects
$(PRINT) "creating - my_project "
$(LINKSHR) \
-Wl,--version-script=$(__srcdir)/my_project.emap \
-o $(__objdir)/my_project \
$(__objdir)/my_project.o \
$(__objdir)/aps_s200061.o \
-Wl,--start-group \
-L$(__libdir) -lapsobj -lcernobj -lcontainerobj -lstringobj -li18n_common -lmsgutilobj -lmftmiscobj -lsrvcoreobj -lcrmobj -lthreadobj \
-Wl,--whole-archive -lsrvobj -Wl,--no-whole-archive \
-Wl,--end-group \
-L$(__exedir) -ldb -ldps -lsrv -lsec \
-lcclora -lreg -lmsgapi -ldate \
-llogical -lsrvcore -lcrm
copy:
$(PRINT) "copying - my_project"
cp $(__objdir)/my_project $(__exedir)
it: my_project copy
# shr:my_project
I want to remove the command cp $(__objdir)/my_project $(__exedir) from the above file.
When I try removing the line manually in a text editor and save it , the make file doesn't throw any errors.
But if I try removing the line programmatically , we get make: *** No rule to make target my_project.o', needed by objects'. Stop.
Sequence of commands we use is :
'makedep'
'make -f ${PWD##*/}.linux -r __target=rel _define="-D_TARGET=_TARGET__REL " __srcdir=$PWD __objdir=$PWD/linuxx86-64 __libdir=$abc_lib_rel __exedir=$abc_exe_rel __build="-O3" it'
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).
I'm using a developement board that has its own libraries. I have installed ROS on it and now I need to use publish/subscribe by including its libraries to the CMakeLists.txt of the package. I have to also note that I use Eclipse for compilation, so the CMakeLists.txt is in that form. Here is the Makefile of hardware library that I want to use in CMakeLists.txt:
DIR=$(shell pwd)/../
INCS = -I.\
-I$(DIR) \
-I$(DIR)/hardware \
-I$(DIR)/hardware/environment \
-I$(DIR)/hardware/environment/cores \
-I$(DIR)/hardware/environment/cores/environment \
-I$(DIR)/hardware/environment/variants \
-I$(DIR)/hardware/environment/variants/sunxi \
-I$(DIR)/libraries \
-I$(DIR)/libraries/Serial \
-I$(DIR)/libraries/SPI \
-I$(DIR)/libraries/Wire \
-I$(DIR)/libraries/LiquidCrystal \
-I$(DIR)/Basibos/include LIBS=../libenvironment.a TARGET=../output/test
OBJS = BasibosAnaProgram
all:
#mkdir -p $(TARGET)
for i in $(OBJS); do echo "$(CXX) $(INCS) $$i.cpp -o $(TARGET)/$$i $(LIBS)"; done
#for i in $(OBJS); do $(CXX) $(INCS) $$i.cpp -o $(TARGET)/$$i $(LIBS); done
clean:
#for i in $(OBJS); do rm -f $(TARGET)/$$i; done
And here is the example CMakeLists.txt that Makefile should be included:
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
rosbuild_add_library(${PROJECT_NAME} src/Basibos.cpp)
rosbuild_add_library(${PROJECT_NAME} src/HedefeGitme.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Konum.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Robot.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Sonar.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Zaman.cpp)
rosbuild_add_library(${PROJECT_NAME} src/XMLAyiklayici.cpp)
rosbuild_add_executable(srctest RobotKontrol.cpp)
target_link_libraries(srctest ${PROJECT_NAME})
I'm stuck and can't go forward without help. Any help will be greately appreciated. Thanks in advance
Source: http://www.ros.org/wiki/rosbuild/CMakeLists
You have to add the source files in following fashion:
rosbuild_add_library(XmlRpc src/XmlRpcClient.cpp
src/XmlRpcDispatch.cpp
src/XmlRpcServer.cpp
src/XmlRpcServerConnection.cpp
src/XmlRpcServerMethod.cpp
src/XmlRpcSocket.cpp
src/XmlRpcSource.cpp
src/XmlRpcUtil.cpp
src/XmlRpcValue.cpp)
I am trying to implement the non-recursive make solution outlined in the paper "Recursive Make Considered Harmful". I'm currently stuck on getting the *.d dependency files to generate. I've provided the makefile, sample module.mk and error below. Any ideas how I can fix this?
MODULES := \
module1 \
module2
# define compiler
CC = /opt/local/bin/clang++-mp-3.1
# exclude the following warnings for clang
CLANG_NO_WARN = \
-Wno-c++98-compat \
-Wno-weak-vtables \
-Wno-padded \
-Wno-global-constructors \
-Wno-exit-time-destructors
# look for include files in each of the modules
CFLAGS += \
-g -Weverything -Wall -std=c++11 -stdlib=libc++ $(CLANG_NO_WARN) \
-I../ -I/usr/local/include $(patsubst %, -I%, $(MODULES))
# linker flags
LDFLAGS := \
-stdlib=libc++ \
-L/usr/local/boost_1_50_0/stage/lib -L/usr/local/lib
# extra libraries if required (each module will add to this)
LIBS := \
-lboost_program_options \
-lboost_system \
-lglog \
-lpugixml
# source files to be compiled (each module will add to this)
SRCS := \
Main.cpp
# include the descriptions for each module
include $(patsubst %, %/module.mk, $(MODULES))
# determine the object files
OBJS := \
$(patsubst %.cpp, %.o, $(filter %.cpp, $(SRCS)))
# link the program
prog: $(OBJS)
$(CC) -o $# $(OBJS) $(LDFLAGS) $(LIBS)
# include the C include dependencies
include $(OBJS:.o=.d)
# calculate C include dependencies
%.d: %.cpp
depend.sh `dirname $*.cpp` $(CFLAGS) $*.cpp > $#
----------
#!/bin/sh
# Evaluate dependencies for use by the makefile
echo "Called"
DIR="$1"
shift 1
case "$DIR" in
"" | ".")
$CC -MM -MG "$#" | sed -e 's#ˆ\(.*\)\.o:#\1.d \1.o:#' ;;
*)
$CC -MM -MG "$#" | sed -e "s#ˆ\(.*\)\.o:#$DIR/\1.d \ $DIR/\1.o:#" ;;
esac
------------
# module.mk
SRCS += \
Algo.cpp \
CommandHandler.cpp \
Exchange.cpp \
TCPSocket.cpp \
TradingEngine.cpp
----------
$ make
makefile:68: Main.d: No such file or directory
makefile:68: view_string.d: No such file or directory
makefile:68: Algo.d: No such file or directory
makefile:68: CommandHandler.d: No such file or directory
makefile:68: Exchange.d: No such file or directory
makefile:68: TCPSocket.d: No such file or directory
makefile:68: TradingEngine.d: No such file or directory
makefile:68: Exchange.d: No such file or directory
makefile:68: Requests.d: No such file or directory
makefile:68: TickCapture.d: No such file or directory
makefile:68: types.d: No such file or directory
make: *** No rule to make target `types.d'. Stop.
UPDATE
Finished makefile and sample module.mk
$cat makefile
# executable name
BINARY := my_prog
# clang config
CLANG := /opt/local/bin/clang++-mp-3.1
CLANG_WARNINGS := \
-Wno-c++98-compat \
-Wno-weak-vtables \
-Wno-padded \
-Wno-global-constructors \
-Wno-exit-time-destructors
CLANG_CFLAGS := \
-g -Weverything -Wall -std=c++11 -stdlib=libc++
CLANG_LDFLAGS := \
-stdlib=libc++
# generic compiler config
CC := $(CLANG)
CFLAGS := $(CLANG_WARNINGS) $(CLANG_CFLAGS)
LDFLAGS := $(CLANG_LDFLAGS)
INCS := \
-I../ \
-I/usr/local/include \
$(patsubst %, -I%, $(SUBDIRS))
LIBS := \
-L/usr/local/boost_1_50_0/stage/lib \
-L/usr/local/lib \
-lboost_program_options \
-lboost_system \
-lglog \
-lpugixml
# list subdirectories in which to look for dependencies
# must define SRCS first as subdirs will append to this
# their src files
SRCS := Main.cpp
SUBDIRS := \
module1 \
module2
include $(patsubst %, %/module.mk, $(SUBDIRS))
# derive object files from srcs
OBJS := $(patsubst %.cpp, %.o, $(filter %.cpp, $(SRCS)))
# link the program
$(BINARY): $(OBJS)
$(CC) -o $# $(OBJS) $(LDFLAGS) $(LIBS)
# include generated dependency files
DEPS := $(OBJS:.o=.d)
-include $(DEPS)
# generate include dependencies
%.d: %.cpp
./depend.sh `dirname $*.cpp` $(INCS) $*.cpp > $#
# compile
.cpp.o:
$(CC) $(CFLAGS) $(INCS) $< -c -o $#
# clean, obviously
clean:
rm -f $(BINARY)
rm -f $(OBJS)
rm -f $(DEPS)
# et voila!
-----
$cat module1/module.mk
SRCS_PATH := module1
SRCS += \
$(SRCS_PATH)/Algo.cpp \
$(SRCS_PATH)/CommandHandler.cpp \
$(SRCS_PATH)/Exchange.cpp \
$(SRCS_PATH)/TCPSocket.cpp \
$(SRCS_PATH)/TradingEngine.cpp
It looks as if some module adds types.cpp to SRCS, even though no such source file exists.
As for the warnings, the first time you run this makefile, the dependency files (foo.d) do not yet exist, so Make complains that it can't include them. It's not a problem, and the warnings won't appear in subsequent runs when those files do exist beforehand. To supress the warnings entirely, change include to -include.