Help with note-c-master on Microsoft Visual Studio

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.

Thanks

Hi Brian,

There are some options for compiling with Windows. See the comments here:

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
#if defined(_MSC_VER)
size_t strlcat(char* dst, const char* src, size_t siz)
#else
attribute((weak)) size_t strlcat(char* dst, const char* src, size_t siz)
#endif

Since the issue is the use of the Microsoft compiler, not the Windows OS

Thanks

Hi Brian,

We updated the note-c files to include your recommended change

GitHub - blues/note-c: C API for Notecard

Cheer!

1 Like

Great! I have a few other observations but I’ll hold off until I get everything working.