Creating your own libraries

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
CoconutDug
Posts: 22
Joined: September 7th, 2014, 4:44 pm

Creating your own libraries

Post by CoconutDug » January 18th, 2017, 10:12 am

So during my learning travels, I have come across making my own libraries. Creating a static library project and then doing the whole Add New Reference and Additional Include Directories thing. Not sure if I am explaining myself in proper technical terms here... But hopefully you guys who know what you are doing will know what I mean.

Before anything else, I would like to emphasise that I am not trying to say that Chili is wrong and I am right, I am just trying to learn. So my question is why is that not used in the tutorials? From what I have seen, it would seem you would want things like the Vec2 and Mat3 classes(from Thrust/HUGS) in a library project and not in the proper project.

Have things changed now so it is no longer any better to do it this way?
Was it simply that Chili did not want to teach that for a reason or another?
Was it something else entirely?

Thank you in advance

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Creating your own libraries

Post by albinopapa » January 18th, 2017, 11:32 am

So as far as creating your own library, I've messed around with creating my own static libs, and it's a pain in the butt unless until you are finished with the lib.

The easiest way though is to have two projects in the same solution. One that you work on the lib file and one that is used to test it. When you are done adding/changing the lib then you can store that in a place and use it in any project you want.

I think the reason Chili didn't go that route is because the tuts were mostly about programming and you were always adding stuff to the "core" library...ie the framework like extra graphics functions or the Mat3,Vec2...ok maybe not the Vec2. I just think it would have distracted from the main focus of what he was trying to cover if he had to add the changes then recompile the lib then copy it over to the folder where it's stored and used.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Creating your own libraries

Post by chili » January 18th, 2017, 1:17 pm

yeah, not really worth it during dev, even if it is stable. If it's stable, it won't get recompiled anyways, no issue. If you are going to distro to other as a library/api, then it makes sense.
Chili

User avatar
cyboryxmen
Posts: 190
Joined: November 14th, 2014, 2:03 am

Re: Creating your own libraries

Post by cyboryxmen » January 19th, 2017, 11:32 am

If you are looking into creating different libraries and sharing them among your applications, I suggest that you adapt Microsoft's recommended single solution project structure. Basically, all your projects from your static and dynamic libraries to your various applications will be placed in one single solution. This is the simplest and most convenient setup that you can do and it has a ton of quality of life benefits.

For one, you no longer have to worry about opening multiple solutions to change your various libraries, then compile them, then copy and paste the headers and binaries into your application projects, then compile those only to realise that you have a bug and start the whole process again. With everything in one solution, you can just conveniently access the projects to be changed from your solution explorer and compile once. With the projects all being in the solution root folder, it's easier to link them together with relative addresses rather than hard coded ones. That way, you can move the solution folder and the addresses would still be valid. Having live project references enables IDE features like intellisense and find and replace making refactoring an ease.

The only real disadvantage I've encountered with this structure so far is when it comes to redistributing the code publicly. If I want to distribute my open source libraries individually through git, setting up separate repositories for each of them can be a hassle. It's not impossible but you do need to do a lot of setup to make it work. The way I'll do it is to make a bunch of "release branches" that pulls specific files from an offline "main branch". These branches will set up their individual solutions differently and will push their content to the remote repo that you are publishing your project on like github. Not that I would ever want to inflict terror upon the world by showing them my complicated template-metaprogramming code. Really, this isn't much of a disadvantage for most people that don't bother with the open source community or just simple want to spare the world from their incomprehensible coding style.
Zekilk

CoconutDug
Posts: 22
Joined: September 7th, 2014, 4:44 pm

Re: Creating your own libraries

Post by CoconutDug » January 19th, 2017, 2:40 pm

Cool, thanks guys! You've been very helpful! And given me plenty to think about.

Post Reply