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

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

问题描述

我正在尝试使用 C++ 教科书中示例中的相邻列表对图形类进行编程,当我使用以下命令进行编译时:代码:g++ -o prog 程序.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?

如果有帮助,我正在使用带有 Intel Core 2 Duo 的 2008 年末 Macbook(所以是 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天全站免登陆