我正在将以前的构建系统(Makefile)转换为CMake。我试图为CMake指定链接器和链接器标志,我不确定我是否使用正确的语法/变量。我已经包含了我原来的Makefile(编译并编译可执行文件)但是当我尝试使用CMake进行操作时,我遇到了错误。
这是错误:
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
原始Makefile使用了三个标志 -lpthread -lc & -o 如果我理解正确 -o ,只是意味着使用CMake将可执行文件命名为特定名称 * ADD_EXECUTABLE * 我不需要,因为我们在那里指定了可执行文件的名称。我已经包含了我的2个CMakeLists和原始Makefile作为参考,非常感谢任何帮助,因为这已经让我在第二天难倒了..
顶级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)
二级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)
原始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)
再次,我们将非常感谢任何和所有帮助/建议!