Jacko Jacko - 1 year ago 381
C++ Question

strcpy_s not working with gcc

I have a C++11 project, and I added some

method calls.
This works on windows, but when compiling on gcc, there is an error
stating that
symbol is not found.

I did add the line

#define __STDC_WANT_LIB_EXT1__ 1

to the code, to no avail.

Answer Source

strcpy_s and friends are not a part of C++ just yet. It seems that C++17 will have them, but as of now providing them is up to the implementations. It seems glibc doesn't.

In fact, according to the cppreference, __STDC_WANT_LIB_EXT1__ will only work if __STDC_LIB_EXT1__ is defined. On my Arch Linux it isn't.

#ifdef __STDC_LIB_EXT1__
constexpr bool can_have_strcpy_s = true;
constexpr bool can_have_strcpy_s = false;

Why don't you use strncpy, though?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download