Extern “C” error expected '=', ',', ';', 'asm' or '__attribute__' before 'int'

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Extern “C” error expected '=', ',', ';', 'asm' or '__attribute__' before 'int'



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:


foo


bar


.lib


expected '=', ',', ';', 'asm' or '__attribute__' before 'int'


#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.


#include "foobar_ble.h"


main.c



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?


extern "C"


#ifdef __cplusplus


extern "C"



Also, I cannot seem to find a good explanation of the EXPORT keyword within C. This could also be a source of my problems.


EXPORT



Tl;dr: Too dumb, too many questions, need help. Plz & thanks.





EXPORT isn't a language keyword. It's usually a preprocessor macro you need to define (or that should be defined for you by the relevant library header).
– François Andrieux
6 mins ago



EXPORT





Ahh ok. I see what you're saying. Let me update my question
– luckyging3r
4 mins ago





Looks to me like your compiler isn't one that is supported by the thing you are trying to compile. As a result, it doesn't hit any of those preprocessor conditions and never defines EXPORT or it's hitting one that isn't appropriate and expands to something your compiler can't handle.
– François Andrieux
2 mins ago



EXPORT




1 Answer
1



I think the problem is that EXPORT in your case isn't defined to anything. So it will just stay in the source code and cause a syntax error. It is probably intended to be defined to something like __declspec(dllexport) on static libraries, and to nothing (empty string) for static usage.


EXPORT



You should be able to fix it by defining EXPORT to an empty string. Depending on the library there might be a place for that in some configuration header file. Otherwise you can also use a define on compiler invocation level, but that might not be preferable, since it removes all EXPORT words from the source code.


EXPORT


EXPORT






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS