【发布时间】:2020-03-22 11:46:33
【问题描述】:
我正在尝试在 Mac OS Catalina 10.15.2 上的 VSCode 上运行代码。
我在这个函数上收到这个错误。
$ g++ main.cpp
Undefined symbols for architecture x86_64:
"nalea(int)", referenced from:_main in main-508a59.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
这是我正在使用的主文件 -
#include<iostream>
#include "proba.h"
#include "constantes.h"
#include "affichage.h"
int main(){
int a = nalea(60);
std::cout<<a;
//int a = InitAffichage();
return 0;
}
这是调用函数的 proba.cpp 文件。
#include <cstdlib> // pour rand()
#include <cstdio> // pour fprintf()
#include <cmath> // pour floor()
#include "proba.h" // types et déclaration des fonctions
int nalea( int max)
{
return (int)floor(rand()*((float)max)/RAND_MAX );
}
这是 proba.h 头文件
int nalea(int max);
请帮帮我,我是 C++ 新手....
【问题讨论】:
-
您需要先发布编译器命令,然后才能有人帮助您。但是关于这个问题有上百万个问题,看看stackoverflow.com/q/12573816/9176689
-
可能没有编译 proba.cpp。
标签: c++