我试图从我的main.cpp文件中运行一个函数,该函数需要一个字符串和命令行参数。这些是我的文件的样子。 (我排除了不必要的include
和变量,因为我认为它们与该问题无关)
main.cpp
#include "lib/run.h"
int main(int argc, char *argv[]){
kiwi_process runfile;
runfile.run(input, argv);
}
lib/run.h
class kiwi_process {
public:
void run(std::string content, char** args);
};
lib/run.cpp
#include <iostream>
#include <string>
#include "run.h"
int kiwi_process::run(std::string content, char** args){
std::cout << content;
}
我正在使用
g++ -o kiwi main.cpp -std=gnu++17
那是错误的
Undefined symbols for architecture x86_64:
"kiwi_process::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char**)", refere
nced from:
_main in main-8b6378.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我在做什么错了?