I am working on better/re-educating myself in the ways of oop c++. One issue that I have run into is building an application with multiple class source files.
Right now I am working on a simple application that connects to a mysql database and outputs information from the table. The one issue that I have run into is that when I try to compile I get the errors below.
I have a feeling it is two possible issues, one would be my linking and the other would be how I wrote the classes. Any help with this would be greatly appreciated.
Here is my current implementation of my class files.
DbConnect.h
DbConnect.cpp
dbTest.cpp (app application)
And here is my current implementation of my makefile
Right now I am working on a simple application that connects to a mysql database and outputs information from the table. The one issue that I have run into is that when I try to compile I get the errors below.
Code:
undefined reference to `DbConnect::db_set(char const*)' undefined reference to `DbConnect::db_get()'
Here is my current implementation of my class files.
DbConnect.h
Code:
#ifndef DBCONNECT_H_ #define DBCONNECT_H_ class DbConnect { public: const char* keep_value; // private data value void db_set(const char* db_value); // public method to set value char db_get(void); // public method to get value }; #endif /*DBCONNECT_H_*/
Code:
#include "DbConnect.h" const char* keep_value; void db_set(const char* db_value){ keep_value = db_value; } const char* db_get(){ return (keep_value); }
Code:
#include <iostream> #include "DbConnect.h" using namespace std; int main(){ DbConnect hostname, datasource, username, password; hostname.db_set("test"); datasource.db_set("test"); username.db_set("test"); password.db_set("test"); cout<<"Accessing data using class\n"; cout<<"-------------------------\n"; cout<<"Data value for hostname is "<<hostname.db_get()<<"\n"; cout<<"Data value for datasource is "<<datasource.db_get()<<"\n"; cout<<"Data value for username is "<<username.db_get()<<"\n"; cout<<"Data value for password is "<<password.db_get()<<"\n"; return 1; }
And here is my current implementation of my makefile
Code:
CXXFLAGS = -O2 -g -Wall -fmessage-length=0 OBJS = dbTest.o DbConnect.o LIBS = TARGET = dbTest $(TARGET): $(OBJS) $(CXX) -o $(TARGET) $(OBJS) $(LIBS) all: $(TARGET) clean: rm -f $(OBJS) $(TARGET)
Comment