Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I know how to create my own arduino library and use it. I am using Xcode to create a c++ project. I have the arduino library files(Servo, Wire, Keypad, etc). If I want to include the Servo.h library file in my created library, how do I go about linking that? For some reason, I can't just add the Servo.h/.cpp files in my project because then I get other linking file problems that Servo.h references and are not linked in my project. Has anyone done this before?

share|improve this question

migrated from electronics.stackexchange.com Dec 17 '14 at 7:44

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

1 Answer 1

up vote 0 down vote accepted

I can't speak for Xcode, but in general with Arduino IDEs (UECIDE excepting) if you use a library within another library, that library also has to be #included in the main sketch. That is the only way most IDEs determine which libraries need to be compiled into the finished program.

That's one of the first targets I had for UECIDE - to enable fully recursive library compilation. Any libraries found within the master header of a library will also be included for compilation - and any found in those libraries, etc. It took a lot of work (and it's by no means 100% perfect), which is why so few others do it and leave it up to the programmer to ensure the inclusion of the right sub-libraries in their sketch.

share|improve this answer
    
Yea, I guess I was just asking in general not necessarily with Xcode. If I were using Visual Studios, is there anyway I can use the current arduino library files (h/cpp) in my own library I am creating to be able to compile it before using? If I add, for example, Servo.h to my library it does not compile as there are other files Servo.h links to that I do not. Just seeing if there is an easy way to add other library files to my project to be able to compile. –  JEB Dec 17 '14 at 17:00
    
No, it takes an intelligent IDE that properly understands the concept of the Arduino library to do that. If the libraries were all pre-compiled code as .a files you'd still need to manually add all the -l... flags to the linker command, so it's not something that's unique to the Arduinosphere. We just have a different way of telling the IDE what libraries need including (#include) than "normal" systems (which would equate to -lservo -lkeyboard etc) –  Majenko Dec 17 '14 at 17:03
    
Believe I have accomplished what I wanted to do. Using the VS Visual Micro plugin. –  JEB Dec 17 '14 at 20:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.