I am trying to include a compiled library into a C project on a Nordic nrf52840. Below (as far as I understand) is a way to link to some of the methods foo
and bar
within the .lib
file for the rest of the project. When Trying to compile this with Segger Embedded Studio I get the following expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
error with the following code snippet:
#ifndef _FOOBAR_SERVICE_H_
#define _FOOBAR_SERVICE_H_
#if (defined(__linux__) || defined(__APPLE__) || defined(ARDUINO) ||
defined(__MSP430FR5969__))
#define IMPORT __attribute__ ((visibility ("default")))
#define EXPORT __attribute__ ((visibility ("default")))
#define LOCAL __attribute__ ((visibility ("hidden")))
#elif defined(_WIN32)
#define EXPORT __declspec(dllexport)
#endif
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
EXPORT int ble_foo(unsigned char *a, unsigned char *buffer); //<--(error)
EXPORT int ble_bar(unsigned char *b, unsigned char *buffer); //<--(same error)
#ifdef __cplusplus
}
#endif
#endif /* _FOOBAR_SERVICE_H_ */
The above is #include "foobar_ble.h"
included in my main.c
file.
Part of it might be my misunderstanding of extern "C"
I believe it to be a way of compiling the C code. I believe the #ifdef __cplusplus
is checking to compile as c++ so would this mean that extern "C"
is not even utilized within a C environment?
Also, I cannot seem to find a good explanation of the EXPORT
keyword within C. This could also be a source of my problems.
Tl;dr: Too dumb, too many questions, need help. Plz & thanks.