什么是编译时错误“架构x86_64的未定义符号”意思? [英] What does the compile-time error "Undefined symbols for architecture x86_64" mean?

查看:341
本文介绍了什么是编译时错误“架构x86_64的未定义符号”意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用C ++教科书中的示例中的相邻列表编程图类,并且使用此命令编译时:
代码:
g ++ -o prog program.cpp
...出现以下错误:

 架构x86_64的未定义符号:
_main ,引用自:
开始于crt1.10.6.o
ld:符号(s)未找到架构x86_64
collect2:ld返回1退出状态

...这是什么意思?它可能会成为我的代码的一个问题,但我觉得它可能比这更深,因为我已经为几个不同的项目获得了这个似乎莫名其妙的错误,其中许多项目都以不同的方式解决,并且不幸的是完全偶然发生。

我在某处读到它可能与我是否使用32位或64位库有关,并且标记-m32或-m64可能需要使用,但我不确定这是否适用于此。有趣的是,当我尝试添加-m64标签时,我得到了相同的确切错误,但是当我尝试使用-m32标签时,我得到了相同的错误,除了它说

 架构i386的未定义符号:
_main,引用自:
开始于crt1.10.6.o
ld:符号(s)未找到对于体系结构x86_64
collect2:ld返回1退出状态

改为。



主要我只想知道错误在说什么。我习惯于调试在代码中给出特定行的编译时错误等,但我无法从中看出类似的东西。任何想法?

如果有帮助,我使用的是Intel Core 2 Duo 2008年底的Macbook(如此是64位),并且我运行的是OS X狮子(10.7.2),我认为它是最新版本。当编译文件时,编译器会调用尝试连接器的尝试生成可执行文件。但它不能,因为你没有提供一个名为 main 的函数,这是你的程序启动时要执行的函数。



要么你不想运行链接器,因为你想分别编译几个文件,然后合并。在这种情况下,使用 -c 标志告诉编译器跳过链接阶段。



或者你想要执行编译的文件。然后你需要实现函数 main

I'm trying to program a graph class using an adjacent list from an example in my C++ text book, and when I compile using this command: Code: g++ -o prog program.cpp ...I get the following error:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

... what in the world does this mean? It may turn out to be an issue with my code, but I feel like it may be deeper than that, because I've gotten this same seemingly inexplicable error for several different projects, many of which were solved in different ways, and unfortunately completely by accident.

I read somewhere that it may have to do with whether I'm using 32 bit or 64 bit libraries, and that the tags -m32 or -m64 may need to be used, but I'm not sure if this applies here. Interestingly enough, when I tried adding the -m64 tag I got the same exact error, but when I tried using the -m32 tag I got the same error, except it said

Undefined symbols for architecture i386:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

instead.

Mainly I just want to know what in the world the error is saying. I'm used to debugging compile-time errors that give a specific line in the code, etc., but I can't discern anything like that from this. Any ideas?

If it helps, I'm using a late 2008 Macbook with Intel Core 2 Duo, (so 64-bit), and I'm running OS X Lion (10.7.2), which I think is the latest version. Also, I'm using gcc version 4.2.1.

解决方案

When you compile the file, the compiler invokes the linker which tries to generate an executable. But it cannot because you didn't provide a function named main which is the function that will be executed when your program is launched.

Either you don't want to run the linker because you want to compile several files separately then combine then. In that case, use the -c flag to tell the compiler to skip the link stage.

Or either you want to execute the compiled file. Then you need to implement the function main.

这篇关于什么是编译时错误“架构x86_64的未定义符号”意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆