Click here to Skip to main content
15,400,433 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys,
Whenever I need to change my pc, I'm haunted by the thoughts of rebuilding external libraries.
Some libraries have step-by-step insturctions which prevents it from becoming a challenge but some libraries like libpqxx(postgresql's c++ library) doesn't give proper instructions and it usually takes 8+ hours for me to find the right way.

Apparently last time I thought I found the right way, I was mistaken.

Now my code works on release mode but doesn't work on debug mode and unfortunately my heart is not ready for another 8+ hours session. I feel like throwing a tantrum, crying and screaming like a spoiled brat. Really, this is scary.

The problem is no matter how I tried to learn the details of cmake / make etc. to build the external libraries in detail, I couldn't find a proper/easily understandable source.


The instructions given by external library websites usually say things like adding options/properties. for example boost library says : "invoke :
b2 --build-dir=build-directory toolset=toolset-name --build-type=complete stage
"

Now , what are these codes? are they defined by the library's coders or are they cmake/make codes that applies to every build session?

Do I need different & specific instructions to build every different library?
Or can I just learn this info and come of with how to build a specific library?

And for all this informations, can you suggest me a good source to start with? Because I want to build external libraries without being unaware of what I'm doing. Thanks alot!


P.s. I'm using visual studio 2019 if that's important.(sometimes I use vs itself to build some libraries)

What I have tried:

-How to build libpqxx
-Googling how to use cmake
-Googling how to use make
etc.
Posted
Updated 20-Oct-21 5:21am

I use VS19 also and I make libraries all the time, no pun intended. Portability to other environments is of zero concern for me so I just use VS19's built-in settings to make it happen. I select a configuration type of static library which is under "Configuration Properties/General" then select an Output Directory and Target Name, also on that tab, and then build it. That's pretty much all there is to it. There are settings under Code Generation that are very important like Runtime Library type. That has to agree with the application being linked with to build correctly. For that reason, I usually have options for both static and dynamic RTLs and debug and release mode builds and I use different naming suffixes for each type. For example, MyLibraryDMS64.lib would be a debug, multibyte, static RTL, 64-bit mode version of MyLibrary. I then use a library selection header with pragmas to automatically select the right version of the library for the application to link with. If your libraries have a limited range of use this might not be important to you.

I can elaborate on this if more explanation is needed.
   
v2
Comments
Weird Japanese Shows 20-Oct-21 11:49am
   
Hello, thanks for detailed answer , I really appreciate it . But isn't this for building your own libraries from your own source codes? Or do you use this steps to build external libraries as well?
Rick York 20-Oct-21 16:00pm
   
I do this for both mine and others. Lots of people like cmake these days but I just use VS19 projects. I find that it's usually not very difficult to build a project for most libraries. I did this for a few third-party libraries just last week. For the most part, it was just a matter of getting the definitions straight. As long as there isn't any weirdness in the build process this is fairly straight-forward. VS19 supports pre and post-build options so most weirdness can be accomadated.
Weird Japanese Shows 20-Oct-21 17:50pm
   
Thanks alot, it works!

I had to use cmake to build .sln files. But after that , did all the configurations and building on visual studio. I've tried that earlier but it was not working as it's supposed to. But thanks to the modifications you suggested, it works now.
merano99 20-Oct-21 16:58pm
   
If you only use Visual Studio the solution is ok.
If the lib should also be usable for compilers other than Visual Studio, it would be advisable get rid of name mangling (also name decoration).
Weird Japanese Shows 20-Oct-21 17:52pm
   
I'm using only visual studio. So yeah, it works great for me.
This is the Quick Answers forum, and there is nowhere near enough space (or time) to provide product tutorials. You will need to find them for yourself. For example: CMake Reference Documentation — CMake 3.22.0-rc1 Documentation[^], make(1) - Linux man page[^] etc.
   
Comments
Weird Japanese Shows 20-Oct-21 11:19am
   
Yes, googling "how to use cmake & how to use make" also took me to the pages you've suggested, but they are just too complicated. That's why I'm trying to find a simpler source but thanks anyways.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900