[英]In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status
I'm new to g++ and compiling my C++ code in LINUX. 我是g ++的新手,在LINUX中编译我的C ++代码。 I'm trying to connect several .o files as .lib using g++. 我正在尝试使用g ++将几个.o文件连接为.lib。
This is the command that I used "g++ -o ../fuzzy/fuzzy.lib example1.o example2.o" and got this error. 这是我使用“g ++ -o ../fuzzy/fuzzy.lib example1.o example2.o”的命令并得到了这个错误。 Even though I try to connect a single object file and make a .lib, it doesn't work. 即使我尝试连接单个目标文件并生成.lib,它也不起作用。
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
命令从.o
文件构建存档。
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: 如果您尝试编译目标文件,则需要传递-c
选项:
g++ -c ....
Otherwise, g++
attempts to compile an executable, and this requires a main
function . 否则, g++
尝试编译可执行文件,这需要一个main
函数 。
To make a static library, use ar
: 要创建静态库,请使用ar
:
ar rcs mylibrary.a a.o b.o c.o
To make a shared library, use gcc
to link: 要创建共享库,请使用gcc
链接:
gcc -o mylibrary.so -shared a.o b.o. c.o
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.