Error using API in Linux based operating system

Mr. Sujit
Mr. Sujit Altair Community Member
edited June 2022 in Community Q&A

Hello All,

I have an API script with strcpy_s functions to copy the data. In windows, it works well. I mean, I can generate .dll files and run the simulations.  However, I'm not able to generate .so file in Linux based system. It gives me error  " ‘strcpy_s’ was not declared in this scope" when in try to compile using g++ command. 

When I use different functions like strcpy and strncpy, I get errors like "invalid conversion from ‘unsigned int’ to ‘const char*’ [-fpermissive]" and "initializing argument 3 of ‘char* strncpy(char*, const char*, size_t)’ [-fpermissive]"

Please help me to resolve this error.

 

Thanks and regards,

Sujith

Tagged:

Answers

  • RWood
    RWood
    Altair Employee
    edited June 2022

    Hi,

    As you rightly point out strcpy_s is not supported by gcc and so you'll have to use either strcpy or strncpy instead, but they take a different number of arguments.

    https://cplusplus.com/reference/cstring/strcpy/

    https://cplusplus.com/reference/cstring/strncpy/

    I did update quite a few of our API tutorials source material a couple of years ago with the intention of making it OS agnostic so I'd take a look at some of those. Taking a look at the source for the first tutorial I can see there's a strncpy implementation there:

    https://community.altair.com/community?id=kb_article&sysparm_article=KB0037689

    The third argument of strncpy is the buffer length. In our tutorials you will usually see this something like "API_BASIC_STRING_LENGTH" as the third argument.

    Cheers,

    Richard

  • Mr. Sujit
    Mr. Sujit Altair Community Member
    edited June 2022

    Hi,

    Thank you for the clarification. Your answer is very helpful. I will try to modify the script using strncpy.

    Regards,

    Sujith