This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: undefined reference to `std::ios_base::Init::Init()

Part Number: TM4C123GH6PM


Dear Sir,

I am using GCC compiler version 7.2.1 for TM4C123GH6PM microcontroller with TivaWare_C_Series-2.2.0.295 library , 

I need need to be develop C++ programing with C standard C++17  ,  without #include <iostream>  linking  ok ; but with #include <iostream>  I am getting linking fault given below 

"C:\\ti\\ccs1040\\ccs\\utils\\bin\\gmake" -k -j 12 all -O

Building file: "../tm4c123gh6pm_startup_ccs_gcc.c"
Invoking: GNU Compiler
"C:/ti/ccs1040/ccs/tools/compiler/gcc-arm-none-eabi-7-2017-q4-major-win32/bin/arm-none-eabi-gcc-7.2.1.exe" -c -mcpu=cortex-m4 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DPART_TM4C123GH6PM -I"C:/ti/ccs1040/ccs/tools/compiler/gcc-arm-none-eabi-7-2017-q4-major-win32/arm-none-eabi/include" -I"D:/GCC/BARCODE" -I"C:/ti/TivaWare_C_Series-2.2.0.295/driverlib" -I"C:/ti/TivaWare_C_Series-2.2.0.295/grlib" -I"C:/ti/TivaWare_C_Series-2.2.0.295" -Og -ffunction-sections -fdata-sections -g -gdwarf-3 -gstrict-dwarf -Wall -specs="nosys.specs" -MMD -MP -MF"tm4c123gh6pm_startup_ccs_gcc.d_raw" -MT"tm4c123gh6pm_startup_ccs_gcc.o" -o"tm4c123gh6pm_startup_ccs_gcc.o" "../tm4c123gh6pm_startup_ccs_gcc.c"
Finished building: "../tm4c123gh6pm_startup_ccs_gcc.c"

Building file: "../main.cpp"
Invoking: GNU Compiler
"C:/ti/ccs1040/ccs/tools/compiler/gcc-arm-none-eabi-7-2017-q4-major-win32/bin/arm-none-eabi-gcc-7.2.1.exe" -c -mcpu=cortex-m4 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DPART_TM4C123GH6PM -I"C:/ti/ccs1040/ccs/tools/compiler/gcc-arm-none-eabi-7-2017-q4-major-win32/arm-none-eabi/include" -I"D:/GCC/BARCODE" -I"C:/ti/TivaWare_C_Series-2.2.0.295/driverlib" -I"C:/ti/TivaWare_C_Series-2.2.0.295/grlib" -I"C:/ti/TivaWare_C_Series-2.2.0.295" -Og -ffunction-sections -fdata-sections -g -gdwarf-3 -gstrict-dwarf -Wall -specs="nosys.specs" -MMD -MP -MF"main.d_raw" -MT"main.o" -fno-threadsafe-statics -o"main.o" "../main.cpp"
Finished building: "../main.cpp"

Building target: "BARCODE.out"
Invoking: GNU Linker
"C:/ti/ccs1040/ccs/tools/compiler/gcc-arm-none-eabi-7-2017-q4-major-win32/bin/arm-none-eabi-gcc-7.2.1.exe" -DPART_TM4C123GH6PM -Og -ffunction-sections -fdata-sections -g -gdwarf-3 -gstrict-dwarf -Wall -specs="nosys.specs" -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,-Map,"BARCODE.map" -L"C:/ti/TivaWare_C_Series-2.2.0.295/driverlib/gcc" -o"BARCODE.out" "./main.o" "./tm4c123gh6pm_startup_ccs_gcc.o" -Wl,-T"../tm4c123gh6pm.lds" -Wl,--start-group "C:/ti/TivaWare_C_Series-2.2.0.295/driverlib/gcc/libdriver.a" "C:/ti/TivaWare_C_Series-2.2.0.295/grlib/gcc/libgr.a" -lc -Wl,--end-group
makefile:146: recipe for target 'BARCODE.out' failed
./main.o: In function `__static_initialization_and_destruction_0(int, int)':
c:\ti\ccs1040\ccs\tools\compiler\gcc-arm-none-eabi-7-2017-q4-major-win32\arm-none-eabi\include\c++\7.2.1/iostream:74: undefined reference to `std::ios_base::Init::Init()'
./main.o: In function `__static_initialization_and_destruction_0(int, int)':
D:\GCC\BARCODE\Debug/../main.cpp:26: undefined reference to `std::ios_base::Init::~Init()'
./main.o: In function `main':
D:\GCC\BARCODE\Debug/../main.cpp:21: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
D:\GCC\BARCODE\Debug/../main.cpp:26: undefined reference to `std::cout'
collect2.exe: error: ld returned 1 exit status
gmake[1]: *** [BARCODE.out] Error 1
gmake: *** [all] Error 2
makefile:142: recipe for target 'all' failed

**** Build Finished ****

I have written small program given below 

#include<stdbool.h>
#include <stdint.h>


#include "Barcode/Point.h"
#include <iostream>
#include <string>
using namespace std;


int main(void)
{

cout << "Hello World!\n" ;
return 0;

return 0;

}

kindly help me to resolve the issue

  • Hi,

      Talking to some experts, it is suspected the problem may be related to the TivaWare version supporting this version of GCC compiler for building C++ objects. Sorry for lack of guidance. I really don't have a solution for this. Can you try C?

  • I need need to be develop C++ programing with C standard C++17  ,  without #include <iostream>  linking  ok ; but with #include <iostream>  I am getting linking fault given below 

    To resolve the linker error about unresolved symbols when using GCC 7.2.1 you need to add stdc++ to the list of libraries:

    However, when I tried that with the following simple code for a TM4C123GH6PM:

    #include <iostream>
    using namespace std;
    
    int main(void)
    {
        cout << "Hello World!\n" ;
    	return 0;
    }
    

    Then got the following linker error since the program was too big to fit in flash:

    **** Build of configuration Debug for project TM4C123GH6PM_GCC_CPP_hello ****
    
    /home/mr_halfword/ti/ccs1040/ccs/utils/bin/gmake -k -j 12 all -O 
     
    Building target: "TM4C123GH6PM_GCC_CPP_hello.out"
    Invoking: GNU Linker
    "/home/mr_halfword/ti/ccs1040/ccs/tools/compiler/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gcc-7.2.1" -DPART_TM4C123GH6PM -Og -ffunction-sections -fdata-sections -g -gdwarf-3 -gstrict-dwarf -Wall -specs="nosys.specs" -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,-Map,"TM4C123GH6PM_GCC_CPP_hello.map" -o"TM4C123GH6PM_GCC_CPP_hello.out" "./main.o" "./tm4c123gh6pm_startup_ccs_gcc.o" -Wl,-T"../tm4c123gh6pm.lds"  -Wl,--start-group -lstdc++ -Wl,--end-group 
    makefile:142: recipe for target 'TM4C123GH6PM_GCC_CPP_hello.out' failed
    /home/mr_halfword/ti/ccs1040/ccs/tools/compiler/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: TM4C123GH6PM_GCC_CPP_hello.out section `.text' will not fit in region `FLASH'
    /home/mr_halfword/ti/ccs1040/ccs/tools/compiler/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 226740 bytes
    collect2: error: ld returned 1 exit status
    gmake[1]: *** [TM4C123GH6PM_GCC_CPP_hello.out] Error 1
    gmake: *** [all] Error 2
    makefile:138: recipe for target 'all' failed
    
    **** Build Finished ****
    

    The error about insufficient flash space occurred even with the -ffunction-sections and -fdata-sections GCC compiler options to place functions / data items in their own sections to help the linker remove unused functions / data items.

    I.e. appears the TM4C123GH6PM flash is too small to fit the C++ code required for cout / iostream support.