相关疑难解决方法(0)

什么是未定义的引用/未解析的外部符号错误,我该如何解决?

什么是未定义的参考/未解决的外部符号错误?什么是常见原因以及如何修复/预防它们?

随意编辑/添加您自己的.

c++ c++-faq linker-errors unresolved-external undefined-reference

1418
推荐指数
32
解决办法
52万
查看次数

VS Code will not build c++ programs with multiple .ccp source files

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.

main.ccp


#include <iostream>
#include "Cat.h" …
Run Code Online (Sandbox Code Playgroud)

c++ linux ubuntu gcc visual-studio-code

5
推荐指数
5
解决办法
6767
查看次数

如何使用visual studio代码编译多cpp文件?

我已经按照一些说明构建了Visual Studio Code C/C++编译和调试环境。但是g++编译器只能编译选定的cpp文件,因此无法编译与cpp文件相关联的.h文件。然后终端显示“架构 x86_64 的未定义符号”错误。代码如下:

.ah 文件

    int func();
Run Code Online (Sandbox Code Playgroud)

a.cpp 文件

    include <iostream>
    include "a.h"
    using namespace std;
    int func(){
        return 111;
    }
Run Code Online (Sandbox Code Playgroud)

main.cpp 文件

    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 文件。

c++ g++ visual-studio-code

4
推荐指数
4
解决办法
1万
查看次数