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

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

问题描述

我试图使用来自我的C ++教科书中的示例的相邻列表来编程图类,当我使用这个命令编译时:
代码:
g ++ -o prog program.cpp
...我得到以下错误:

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.

我读的地方可能与我使用32位或64位库有关,标签-m32或-m64可能需要使用,但我不知道这是否适用这里。有趣的是,当我试图添加-m64标签时,我得到了相同的确切错误,但是当我尝试使用-m32标签时,我得到了相同的错误,除非它说

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

主要我只是想知道在世界上的错误是什么。我习惯于调试编译时错误,给出代码中的特定行等,但我不能辨别这样的东西。任何想法?

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?

如果它有帮助,我使用的是2008年底的Macbook与Intel Core 2 Duo(64位),我运行的是OS X Lion(10.7.2),我认为是最新版本。另外,我使用gcc版本4.2.1。

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.

推荐答案

编译文件时,编译器调用链接器以生成可执行文件。但它不能,因为你没有提供一个名为 main 的函数,这是在程序启动时执行的函数。

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.

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

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.

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

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

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

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