[英]CPP Calling a function from another .cpp file
我有3個檔案。
main.cpp
:
#include <iostream>
#include "function.h"
using namespace std;
int main() {
abc();
return 0;
}
第二個是function.h
:
#pragma once
#include <iostream>
void abc();
最后一個是function.cpp
:
#include "function.h"
void abc() {
std::cout << "ABC!" << std::endl;
}
當我嘗試編譯它時,我得到了abc()
鏈接器錯誤的多個定義。 如何解決? 如何從另一個文件執行功能?
您應該在 抱歉,我之前的回答是錯誤的。 main.cpp
包含function.cpp
請使用g++ main.cpp function.cpp
編譯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.