【发布时间】:2019-11-30 13:17:26
【问题描述】:
我正在尝试将我的代码分解为 C++ 中的多个文件。我的主文件是base.cpp,我试图在其中导入foo.cpp。但它在编译过程中显示以下错误。
架构 x86_64 的未定义符号: “foo()”,引用自: _main in base-a3f2f3.o ld:未找到架构 x86_64 的符号
我的 base.cpp 文件是:
#include<bits/stdc++.h>
#include "foo.h"
using namespace std;
int main(){
foo();
cout<<tot<<endl;
cout<<"bye"<<endl;
}
我的 foo.cpp 是:
#include<bits/stdc++.h>
using namespace std ;
void foo(){
cout<<"hello world"<<endl;
}
int tot = 90;
我的 foo.h 文件是:
#ifndef FOO_H
#define FOO_H
int tot;
void foo();
#endif
我使用以下命令成功编译了我的 c++ 文件: g++ -std=c++14 文件名.cpp && ./a.out
我使用 Mac。我的代码编辑器是 VS Code。
My cpp configuaration is as follows :
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
谢谢。
【问题讨论】:
-
但是我找不到如何编译我的代码?