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.

C674X Mathlib error #821: badly formed pragma

Other Parts Discussed in Thread: MATHLIB

Hello,

I've been trying to include Mathlib for C6748 processor into my C++ project, CCS found the newly installed package and then in my project settings (Project Properties->CCS Build->C6000 Compiler->Include options) I included the path to the "E:\ti\mathlib_c674x_3_0_1_1\inc" folder, but whenever I try to compile the code, it reports "error #821: badly formed pragma". I managed to successfully integrate DSPLIB into this project using similar steps. Also tried using the following include but same error:

extern "C"{

#include <mathlib.h>

};

The lib is included as  "E:\ti\mathlib_c674x_3_0_1_1\lib\dsplib.ae674" into  Project Properties->CCS Build->C6000 Linker->File Search Path. My XDCtools environment is 3.23.3.53, CCS 5.2.1.00018 and I can see in Project Properties->CCS General->RTSC tab that DSPLIB and MATHLIB are included along SYS/BIOS.

 Any idea how this library can be integrated into C++ project?

Thank you in advance,

David.

  • For the TI compiler, the pragma syntax is different between C and C++, and even an 'extern"C"' block won't patch over this difference.

    Create a separate C source file in your project and compile it as C code.  Place all references to mathlib.h in that file.  You can create wrapper functions which make direct calls to mathlib.h features, and then call those wrapper functions from your C++ code.

    Could you please tell me exactly which file line 821 is in, and what the exact text of the pragma on that line is?  This is something that can be worked around by changing mathlib.h to be sensitive to whether it is being compiled for C++, but there are probably other things that need to be adjusted.

  • I'm getting the following errors:

    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atan2dp/c674/atan2dp_i.h", line 49: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atan2dp/c674/atan2dp_i.h", line 50: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atan2dp/c674/atan2dp_i.h", line 51: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atan2sp/c674/atan2sp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atan2sp/c674/atan2sp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atan2sp/c674/atan2sp_i.h", line 49: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atandp/c674/atandp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atandp/c674/atandp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atansp/c674/atansp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atansp/c674/atansp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/atansp/c674/atansp_i.h", line 49: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/cosdp/c674/cosdp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/cossp/c674/cossp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/divdp/c674/divdp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/divsp/c674/divsp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp10dp/c674/exp10dp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp10dp/c674/exp10dp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp10sp/c674/exp10sp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp10sp/c674/exp10sp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp2dp/c674/exp2dp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp2dp/c674/exp2dp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp2sp/c674/exp2sp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp2sp/c674/exp2sp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/exp2sp/c674/exp2sp_i.h", line 80: error #20: identifier "fabsf" is undefined
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/expdp/c674/expdp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/expdp/c674/expdp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/expsp/c674/expsp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/log10dp/c674/log10dp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/log10dp/c674/log10dp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/log10sp/c674/log10sp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/log2dp/c674/log2dp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/log2dp/c674/log2dp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/log2sp/c674/log2sp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/logdp/c674/logdp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/logdp/c674/logdp_i.h", line 48: error #821: badly formed pragma

    >> Compilation failure
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/logsp/c674/logsp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/powdp/c674/powdp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/powdp/c674/powdp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/powdp/c674/powdp_i.h", line 49: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/powdp/c674/powdp_i.h", line 50: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/powsp/c674/powsp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/powsp/c674/powsp_i.h", line 48: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/powsp/c674/powsp_i.h", line 49: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/recipdp/c674/recipdp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/recipsp/c674/recipsp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/rsqrtdp/c674/rsqrtdp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/rsqrtsp/c674/rsqrtsp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/sindp/c674/sindp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/sinsp/c674/sinsp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/sqrtdp/c674/sqrtdp_i.h", line 47: error #821: badly formed pragma
    "E:/ti/mathlib_c674x_3_0_1_1/packages/ti/mathlib/src/sqrtsp/c674/sqrtsp_i.h", line 47: error #821: badly formed pragma

    Wrapping Mathlib functions in a .c file however compiles fine so I'll use that for the moment.

    Thank you for your help,

    David.

  • Are there any plans to fix this pragma issue in a future release of MATHLIB? It is not desirable to have to create a C wrapper function for every MATHLIB function that is needed.

    Over the years I have found several issues where TI provided libraries simply will not compile or link under C++. It is very apparent that TI does not properly test their libraries under anything but C.

  • I agree, all libraries provided by TI should be able to be used in C++, at least under 'extern "C"', but MATHLIB is not a product of the compiler team, so we can't do anything about it.  This thread needs to be moved to a forum where MATHLIB is supported so that the maintainers can be made aware.  I don't know how to bring this to the attention of all TI library maintainers; I'll ask around internally.

  • Jeremiah Ferguson said:

    Are there any plans to fix this pragma issue in a future release of MATHLIB? It is not desirable to have to create a C wrapper function for every MATHLIB function that is needed.

    Over the years I have found several issues where TI provided libraries simply will not compile or link under C++. It is very apparent that TI does not properly test their libraries under anything but C.

    I agree with Jeremiah - I'm having the same problem (pragma errors) right now with MATHLIB.


    It would also be beneficial if the details discussed in this thread could be posted on the TI MATHLIB Wiki.....

         -     http://processors.wiki.ti.com/index.php?title=Software_libraries#MathLIB

    As a TI customer it is disappointing to see nothing on the MATHLIB FAQ page.

         -     http://processors.wiki.ti.com/index.php/Library_FAQ#MATHLIB_FAQ

  • I'll move this thread over to the C67x single core forum.  Some of the MATHLIB experts monitor that forum.

    Thanks and regards,

    -George

  • Thanks George.

    For forum records: I replied to this post to state that I find this information very important but very difficult to find.  (And to point out the MATHLIB Wiki FAQ is empty).

    I created a new thread (now closed) to discuss my specific MATHLIB efforts in order to avoid hijacking this thread.

  • I checked with some of the MATHLIB development folks.  The feedback is that this pragma issue will be fixed in the next release v3.1.0. 

    The correct pragma is:

    #pragma CODE_SECTION(".text:optci")    

    And not

    #pragma DATA_SECTION(".text:optci")

     

    In some kernels CODE_SECTION is used and in some kernels DATA_SECTION for C++.

    Only header files with DATA_SECTION is giving the error.

    Beyond that, we do not have plans to test any of the DSP libraries with C++ compiler.  We strictly use C and sometimes even ANSI C for our libraries.

    Regards,

    Travis

  • Thanks everyone.

    For the record, I've gotten MATHLIB to work in C++ by creating the C wrapper functions based on Arch's guidance.  I'm not sure if this will slow down my code any, since it's just a function call inside a function call, and now that I've figured out this method I can add new MATHLIB function calls to my program with ease in a matter of minutes.

    Travis:  Since my code now works this way, I haven't tried your pragma correction.  If I do, I'll surely post back with feedback.