How do I make a .a library?

Pages: 12
This is getting ridiculous.
Yes, well... I don't understand why...
How about someone gives a link to compile-ready files
for me to compile? Maybe my code is the problem?
closed account (z05DSL3A)
Have you thought that your toolchain may be fracked?
Try this minimal example:

1
2
3
4
5
6
7
8
9
10
11
12
13
// add.cpp
int add(int a, int b) { return a + b; }

// main.cpp
#include <iostream>

int add(int, int);

int main() {
    int a, b;
    std::cin >> a >> b;
    std::cout << add(a, b) << '\n';
}


$ clang++ -c add.cpp         # or g++
$ ar rcs libadd.a add.o
$ clang++ main.cpp -L. -ladd
$ ./a.out
3 6
9

Didn't read the thread, but can confirm the above works fine for me.
(Except, if OP is doing this on Windows, it's a.exe, not a.out)
So you would do
>.\a.exe
or just
>a


g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Last edited on
I got the same stupid error...
Should I reinstall g++, or what?
Are you on linux or windows?
Try the following with the add.o object file.
First delete libadd.a.

$ ar rcs libadd.a add.o
$ nm libadd.a

Windows.

And I got this error:
C:\TDM-GCC-32\bin\nm.exe: add.o: file format not recognized
file format not recognized

I think that's the key here.

You seem to be using a 32-bit version of TDM. Is that what you mean to do?

What is the output of the following (if you have the file command):

file add.o

add.o: Intel amd64 COFF object file, no line number info, not stripped, 6 sections, symbol offset=0x176, 16 symbols
Gosh, you were right. I had two installations, 32 and 64.
I deleted the 32 folder and everything worked well!
Thanks!
There you go! :-)
That was frustrating, although I'm sure 100 times more so for you.

Looks like there's a new tdm-gcc for gcc9. You might want to update to that.
https://jmeubank.github.io/tdm-gcc/
Ok, thank you very much! :D
Topic archived. No new replies allowed.
Pages: 12