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) 为了学习 C++,我在 Mac 上安装了带有 Catalina 的 Visual Studio Code。安装的扩展C/C++
、C/C++ Extension Pack
、C++ Intellisense
和CMake Tools
。Code 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)