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:
- Edit the Makefile: Open up the file called
Makefile
and scroll to line 27. ChangeIS_LIBRARY:=0
toIS_LIBRARY:=1
,LIBNAME:=libtest
toLIBNAME:=your_templates_name
, andVERSION:=1.0.0
to whatever your version is. Finally, changeTEMPLATE_FILES=$(INCDIR)/**/*.h $(INCDIR)/**/*.hpp
toTEMPLATE_FILES=$(INCDIR)/$(LIBNAME)/*.h $(INCDIR)/$(LIBNAME)/*.hpp
. - 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 directoryinclude/name_of_your_template
. Ensure that name_of_your_template matches what you put in the Makefile exactly. - 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.
- Fetch it: Navigate the terminal to the folder that contains the zip file, and run the command
pros c fetch full_name_of_zip_file.zip
. You only need to do this once, and then you can apply it as many times as you want - 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 runpros c apply template_name@version_number
.
Hope this helps, let me know if you have any problems.
8 Likes
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.
6 Likes