이것은 매우 간단 할 것입니다 만, C++ 도로를 따라 가면서 저를 방해하고 있습니다. 저는 현재 가속화 된 C++를 읽고 있습니다. 그리고 나는 연습 문제 중 하나를 과도하게 사용하기로 결정했습니다. 그것은 모두 잘 작동하고 헤더와 분리 된 소스 파일로 나눌 때까지 내 코드는 잘 돌아갔다. 필자가 작성한 일부 함수가 포함 된 .cpp 소스 파일을 가져 오면 모든 것이 정상적으로 실행됩니다. 그러나 헤더 파일을 통해 함수를 가져 오려고하면 끔찍하게 실패하고 다음과 같은 오류가 발생합니다. Geany에서 gcc로 컴파일 중이며, 지금까지는 모두 잘 돌아갔다. 어떤 도움을 주셔서 감사합니다.C++ : 헤더 파일 포함 컴파일은 실패하지만 소스 cpp 파일 컴파일 포함
오류 :
g++ -Wall -o "quartile" "quartile.cpp" (in directory: /home/charles/Temp)
Compilation failed.
/tmp/ccJrQoI9.o: In function `main':
quartile.cpp:(.text+0xfd): undefined reference to `quartile(std::vector<double, std::allocator<double> >)'
collect2: ld returned 1 exit status
"stats.h"
#ifndef GUARD_stats_h
#define GUARD_stats_h
#include <vector>
std::vector<double> quartile(std::vector<double>);
#endif
"stats.cpp"
#include <vector>
#include <algorithm>
#include "stats.h"
using std::vector; using std::sort;
double median(vector<double> vec){
//code...
}
vector<double> quartile(vector<double> vec){
//code and I also reference median from here.
}
"quartile.cpp" :
#include <iostream>
#include <vector>
#include "stats.h" //if I change this to "stats.cpp" it works
using std::cin; using std::cout;
using std::vector;
int main(){
//code and reference to quartile function in here.
}
은, 대단히 감사합니다 "위법" "quartile.cpp" "stats.cpp". 책을 읽을 때 stats.h가 stats.cpp를 어떻게 찾을 것인지 모르겠다. 그냥 파이썬의 가져 오기처럼 마술을 사용한다고 믿었다. – Chazadanga