我有一个使用cmake作为构建系统的项目,我遇到链接问题。
我有一个名为lwm2mclient.h
的haeader文件,它具有以下结构和指针声明。
typedef struct
{
char binary_filename[256];
}programming;
extern programming device1;
extern programming device2;
extern programming *programmingPtr1;
extern programming *programmingPtr2;
我有一个包含lwm2mclient.h
的源文件,这些文件分配指向实例的指针。
programming *programmingPtr1 = &device1;
programming *programmingPtr2 = &device2;
但是我收到错误建议
dut_object.c.o:(.data+0x0): undefined reference to
DEVICE1'`
我认为这与错误的链接有关但我无法理解cmakelists.txt文件中的错误。
这是cmakelists.txt文件,两个文件都设置为源。
如果有人可以查看,请欣赏它吗?
cmake_minimum_required (VERSION 3.0)
project (lwm2mclient)
option(DTLS "Enable DTLS" OFF)
# Compiler include
#INC1 = ~/Documents/wakaama-master-2_0/examples/IniParser/iniparser-master/src
SET(CRADLE_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../cradle-util/libcradle)
include(${CMAKE_CURRENT_LIST_DIR}/../../core/wakaama.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../shared/shared.cmake)
add_definitions(-DLWM2M_CLIENT_MODE -DLWM2M_BOOTSTRAP -DLWM2M_SUPPORT_JSON)
add_definitions(${SHARED_DEFINITIONS} ${WAKAAMA_DEFINITIONS})
include_directories (${WAKAAMA_SOURCES_DIR} ${SHARED_INCLUDE_DIRS} ${CRADLE_INCLUDE_DIR} )
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -O0")
message("CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}")
SET(SOURCES
lwm2mclient.c
lwm2mclient.h
system_api.c
object_security.c
object_server.c
object_device.c
object_firmware.c
object_location.c
object_connectivity_moni.c
object_connectivity_stat.c
object_access_control.c
test_object.c
dut_object.c
usb_control.c
)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB_PKG glib-2.0)
message(Found glib-2.0)
include_directories(${GLIB_PKG_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} ${SOURCES} ${WAKAAMA_SOURCES} ${SHARED_SOURCES})
target_link_libraries(${PROJECT_NAME} cradle.a mraa.so m pthread iniparser.a )
LINK_DIRECTORIES(/usr/local/lib /usr/lib/x86_64-linux-gnu ${CMAKE_CURRENT_LIST_DIR}/../../../cradle-util/libcradle )
# Add WITH_LOGS to debug variant
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:WITH_LOGS>)