I am using CMake to build TI C2000 project where I am importing 3 TI libraries libc.a, driverlib.lib and driverlib_coff.lib.
These libraries are added by importing them as shown in below. Moreover, I am able to build 3 similar projects using CMake which uses same libraries and also this project in CCS IDE without any problem, not able to build this project successfully using CMake it’s giving undefined referenced symbol for imported libraries (see the output below)
I have spent 3-4 days looking for a solution as following without any progress. Just not sure what I am doing wrong or what to do next. Please help.
Tried
- LINK_INTERFACE_MULTIPLICITY
- re-arranging dependencies
- adding --reread_library linker flag etc.
# ==========================================================================================================
# CPU2 APPLICATON PROJECT
# ==========================================================================================================
project($ENV{CPU2_APPCODE_DIR_NAME} C CXX ASM) # support C,C++,ASM languages
include(compiler_flags.cmake)
# ========= set pre-defines ================================================================================
add_compile_definitions(CPU2 _FLASH MEASURE_CPU2_LLC_INT xdc__strict)
#add_defines(DEFINE_FLAGS_FOR_LINKER_FILE "--define=CLA_C=1 ")
# ========= set commonly used path variables ===============================================================
#set(COMMON_FLASH_DIR ${PROJ_COMN_DIR}/flash_api)
set(CPU2_APPLICATION2_DIR $ENV{CPU2_APPCODE_DIR}/application)
# ========= set include paths ==============================================================================
# Tools
# Project - top level
include_directories(${C2000WARE_DIR}/driverlib)
# Project - sub directories of cpu2-application
# TODO: Find a way to recursively include all
include_directories(${PROJ_COMN_DIR})
include_directories($ENV{CPU2_APPCODE_DIR})
include_directories(${CPU2_APPLICATION2_DIR})
include_directories(${CPU2_APPLICATION2_DIR}/analog)
# ========= Build libraris first ===========================================================================
set(C2000Ware_C2A
${C2000WARE_DIR}/source/F2837xD_Adc.c
# actual CMake file has bunch of files here
)
set(CommonLib_C2A
${PROJ_COMN_DIR}/dac.cpp
# actual CMake file has bunch of files here
)
set(AppCode_C2A
${CPU2_APPLICATION2_DIR}/dc_control.cpp
# actual CMake file has bunch of files here
)
# ========= Create executables from source and library files ===============================================
# Ask cmake to read <foo>.cla as <foo>.c file -- .cla extension is not recognized by cmake
SET_SOURCE_FILES_PROPERTIES(${CPU2_APPLICATION2_DIR}/cla/cla_tasks_c.cla PROPERTIES LANGUAGE C)
# main file
add_executable(${PROJECT_NAME}
main.c
${AppCode_C2A}
${CommonLib_C2A}
${C2000Ware_C2A}
)
add_library(TI_Libraries1 STATIC IMPORTED)
add_library(TI_Libraries2 STATIC IMPORTED)
add_library(TI_Libraries3 STATIC IMPORTED)
set_property(TARGET TI_Libraries1 PROPERTY
IMPORTED_LOCATION ${TI_C2000_COMPLR_PATH}/lib/libc.a)
set_property(TARGET TI_Libraries2 PROPERTY
IMPORTED_LOCATION ${C2000WARE_DIR}/driverlib/driverlib.lib)
set_property(TARGET TI_Libraries3 PROPERTY
IMPORTED_LOCATION ${C2000WARE_DIR}/driverlib/driverlib_coff.lib)
add_dependencies(${PROJECT_NAME} TI_Libraries2 TI_Libraries1)
add_dependencies(${PROJECT_NAME} TI_Libraries3 TI_Libraries1)
add_dependencies(${PROJECT_NAME} TI_Libraries1 )
set(DEFINE_FLAGS_FOR_LINKER_FILE "--define=CLA_C=1")
target_link_libraries(${PROJECT_NAME}
${DEFINE_FLAGS_FOR_LINKER_FILE}
${CMAKE_CURRENT_SOURCE_DIR}/2837xD_FLASH_lnk_cpu2.cmd
${C2000WARE_DIR}/cmd/F2837xD_Headers_nonBIOS_cpu2.cmd
TI_Libraries2
TI_Libraries3
TI_Libraries1
# ${C2000WARE_DIR}/driverlib/driverlib.lib
# ${C2000WARE_DIR}/driverlib/driverlib_coff.lib
# ${TI_C2000_COMPLR_PATH}/lib/libc.a
)
#set(CMAKE_EXE_LINKER_FLAGS ${LINKER_OPTIONS})
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
# ========= Specify folders where you want output files =====================================================
include(${PROJ_ROOT_DIR}/common.cmake)
Function_Export_Target_Files(${PROJECT_NAME})
/opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/bin/cl2000 --run_linker --output_file=emb-powermodule-cpu2 --map_file=emb-powermodule-cpu2.map --define=CLA_C=1 ../../emb-powermodule-cpu2/2837xD_FLASH_lnk_cpu2.cmd ../../C2000Ware/cmd/F2837xD_Headers_nonBIOS_cpu2.cmd ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a ../../C2000Ware/driverlib/driverlib.lib ../../C2000Ware/driverlib/driverlib_coff.lib /opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a --output_file=emb-powermodule-cpu2.0.94.6.4d2d67ac.out --map_file=emb-powermodule-cpu2.0.94.6.4d2d67ac.map --heap_size=0 --stack_size=0x400 --warn_sections --diag_wrap=off --display_error_number --diag_suppress=10063-D --verbose_diagnostics --xml_link_info=emb-powermodule-cpu2.0.94.6.4d2d67ac.xml CMakeFiles/emb-powermodule-cpu2.dir/main.c.o
## Actual command line output has bunch of object files here
## Actual command line output has bunch of object files here
## Actual command line output has bunch of object files here
## Actual command line output has bunch of object files here
## Actual command line output has bunch of object files here
## Actual command line output has bunch of object files here
<Linking>
"/tmp/TI0cmEV3CJ8", line 8: warning #10211-D: cannot resolve archive
../../C2000Ware/driverlib/driverlib.lib to a compatible library, as no input
files have been encountered; build attribute information from input files is
needed to determine library compatibility
"../../C2000Ware/driverlib/driverlib.lib"
"/tmp/TI0cmEV3CJ8", line 10: warning #10211-D: cannot resolve archive
/opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a to a
compatible library, as no input files have been encountered; build attribute
information from input files is needed to determine library compatibility
"/opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a"
"/tmp/TI0cmKDw0P3", line 8: warning #10211-D: cannot resolve archive
../../C2000Ware/driverlib/driverlib.lib to a compatible library, as no input
files have been encountered; build attribute information from input files is
needed to determine library compatibility
"../../C2000Ware/driverlib/driverlib.lib"
"/tmp/TI0cmKDw0P3", line 10: warning #10211-D: cannot resolve archive
/opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a to a
compatible library, as no input files have been encountered; build attribute
information from input files is needed to determine library compatibility
"/opt/ti/ccs/tools/compiler/ti-cgt-c2000_18.12.4.LTS/lib/libc.a"
undefined first referenced
symbol in file
--------- ----------------
___adelete CMakeFiles/emb-powermodule-cpu2.dir/application/pmstatusbits.cpp.o
___anew CMakeFiles/emb-powermodule-cpu2.dir/application/dc_ctrl_task.cpp.o
operator delete(void *) CMakeFiles/emb-powermodule-cpu2.dir/application/dc_ctrl_task.cpp.o
operator new(unsigned long) CMakeFiles/emb-powermodule-cpu2.dir/application/dc_ctrl_task.cpp.o
___record_needed_destruction CMakeFiles/emb-powermodule-cpu2.dir/application/dc_ctrl_task.cpp.o
__abort_msg CMakeFiles/emb-powermodule-cpu2.dir/application/os/hwi.cpp.o
__stack CMakeFiles/emb-powermodule-cpu2.dir/application/os/task.cpp.o
_c_int00 CMakeFiles/emb-powermodule-cpu2.dir/application/os/task_funcs.asm.o
_memset CMakeFiles/emb-powermodule-cpu2.dir/application/os/mem.cpp.o
error #10234-D: unresolved symbols remain
error #10010: errors encountered during linking;
"emb-powermodule-cpu2.0.94.6.4d2d67ac.out" not built
>> Compilation failure
make[2]: *** [emb-powermodule-cpu2/CMakeFiles/emb-powermodule-cpu2.dir/build.make:721: emb-powermodule-cpu2/emb-powermodule-cpu2] Error 1
make[2]: Leaving directory '/home/git/powermodule_v1_5/cmake-build'
make[1]: *** [CMakeFiles/Makefile2:94: emb-powermodule-cpu2/CMakeFiles/emb-powermodule-cpu2.dir/all] Error 2
make[1]: Leaving directory '/home/git/powermodule_v1_5/cmake-build'
make: *** [Makefile:130: all] Error 2