Compile Error: linker command failed with exit code 1
Compile Error: linker command failed with exit code 1
我是 C++ 的新手,正在尝试编写一个简单的程序。
但是我得到这个错误:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 0.4s with exit code 1]
来自这段代码:
#include <iostream>
using namespace std;
// Lets add some global variables
int FirstNumber = 0;
int SecondNumber = 0;
int MultiNum = 0;
void MultiNumbers ()
{
cout << "Enter the first number: ";
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber;
// Multiply two numbers...
MultiNum = FirstNumber * SecondNumber;
// Display result
cout << "Displaying result from MultiNumbers(): ";
cout << FirstNumber << " x " << SecondNumber;
cout << " = " << MultiNum << endl;
}
int Main ()
{
cout << "This program will help you to multiply two numbers" << endl;
// Now call the function that does all the work
MultiNumbers();
cout << "Displaying from main(): ";
// This line will not compile and work because of the global variables
cout << FirstNumber << " x " << SecondNumber;
cout << " = " << MultiNum << endl;
return 0;
}
我已经尝试在 sublime 上检查我的编译器,在终端中使用 g++ -o test test.cpp
进行编译
但似乎无济于事。
我的理解是,我在上面定义了 MultiNumbers() 然后我在 Main() 中调用它...但我似乎错过了什么...
建议?
C++ 区分大小写。这个:
int Main ()
应该是
int main ()
我是 C++ 的新手,正在尝试编写一个简单的程序。
但是我得到这个错误:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 0.4s with exit code 1]
来自这段代码:
#include <iostream>
using namespace std;
// Lets add some global variables
int FirstNumber = 0;
int SecondNumber = 0;
int MultiNum = 0;
void MultiNumbers ()
{
cout << "Enter the first number: ";
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber;
// Multiply two numbers...
MultiNum = FirstNumber * SecondNumber;
// Display result
cout << "Displaying result from MultiNumbers(): ";
cout << FirstNumber << " x " << SecondNumber;
cout << " = " << MultiNum << endl;
}
int Main ()
{
cout << "This program will help you to multiply two numbers" << endl;
// Now call the function that does all the work
MultiNumbers();
cout << "Displaying from main(): ";
// This line will not compile and work because of the global variables
cout << FirstNumber << " x " << SecondNumber;
cout << " = " << MultiNum << endl;
return 0;
}
我已经尝试在 sublime 上检查我的编译器,在终端中使用 g++ -o test test.cpp
进行编译但似乎无济于事。
我的理解是,我在上面定义了 MultiNumbers() 然后我在 Main() 中调用它...但我似乎错过了什么...
建议?
C++ 区分大小写。这个:
int Main ()
应该是
int main ()