Use Custom Static Library

Has anyone had luck creating and using custom static libraries in c using VS Code and the VEX extension? I’m pretty sure I correctly created a static library file called libcustom.a.

In a new empty V5 template, I copied the library file into the build folder, the library header file into the include folder. In the mkenv.mk file I added -L"$(BUILD)" to the end of the linker flags and -lcustom to the beginning of the LIBS group.

When I try to build I get an “undefined reference” error to the function that I’m trying to call in my custom library.

Any ideas what I’m missing or doing wrong? Is there a tutorial online for doing this in VS Code with the VEX extension?

Thanks!

yes, you can do this but will need to update the makefile as you have found. I don’t usually put the library in the build folder as it may get deleted there when the project is cleaned. I’ll find an example later when I get time.

Is the library written in C or C++ ? If C, don’t forget the declare functions as extern “C” or the C++ code will not find them due to name mangling.

Ah!!! Extern “C” was indeed the problem. I also moved the library out of the build directory. Thanks so much!

Just curious, what are you working on ? I assume not for student use.

Mostly just playing around for fun, but some of our students have talked about developing a library for odometry, etc. Are there specific guidelines for legal software use beyond no code written by adults/coaches. I’m curious if there are special allowances for PROS and the libraries in their ecosystem. Example: LemLib seems popular with many of the advanced teams even though they did not contribute to the code. Are other teams allowed to use code/libraries written by other teams?

I do want to make sure our teams are following all the rules! Please let me know if there’s a resource where this is all explained.

Check the Game Manual G4 in particular.

and this Q&A:

Also, if your team is middle school, many of the foundational concepts mathematically are not yet taught or presented. Also, if team does not know how libraries are built and link, you should likely not be doing it for them - they can copy and paste.

This all makes sense. I guess I would lean towards discouraging the use of any code not developed by the team as that best fits the overall mission and avoids the grey area. :wink: