1
votes

I don't understand why XCode is running into a linking issue when using

    string create_base_uri(string host, int port, string dbname){
      std::ostringstream ostr; //output string stream
      ostr << port; //use the string stream just like cout,
      string port_string = ostr.str();
      return "http://" + host + ":" + port_string + "/" + dbname;
}

Undefined symbols for architecture x86_64: "CouchServer::create_base_uri(std::__1::basic_string, std::__1::allocator >, int, std::__1::basic_string, std::__1::allocator >)", referenced from: CouchServer::get_document_by_id(std::__1::basic_string, std::__1::allocator >) in couch_server.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Can someone help me out?

1
Is create_base_uri defined in the class CouchServer? It doesn't look like it in the example you've given.Peter Wood
Yes. private: string create_base_uri(string host, int port, string dbname);Nick
No, that's the declaration. The definition needs to be string CouchServer::create_base_uri(string host, int port, string dbname) { //...Peter Wood
if I comment out lines that use sstream it worksNick
Your right! I'm a dorkNick

1 Answers

1
votes

You need to define the member function relative to the class:

string CouchServer::create_base_uri(string host, int port, string dbname) {
    //..
}

Instead, you're defining a free function:

string create_base_uri(string host, int port, string dbname) {
    //..
}

Interestingly, it compiles as it doesn't refer to any other members of the class. It may be better to actually make it a free function! If it is currently a private member you can put it in an anonymous namespace instead. If it's useful in other places, you could make it into a utility function.