Adding a static library to PROS

I decided this year to attempt to add classes and function definitions to my code in a format that could be distributed as a library. With limited programming knowledge, I have created two working .cpp and accompanying .h files that contain all of the code. However, when attempting to create a .a file that can be treated the same way as PROS’ “libpros.a” or OkapiLib’s “okapilib.a,” I encounter an error “member in archive is not an object.” I have confirmed that the only two files used to make my .a are two .o files made from my two .cpp files. Upon removing the .a and adding the .cpp s to src and the .h s to include, the code builds just fine. Any advice?

If you want to distribute your code as a library, you should use our template system. This will allow users to easily fetch templates and apply them to their projects. Here is a quick rundown on what to do:

  1. Edit the Makefile: Open up the file called Makefile and scroll to line 27. Change IS_LIBRARY:=0 to IS_LIBRARY:=1, LIBNAME:=libtest to LIBNAME:=your_templates_name, and VERSION:=1.0.0 to whatever your version is. Finally, change TEMPLATE_FILES=$(INCDIR)/**/*.h $(INCDIR)/**/*.hpp to TEMPLATE_FILES=$(INCDIR)/$(LIBNAME)/*.h $(INCDIR)/$(LIBNAME)/*.hpp.
  2. Organize your files: Make sure that all of your cpp files are in the directory src/name_of_your_template, and all of your header files are in the directory include/name_of_your_template. Ensure that name_of_your_template matches what you put in the Makefile exactly.
  3. Build the template: Open the PROS Integrated Terminal and run the command pros make template. This will generate a zip file containing your header files, a template.pros file, and the library.a file. You can then send this zip to other people and they are able to use it.

To use this, users will need to fetch and then apply it.

  1. Fetch it: Navigate the terminal to the folder that contains the zip file, and run the command pros c fetch You only need to do this once, and then you can apply it as many times as you want
  2. Apply it: Open a PROS terminal inside whatever PROS project you want to have this template. Then, run the command pros c apply template_name. if you have multiple version of that template and want to use not the most recent, you can run pros c apply template_name@version_number.

Hope this helps, let me know if you have any problems.


Just curious - is there a repository of available templates available in PROS or are the existence of these just known by word of mouth?

Their existence is currently just word of mouth, but we are actively working on a project called branchline that will essentially create an app store for templates in our VSCode extension and CLI.