Have following header (and correspondent cpp) in project:
#include <string>
#include <vector>
#ifndef STRINGWORK_H
#define STRINGWORK_H
using namespace std;
vector<string> split(const string& str, const string &delimiters = " ");
string trim(string &str);
#endif // STRINGWORK_H
Building project returns linker error:
file.cpp:21: error: undefined reference to `trim(std::string&)'
if I add extern "C"
to 2nd function, project builds fine. If I also add extern "C"
to first function, get linker error again but for the 1st function:
file.cpp:16: error: undefined reference to `split'
What is the problem here? How to correctly declare such functions?
What is an undefined reference/unresolved external symbol error and how do I fix it? - does not explain things, and does not help as here we have C/C++ mixed code.