I have a project that uses cmake as the build system and I have a problem with linking.
I have haeader file called lwm2mclient.h
that has the following struct and pointer declarations.
typedef struct
{
char binary_filename[256];
}programming;
extern programming device1;
extern programming device2;
extern programming *programmingPtr1;
extern programming *programmingPtr2;
I have a souce files that includes lwm2mclient.h
which assigns the pointers to the instances liek this.
programming *programmingPtr1 = &device1;
programming *programmingPtr2 = &device2;
But I get an error bulding
dut_object.c.o:(.data+0x0): undefined reference to
device1'`
I gather this is related to incorrect linking but I can't understand whats wrong in the cmakelists.txt file.
Thi is the cmakelists.txt file and both files are set as sources.
Appreciate it if somebody could review it please?
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>)