相关疑难解决方法(0)

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 Code 与 C++ 的链接错误

为了学习 C++,我在 Mac 上安装了带有 Catalina 的 Visual Studio Code。安装的扩展C/C++C/C++ Extension PackC++ IntellisenseCMake ToolsCode Runner

为了测试 VSCode,我尝试运行以下代码:

再见.cpp:

#include <iostream>

void tryMe(int s) {
    std::cout << "ok";
}
Run Code Online (Sandbox Code Playgroud)

再见.h:

void tryMe(int s);
Run Code Online (Sandbox Code Playgroud)

你好.cpp:

#include <iostream>
#include "bye.h"

int main() {
    tryMe(3);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但它不会运行,因为它会导致编译错误:

$ cd "/Users/x/Workspace/LearnCPP/" && g++ hello.cpp -o hello && "/Users/x/Workspace/LearnCPP/"hello
Undefined symbols for architecture x86_64:
  "tryMe(int)", referenced from:
      _main in hello-ef5e99.o
ld: symbol(s) not found for architecture …
Run Code Online (Sandbox Code Playgroud)

c++ linker-errors visual-studio-code

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

标签 统计

c++ ×2

visual-studio-code ×2

gcc ×1

linker-errors ×1

linux ×1

ubuntu ×1