Hello. I want to know how to make a library (.a file)
that I can use in projects on all operating systems/devices
(3ds, etc.) How would I go about doing this in VS2019?
CMake is a cross-platform tool for making build-tools. It allows you to write one codeset to specifiy the build tools you want, and then it will build the tools for you depending on what system you're using. So, on Linux, it will create your makefiles for you, and on Windows it will create the Visual Studio solutions and projects, etc.
It's complicated and difficult to learn, and not necessary for this.
If you're using gcc, this looks like a good start for you:
CMake is a cross-platform tool for making build-tools. It allows you to write one codeset to specifiy the build tools you want, and then it will build the tools for you depending on what system you're using.
I'm not sure I agree with you there, it is a cross-platform build system (?) "CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice." -- https://cmake.org/
and wrote:
It's complicated and difficult to learn, and not necessary for this.
You find it complicated and difficult to learn...okay. I think the basics are pretty easy to get you stated. As to if it's necessary, the OP seems to want a single codebase built out to several different platforms, what do you suggest?
Ah, I'd missed that the OP wanted this for multiple platforms. So it might be suited to the OP's requirements.
I stand by what I said about it being rather complicated. I mean, it's doing a very complicated and difficult job, so I wouldn't expect it to be simple to learn and use. It's an extremely powerful and useful tool, and it's one I use myself - I would never go back to trying to maintain multiple build sustems again. It's no more complicated than it needs to be, and there's no need to jump to its defence.
But it's not something I would expect someone who's still fairly close to the start of the programming learning curve to learn easily.
To the OP: what build tools are you already using on the multiple platforms you want to develop on?
Ah, I'd missed that the OP wanted this for multiple platforms.
Can't blame you for that, I missed it's importance with my first reply.
I wasn't jumping to cmakes defence or attacking you or anything like that, I was just a bit surprised by what you wrote. I guess I have the view that it is best to start using it early while your demands on it are on the relatively easier end of the learning curve...and the OP mentioned Visual Studio and the tooling for cmake it it look good...
If you have mingw on your computer (gcc, g++ e.t.c.) , then it is easy to make a static (.a) library.
g++ -c myfile.cpp
(This gets you myfile.o)
then
ar rcs -o libmyfile.a myfile.o
The output file is libmyfile.a
(You don't need any int main() in your myfile.cpp), only your functions.
I can point you to a mingw .7z compressed file if you want, no installation, just unzip somewhere and put the bin folder on path.
Then you will have gcc, g++, gnu fortran, and many other useful functions at hand.
Whether or not your newly created libmyfile.a will do for Visual Studio C++ I don't know. I know than many libraries (example: gmp) are from gcc (gnu project).
Ok, so, I figured out how to build a library, but when I try to compile,
("g++ -o main main.cpp -L. libGUI.a")
I get the following error:
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libGUI.a: error adding symbols: archive has no index; run ranlib to add one
Any idea why?
EDIT: The compile commands for the library are as follows:
Range from 100000000000000000 to 100000000000000900
100000000000000003 Prime
100000000000000013 Prime
100000000000000019 Prime
100000000000000021 Prime
100000000000000049 Prime
100000000000000081 Prime
100000000000000099 Prime
100000000000000141 Prime
100000000000000181 Prime
100000000000000337 Prime
100000000000000339 Prime
100000000000000369 Prime
100000000000000379 Prime
100000000000000423 Prime
100000000000000519 Prime
100000000000000543 Prime
100000000000000589 Prime
100000000000000591 Prime
100000000000000609 Prime
100000000000000669 Prime
100000000000000691 Prime
100000000000000781 Prime
100000000000000787 Prime
100000000000000817 Prime
100000000000000819 Prime
100000000000000871 Prime
100000000000000889 Prime
Press any key to continue . . .
My g++ version is 8.1.0, 64 bits.
I keep the .a file in the same folder as the C++ test file.
Try omitting the
extern "C++"
in the test file.
I didn't think there would be a problem within g++, but using the lib with visual C++ maybe, but I cannot test (I don't have visual C++).
Did you use ar rcs to convert from .o to .a?
Try using the .o file only
g++ -o useprimes.exe useprimes.cpp primes.o
It works here.
Are your symbols present?
try
nm libprimes.a
Here are my results
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
C:\Users\Computer\Desktop\fb\C++\TESTERS>nm libprimes.a
primes.o:
0000000000000000 b .bss
0000000000000000 d .data
0000000000000000 p .pdata
0000000000000000 p .pdata$_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsrSt12__is_integerIT_E7__valueEdE6__typeES3_
0000000000000000 r .rdata
0000000000000000 r .rdata$zzz
0000000000000000 t .text
0000000000000000 t .text$_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsrSt12__is_integerIT_E7__valueEdE6__typeES3_
0000000000000000 r .xdata
0000000000000000 r .xdata$_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsrSt12__is_integerIT_E7__valueEdE6__typeES3_
0000000000000000 T _Z7isprimey
0000000000000000 T _ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsrSt12__is_integerIT_E7__valueEdE6__typeES3_
U sqrt
They have dll hell, which I think encompasses .a files.