2

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

4

2 回答 2

4

如果您尝试构建库,选项取决于您是要构建静态库还是共享库。例如,

# shared library
g++ -shared -o name.so obj1.o obj2.o obj3.o

静态库本质上是一个存档,您可以.o使用ar命令从文件构建它。

ar <options> mylib.a obj1.o obj2.o obj3.o

如果您尝试编译目标文件,则需要传递-c选项:

g++ -c ....

否则,g++尝试编译可执行文件,这需要一个main函数

于 2013-05-14T21:09:58.567 回答
4

要制作静态库,请使用ar

ar rcs mylibrary.a a.o b.o c.o

要创建共享库,请使用gcc链接:

gcc -o mylibrary.so -shared a.o b.o. c.o
于 2013-05-14T21:31:28.307 回答