Results 1 to 4 of 4
Hi All,
I'm getting this identicaly error (obviously with different file names and classes shown) for every file I try to compile right now that has #include <string>
This particular ...
- 11-24-2011 #1
Same Error for All Compiling (String)
Hi All,
I'm getting this identicaly error (obviously with different file names and classes shown) for every file I try to compile right now that has #include <string>
This particular one is an example that is actually just trying to compile an example from the book I'm using:
Thought it was me so I spent hours yesterday trying to clean basic code up and ultimately failed, finally decided to just try to compile the cpp that is included in chapter 3 of my book that I am using to learn C++. Any ideas??Code:fig03_17.cpp:(.text+0x45): undefined reference to `GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
Here's an idea of my code, really really basic:
Account.h
Code://Chapter 3, Accounts Exercise: Accounts.h //Presents the public interface of the class //Member function definitions appear in Accounts.cpp #include <string> using namespace std; class Account { public: Account ( string ); void setAccountName ( string ); string getCourseName (); private: string accountName; };
Account.cpp
Code://Chapter 3, Accounts Exercise: Accounts.cpp //Implementations of the Accounts member-function definitions. //Some functions perform validations #include <iostream> #include "Account.h" using namespace std; Account::Account (string name) { setAccountName (name); } void Account::setAccountName (string name) { accountName = name; } string Account::getAccountName { return accountName; }
Main.cpp
Code://Chapter 3, Accounts Exercise: Main.cpp //Create and manipulate Account object #include <iostream> #include "Account.h" using namespace std; int main() { Account myAccount("Test"); }Last edited by jmadero; 11-24-2011 at 04:42 PM.
Bodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 11-25-2011 #2
Apparently, this is a linker problem and it should be solvable by adding the file with the gradebook class to your project. How you do this would vary from ide to ide. If you are not using an IDE, make sure to pass all the files into the compiler so it can link them.
If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 11-26-2011 #3
How do I "build a project" using g++. Basically I have the header file and two cpp files in one folder, assumed that doing g++ main.cpp -o main would work but apparently I need to build a project. Main.cpp is dependent on a class defined in a header file and another cpp file defines the functions in the header file. Thanks in advance
Bodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 11-26-2011 #4
In standard c (gcc compiler) I usually compile them in order such as
but with g++ it looks like you need to use the -combine flag.Code:gcc file1.c file2.c file3.c main.c -o myprog
If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.


Reply With Quote