- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是编程的新手,有一个非常基本的问题可能会在其他线程中得到解答,但我认为它们太高级了,我无法理解如何回答。到目前为止,我实际上已经在此站点上找到了很多答案,但这是第一个迫使我创建帐户并询问的问题。 无论如何,我正在 linux mint 18.3 上运行一个非常基本的示例程序。现在我已经看到这个确切的代码在装有 Windows 8 的机器上工作,我相信所以我想知道这是否可能是问题所在。我创建了一个类,当我插入我的对象然后构建并运行时,我得到:
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o||在函数 _start':|
main'|
(.text+0x20)|| undefined reference
这是完整的代码:
#include <iostream>
#include "Gladius.h"
using namespace std;
int main()
{
Gladius io;
return 0;
}
这是非常基本的。这是.h
#ifndef GLADIUS_H
#define GLADIUS_H
class Gladius
{
public:
Gladius();
};
#endif // GLADIUS_H
和类的 .cpp。
#include "Gladius.h"
#include <iostream>
using namespace std;
Gladius::Gladius()
{
cout << "The Gladius is a short sword" << endl;
}
我知道这看起来非常简单,但我只是在学习编码,我一直在寻找为什么这不起作用的解释,但我看到它在另一台电脑上完全按原样工作。无论如何,我们将不胜感激。
这是我在命令行中找到的内容,如果这回答了您关于 cmd 中的内容的问题。
g++ -Wall -fexceptions -g -std=c++11 -Wall -I -c/home/gator/Documents/Spartan1/Gladius.cpp -o obj/Debug/Gladius.o/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:在函数 _start' 中:
main' 的 undefined reference collect2:错误:ld 返回 1 退出状态
(.text+0x20): 对
最佳答案
了解编译器选项(gcc/g++ 编译器):
所以当你运行的时候
g++ filename.cpp -o executable_name
,您生成一个可以执行的应用程序。
问题是当您尝试编译“Gladius.cpp”并且编译器正在尝试搜索 main() 定义时,您正在编译、汇编和链接。
所以在你的情况下,编译步骤是:
首先编译“Gladius.cpp”并生成目标文件“Gladius.o”:
g++ -Wall -fexceptions -g -std=c++11 -c Gladius.cpp
接下来编译“main.cpp”并生成目标文件“main.o”:
g++ -Wall -fexceptions -g -std=c++11 -c main.cpp
通过链接“main.o”和“Gladius.o”生成可执行文件
g++ -Wall -fexceptions -g -std=c++11 -o main main.o Gladius.o
现在你可以运行“main”了:
./main
关于c++ - 为什么我得到 "undefined reference to main",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48940315/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!