Title: undefined reference to; class public function not accessible at link time
Tags: c++;function;class
Question: I'm trying to build a simple program where I defined a class and included it's header in Main. While linking, Linker complains about accessing any of the member function from class:
: undefined reference to voxel75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0nyFunction
even though functions are public and headers are included.
Originally I discovered the problem when creating an object of voxel - I had overloaded the default constructor, but I figure out the problem is present for any function from voxel class.
Here are some code excerpts:
voxel.hpp
class voxel
public:
//here defined some member variables
//ommited the constructor
void fillMemberValuesWithDummy();//sets all members to some dummy value
voxel.cpp
#include "voxel.hpp"
void voxel75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0illMemberValuesWithDummy()
//does the assignment to member variables
Main.cpp
#include <iostream&gt;
#include <fstream&gt;
using namespace std;
#include "voxel.hpp"
voxel someVoxel;
somevoxel.fillMemberValuesWithDummy();
I figure it is something very stupid I am (not) doing here, but can you tell me what?
Comment: which OS? Are you linking the voxel object file? Including header is not enough.

Comment: So far I programmed in windows and seems like IDE took care of linking properly (I myself have little exp with it) will check some references. I forgot to paste the int main(), but it is definitely in.

Comment: `int main()` function is missing in `Main.cpp`

Comment: Are you linking `voxel.o` (or `voxel.obj`) with `main.o` (or `main.obj`) to create the executable?  If not, that's probably the trouble.

Here is the accepted answer: You need to link all object files to get the executable. When you have just your two source files you can compile them directly:
g++ -o myprog.exe Main.cpp voxel.cpp
When you want to divide compile and link and do it this way:
g++ -c -o Main.o Main.cpp
g++ -c -o voxel.o voxel.cpp
g++ -o myprog.exe Main.o voxel.o
Feel free to create an appropriate Makefile that generates such commands.
Remove the .exe if you OS doesn't need it.
Comment for this answer: yes, this is the answer - I need to brush up on my compiling/linking. thank you !!


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:12/21/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c++><function><class>', 'Title': 'undefined reference to; class public function not accessible at link time', 'ViewCount': 101, 'id': 20721698, 'user_AboutMe': None, 'user_AccountId': 3760150.0, 'user_DisplayName': 'user3125417', 'user_Reputation': 3.0, 'user_Views': 3.0, 'user_id': 3125417.0}}