Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 4 months ago.
Using Custom Libraries gives "namespace" error
I am trying make my own .h and .c files to make my own library. The main program looks like this:
include "myLib.h" DigitalOut led1(LED1); int main() { while(1) { blinkOnce(led1); } }
while my library files look like this:
//myLib.h #include "mbed.h" void blinkOnce(DigitalOut myled);
//myLib.c #include "myLib.h" void blinkOnce(DigitalOut myled) { myled = 1; wait(0.2); myled = 0; wait(0.2); }
However this gives identifier "namespace" undefined error. If I write the entire function definition in the .h file itself, the program compiles flawlessly. What is the problem and how can it be rectified?
1 Answer
11 years, 4 months ago.
Hi Rachit,
Should be a simple fix. You are using C++, so your file extension for the source file should be .cpp
The actual error is explained by the fact it is therefore compiling it as C, comes across "namespace" keyword in one of the libraries which is not part of C so claims the identifier is not defined.
Simon