首页 > 解决方案 > Visual Studio Code C++ 包含本地文件

问题描述

几天以来,我试图包含我的自定义头文件

你好世界.cpp:

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

int main(){
    printHelloWorld();
    return 0;
}

我的函数.cpp

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


int printHelloWorld(){
    std::cout <<"Hello World" << std::endl;
    return 0;
} 

我的函数.h

#pragma once
int printHelloWorld();  

文件夹结构

错误信息:

[Running] cd "c:\Users\juriw\Desktop\Projekts\C++\Learning\" && g++ HelloWorld.cpp -o HelloWorld && "c:\Users\juriw\Desktop\Projekts\C++\Learning\"HelloWorld
C:\Users\juriw\AppData\Local\Temp\ccCJZTCT.o:HelloWorld.cpp:(.text+0xc): undefined reference to `printHelloWorld()'
collect2.exe: error: ld returned 1 exit status

到目前为止有什么问题吗?

我多次重新安装 vsc、扩展和编译器。我是新手,不知道代码是错误的还是我搞砸了配置。还有什么我可以告诉你的,以确定问题吗?

标签: c++visual-studio-code

解决方案


推荐阅读