I have run into an odd situation with linking files in my application. I have written a method that returns data for other methods. When I use this method(with in the same class) I get this error from linking.

Any help with this is greatly appreciated

RetsParse.cpp: undefined reference to `RetsParse::rets_parse_metadata(boost::shared_ptr<librets::RetsSession>)'

Here is my current code base.

.h;

#ifndef RETSPARSE_H_
#define RETSPARSE_H_

#include "librets.h"
#include <iostream>
#include <string>
#include <vector>


class RetsParse
{
public:
	int rets_parse_idx(void);// public method to parse rets data;
	std::vector<std::vector<std::string> > rets_parse_metadata(librets::RetsSessionPtr session); 
};

#endif /*RETSPARSE_H_*/

.cpp

int rets_parse_idx(void){
			
			RetsParse metaAction;
			
			// Define session request
	        librets::RetsSessionPtr session(new librets::RetsSession("URL"));
	        session->Login("USER", "PASS");
	        
	        std::vector<std::vector<std::string> > metaVector = metaAction.rets_parse_metadata(session);
	        
	        std::cout << metaVector.size() << std::endl;
        
	        return 0;

	}

MakeFile

# =========================================================================
#     This makefile was generated by
#     Bakefile 0.2.5 (http://www.bakefile.org)
#     Do not modify, all changes will be overwritten!
# =========================================================================



# -------------------------------------------------------------------------
# These are configurable options:
# -------------------------------------------------------------------------

# C++ compiler 
CXX = g++

# Standard flags for C++ 
CXXFLAGS ?= 

# Standard preprocessor flags (common for CC and CXX) 
CPPFLAGS ?= 

# Standard linker flags 
LDFLAGS ?= 

# Set to 1 to build debug version [0,1]
DEBUG ?= 0



# -------------------------------------------------------------------------
# Do not modify the rest of this file!
# -------------------------------------------------------------------------

### Variables: ###

CPPDEPS = -MT$@ -MF`echo $@ | sed -e 's,\.o$$,.d,'` -MD -MP
RETSCOMM_CXXFLAGS = $(____DEBUG_0_p) $(____DEBUG_1_2) $(____DEBUG_3) \
	-Ilib -I/usr/include/mysql \
	-I/usr/local/include/mysql++$(CPPFLAGS) $(CXXFLAGS)
RETSCOMM_OBJECTS =  \
	retsComm_retsComm.o \
	retsComm_DbConnect.o \
	retsComm_DataParse.o \
	retsComm_RetsParse.o

### Conditionally set variables: ###

ifeq ($(DEBUG),0)
____DEBUG_0_p = -DNDEBUG
endif
ifeq ($(DEBUG),1)
____DEBUG_0_p = 
endif
ifeq ($(DEBUG),0)
____DEBUG_1_2 = -O2
endif
ifeq ($(DEBUG),1)
____DEBUG_1_2 = -O0
endif
ifeq ($(DEBUG),0)
____DEBUG_3 = 
endif
ifeq ($(DEBUG),1)
____DEBUG_3 = -g
endif


### Targets: ###

all: retsComm

install: 

uninstall: 

clean: 
	rm -f ./*.o
	rm -f ./*.d
	rm -f retsComm

retsComm: $(RETSCOMM_OBJECTS)
	$(CXX) -o $@ $(RETSCOMM_OBJECTS)  $(____DEBUG_3) $(LDFLAGS) -lmysqlpp -lmysqlclient `/usr/local/bin/librets-config --libs`

retsComm_retsComm.o: ./retsComm.cpp
	$(CXX) -c -o $@ $(RETSCOMM_CXXFLAGS) $(CPPDEPS) $<

retsComm_DbConnect.o: ./DbConnect.cpp
	$(CXX) -c -o $@ $(RETSCOMM_CXXFLAGS) $(CPPDEPS) $<
	
retsComm_DataParse.o: ./DataParse.cpp
	$(CXX) -c -o $@ $(RETSCOMM_CXXFLAGS) $(CPPDEPS) $<
	
retsComm_RetsParse.o: ./RetsParse.cpp
	$(CXX) -c -o $@ $(RETSCOMM_CXXFLAGS) $(CPPDEPS) $<

.PHONY: all install uninstall clean


# Dependencies tracking:
-include ./*.d

Dani AI

Generated

is on the right track: the linker error means the method was declared but not defined with the exact class scope and signature the linker expects. The posted .cpp shows a global int rets_parse_idx(void) (no RetsParse::), and there is no RetsParse::rets_parse_metadata(...) implementation in the snippets — that produces the undefined reference when metaAction.rets_parse_metadata(session) is emitted.

Implement the class members in the .cpp using the class scope operator and the exact parameter/type list used in the header. For example, add a definition like this to RetsParse.cpp (fill the body with the parsing logic):

std::vector<std::vector<std::string> >
RetsParse::rets_parse_metadata(librets::RetsSessionPtr session)
{
    // parse session metadata and return a vector-of-vectors
}

If rets_parse_idx is intended to be a member, give it the same treatment:

int RetsParse::rets_parse_idx(void)
{
    // body that can create a session and call rets_parse_metadata
}

Troubleshooting tips: compile the translation unit and inspect the object with nm -C to confirm the symbol is defined:

g++ -c RetsParse.cpp
nm -C RetsParse.o | grep rets_parse_metadata

A defined symbol shows as T/t; U means unresolved. If a symbol appears with a different signature, check for subtle mismatches (extra const, reference vs value, namespace differences, or different overloads). Also ensure RetsParse.cpp includes the header and that the object is actually listed and linked by the Makefile (the unit must be rebuilt after changes). These steps will resolve the undefined reference reported by the linker.

All I see in the code you posted is the function prototype for that function -- where in *.cpp or *.h file is the implementation code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.