简体   繁体   English

函数`_start':(。text + 0x20):未定义引用`main'colle2:ld返回1退出状态

[英]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.

相关问题 编译问题:在函数“_start”中:未定义对“main” collect2 的引用:错误:ld 返回 1 个退出状态 - Compiling problem : In function `_start': undefined reference to `main' collect2: error: ld returned 1 exit status ...未定义引用... collect2:ld返回1退出状态 - … undefined reference to … collect2: ld returned 1 exit status C++ 中的编译错误:对“main”collect2 的未定义引用:错误:ld 返回 1 个退出状态 - Compilation Error in C++: undefined reference to `main' collect2: error: ld returned 1 exit status g ++链接问题:在函数`_start'中:(。text + 0x20):对'main'的未定义引用 - g++ link problems: In function `_start': (.text+0x20): undefined reference to `main' crt1.o:在函数_start中:(.text + 0x20):对main的未定义引用 - crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2:错误:ld 返回 1 退出状态未定义的引用 - collect2: error: ld returned 1 exit status undefined references 对 `print(char const (*) [80], int, int)&#39; collect2 的未定义引用:错误:ld 返回 1 个退出状态 - undefined reference to `print(char const (*) [80], int, int)' collect2: error: ld returned 1 exit status collect2: ld 返回 1 个退出状态 - collect2: ld returned 1 exit status 未定义的引用和collect2:错误:ld返回1 - Undefined reference and collect2: error: ld returned 1 链接错误:collect2:错误:ld返回1退出状态 - Linking error : collect2: error: ld returned 1 exit status
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM