Thanks in advance for the help.
I am putting together a software prototype to test my Notecard. I have found it easier to build prototypes on MSVC because my embedded platform tends to be Atmel Studio. Thus I avoid the horrors of Arduino and having to burn code into a board to get started.
The note-c-master library appear written for gcc, which has
attribute((weak)) // underscore underscore attribute underscore underscore ((weak))
(see in n_str.c used twice)
Microsoft C doesn’t support
attribute((weak)). It seems the equivalent is
__declspec(selectany) //underscore underscore declspec
Changing the code to __declspec(selectany) removes most of the errors but results in 2 errors
Error C2496 ‘strlcpy’: ‘selectany’ can only be applied to data items with external linkage
However, simply removing
attribute((weak)) allows the code to compile.
The problem is I have no idea what
attribute((weak)) does so I don’t know whether this will cause a problem down the line.
This is obviously not urgent but since I am not the only person who uses MSVC it might be worth addressing.
There are some options for compiling with Windows. See the comments here:
void (*free_fn)(void *ptr);
typedef int Jbool;
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 2 define options:
N_CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
N_CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
N_CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
However: I don’t think it resolves your specific case as attribute(weak) is hard-coded in
n_str.c. Let me see what we can do, and I’ll follow up.
Indeed, I verified that that path is taken by the compiler but the problem remains. No rush: I can apparently get things to compile so I’ll be able to step through, etc.
edit this is what I did
size_t strlcat(char* dst, const char* src, size_t siz)
attribute((weak)) size_t strlcat(char* dst, const char* src, size_t siz)
Since the issue is the use of the Microsoft compiler, not the Windows OS
We updated the
note-c files to include your recommended change
GitHub - blues/note-c: C API for Notecard
Great! I have a few other observations but I’ll hold off until I get everything working.