什么是未定义的参考/未解决的外部符号错误?什么是常见原因以及如何修复/预防它们?
随意编辑/添加您自己的.
c++ c++-faq linker-errors unresolved-external undefined-reference
Note that I'm using VS Code on Ubuntu 17.10 and using the GCC Compiler.
I'm having trouble building a simple program which makes use of additional .ccp files. I'm probably missing something obvious here as I'm fairly new to programming but I'll explain what I've done so far. This is something that is stopping me from continuing with a tutorial I'm doing.
I have written a very simple program to demonstrate my point as follows.
#include <iostream>
#include "Cat.h" …Run Code Online (Sandbox Code Playgroud) 我已经按照一些说明构建了Visual Studio Code C/C++编译和调试环境。但是g++编译器只能编译选定的cpp文件,因此无法编译与cpp文件相关联的.h文件。然后终端显示“架构 x86_64 的未定义符号”错误。代码如下:
int func();
Run Code Online (Sandbox Code Playgroud)
include <iostream>
include "a.h"
using namespace std;
int func(){
return 111;
}
Run Code Online (Sandbox Code Playgroud)
include "a.h"
using namespace std;
int main()
{
int b = func();
cout << b << endl;
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio 代码将使用如下命令
g++ directory/main.cpp -o directory/main.out -g -Wall -fcolor- diagnostics -std=c++11
Run Code Online (Sandbox Code Playgroud)
此命令将引发“体系结构 x86_64 的未定义符号”错误我可以使用此新命令修复它
g++ main.cpp a.cpp -o main.out.
Run Code Online (Sandbox Code Playgroud)
所以问题是如何配置这些 json 文件来修复 g++ 编译问题。当我想使用某些库(例如 FFMpeg)时,如何正确链接 FFMpeg .h 文件。