I'm new to g++ and compiling my C++ code in LINUX. I'm trying to connect several .o files as .lib using g++.
This is the command that I used "g++ -o ../fuzzy/fuzzy.lib example1.o example2.o" and got this error. Even though I try to connect a single object file and make a .lib, it doesn't work.
Your help is much appreciated.
Thanks
If you are trying to build a library, the options depend on whether you want to build a static or a shared library. For example,
# shared library
g++ -shared -o name.so obj1.o obj2.o obj3.o
A static library is essentially an archive, which you can build from the .o files using the ar command.
ar <options> mylib.a obj1.o obj2.o obj3.o
If you are trying to compile an object file, you need to pass the -c option:
g++ -c ....
Otherwise, g++ attempts to compile an executable, and this requires a main function.
To make a static library, use ar:
ar rcs mylibrary.a a.o b.o c.o
To make a shared library, use gcc to link:
gcc -o mylibrary.so -shared a.o b.o. c.o
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With