Reputation: 885
I have a very interesting error that I am having a hard time root out. Maybe someone here can shed some light.
So I Have 3 files, one header file and 2 source files. My header file contains my class definition. One of my source files contains all of the class implementation. I decided to create a new file in order to help organize my source a little bit more and give it some structure.
When I have all of my code in the one source file, it compiles fine.
However, when I create a new source file and add in the include statement:
#include "UI/OmniFEM.h"
I receive the following error
./Debug/UI_mainOmniFEMUI.cpp.o:/home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:57: first defined here ./Debug/UI_test.cpp.o:(.rodata+0x30): multiple definition of
OmniFEMMainFrame::sm_eventTable' ./Debug/UI_mainOmniFEMUI.cpp.o:(.rodata+0x30): first defined here ./Debug/UI_test.cpp.o: In function
OmniFEMMainFrame::GetEventHashTable() const': /home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:57: multiple definition ofOmniFEMMainFrame::GetEventHashTable() const' ./Debug/UI_mainOmniFEMUI.cpp.o:/home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:57: first defined here ./Debug/UI_test.cpp.o: In function
wxEventTableEntry': /usr/include/wx-3.0-unofficial/wx/event.h:3201: multiple definition ofOmniFEMMainFrame::sm_eventHashTable' ./Debug/UI_mainOmniFEMUI.cpp.o:/usr/include/c++/4.8/ext/atomicity.h:49: first defined here ./Debug/UI_test.cpp.o: In function
wxWindowBase::CanBeFocused() const': /home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:57: multiple definition ofOmniFEMMainFrame::sm_eventTableEntries' ./Debug/UI_mainOmniFEMUI.cpp.o:/home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:57: first defined here ./Debug/UI_test.cpp.o: In function
wxMDIParentFrameBase::OnCreateClient()': /home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:76: multiple definition ofwxCreateApp()' ./Debug/UI_mainOmniFEMUI.cpp.o:/home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:76: first defined here ./Debug/UI_test.cpp.o: In function
main': /home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:76: multiple definition ofmain' ./Debug/UI_mainOmniFEMUI.cpp.o:/home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:76: first defined here ./Debug/UI_test.cpp.o: In function
wxGetApp()': /home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:76: multiple definition ofwxGetApp()' ./Debug/UI_mainOmniFEMUI.cpp.o:/home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:76: first defined here ./Debug/UI_test.cpp.o: In function
wxMDIParentFrameBase::ArrangeIcons()': /home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:57: multiple definition of `wxTheAppInitializer' ./Debug/UI_mainOmniFEMUI.cpp.o:/home/philm/GitHub/Omni-FEM/./Include/UI/OmniFEM.h:57: first defined here
The point is is this, I receive multiple first defined here errors. I am not sure why because I only have one line of code in the source file which is the include statement for the header file. When I remove this statement, the code compiles just fine again.
I did not find it necessary to post the code because again, the source file is empty save for the single line for the include statement. However, if it helps the community, please let me know and I will post the source for the class implementation.
For those curious, I am using ubuntu 14.04 and the codelite IDE.
EDIT:
Per a user request, here is the code for my other source file:
#include "UI/OmniFEM.h"
bool OmniFEMApp::OnInit()
{
OmniFEMMainFrame *frame = new OmniFEMMainFrame("Omni-FEM", wxPoint(50, 50), wxSize(450, 340) );
frame->Show( true );
return true;
}
OmniFEMMainFrame::OmniFEMMainFrame(const wxString &title, const wxPoint &pos, const wxSize &size) : wxFrame(NULL, wxID_ANY, title, pos, size)
{
/* Initilize variables */
wxMenuBar *menuBar = new wxMenuBar;
wxMenu *menuFile = new wxMenu;
wxMenu *menuEdit = new wxMenu;
wxMenu *menuView = new wxMenu;
wxMenu *menuMesh = new wxMenu;
wxMenu *menuProblem = new wxMenu;
wxMenu *menuHelp = new wxMenu;
/* This creates the main menu Bar at the top */
menuBar->Append(menuFile, "&File");
menuBar->Append(menuEdit, "&Edit");
menuBar->Append(menuView, "&View");
menuBar->Append(menuMesh, "&Mesh");
menuBar->Append(menuProblem, "&Problem");
menuBar->Append(menuHelp, "&Help");
/* Creating the menu listing of File menu */
menuFile->Append(ID_New, "&New\tCtrl-N");
menuFile->Append(ID_Save, "&Save\tCtrl-S");
menuFile->Append(ID_SaveAs, "&Save As");
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
/* Creating the menu listinging of the Edit Menu */
menuEdit->Append(ID_Preferences, "&Preferences\tCtrl-P");
/* Creates the menu listing of the help menu */
menuHelp->Append(ID_Manual, "View Manual");
menuHelp->AppendSeparator();
menuHelp->Append(ID_License, "License");
menuHelp->Append(wxID_ABOUT);
/* Create and display the menu bar */
SetMenuBar(menuBar);
CreateStatusBar();
SetStatusText("Menu test for Omni-FEM");
}
void OmniFEMMainFrame::OnExit(wxCommandEvent &event)
{
Close(true);
}
void OmniFEMMainFrame::onNewFile(wxCommandEvent &event)
{
wxMessageBox("Created New File", "New File Creation", wxOK | wxICON_INFORMATION);
}
void OmniFEMMainFrame::OnSave(wxCommandEvent &event)
{
wxMessageBox("Work saved", "Save", wxOK | wxICON_INFORMATION);
}
void OmniFEMMainFrame::onSaveAs(wxCommandEvent &event)
{
wxMessageBox("Work saved in location", "Saved As", wxOK | wxICON_INFORMATION);
}
void OmniFEMMainFrame::onPreferences(wxCommandEvent &event)
{
wxMessageBox("Preferences are located here", "Preferences", wxOK | wxICON_INFORMATION);
}
void OmniFEMMainFrame::OnAbout(wxCommandEvent &event)
{
wxMessageBox("This is a test", "New File", wxOK | wxICON_INFORMATION);
}
void OmniFEMMainFrame::onManual(wxCommandEvent &event)
{
wxMessageBox("This is the manual", "Manual", wxOK | wxICON_INFORMATION);
}
void OmniFEMMainFrame::onLicense(wxCommandEvent &event)
{
wxMessageBox("This is the license", "License", wxOK | wxICON_INFORMATION);
}
And here is the code for the header file:
#ifndef OMNIFEM_H_
#define OMNIFEM_H_
#include <wx/wx.h>
class OmniFEMApp : public wxApp
{
public:
virtual bool OnInit();
};
class OmniFEMMainFrame : public wxFrame
{
public:
OmniFEMMainFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
private:
/* This section is for the File menu */
void onNewFile(wxCommandEvent &event);
void OnSave(wxCommandEvent &event);
void onSaveAs(wxCommandEvent &event);
/* This section is for the Edit menu */
void onPreferences(wxCommandEvent &event);
/* This section is for the Help menu */
void onManual(wxCommandEvent &event);
void onLicense(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event);
void OnExit(wxCommandEvent &event);
wxDECLARE_EVENT_TABLE();
};
enum
{
ID_New = 1,
ID_Save = 2,
ID_SaveAs = 3,
ID_Preferences = 4,
ID_Manual = 5,
ID_License = 6
};
wxBEGIN_EVENT_TABLE(OmniFEMMainFrame, wxFrame)
/* This section is for teh file menu */
EVT_MENU(ID_New, OmniFEMMainFrame::onNewFile)
EVT_MENU(ID_Save, OmniFEMMainFrame::OnSave)
EVT_MENU(ID_SaveAs, OmniFEMMainFrame::onSaveAs)
/* This section is for the view menu */
EVT_MENU(ID_Preferences, OmniFEMMainFrame::onPreferences)
/* This section is for the Help menu */
EVT_MENU(ID_Manual, OmniFEMMainFrame::onManual)
EVT_MENU(ID_License, OmniFEMMainFrame::onLicense)
EVT_MENU(wxID_ABOUT, OmniFEMMainFrame::OnAbout)
/* Everything Else */
EVT_MENU(wxID_EXIT, OmniFEMMainFrame::OnExit)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(OmniFEMApp);
#endif /* OMNIFEM_H_ */
Upvotes: 1
Views: 1553
Reputation: 885
ok guys, after asking the question on another forum, the problem has been solved.
Basically, the code
wxBEGIN_EVENT_TABLE(OmniFEMMainFrame, wxFrame)
/* This section is for teh file menu */
EVT_MENU(ID_New, OmniFEMMainFrame::onNewFile)
EVT_MENU(ID_Save, OmniFEMMainFrame::OnSave)
EVT_MENU(ID_SaveAs, OmniFEMMainFrame::onSaveAs)
/* This section is for the view menu */
EVT_MENU(ID_Preferences, OmniFEMMainFrame::onPreferences)
/* This section is for the Help menu */
EVT_MENU(ID_Manual, OmniFEMMainFrame::onManual)
EVT_MENU(ID_License, OmniFEMMainFrame::onLicense)
EVT_MENU(wxID_ABOUT, OmniFEMMainFrame::OnAbout)
/* Everything Else */
EVT_MENU(wxID_EXIT, OmniFEMMainFrame::OnExit)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(OmniFEMApp);
Needs to be placed in the .cpp file and not the header file. This fixed the issue
Upvotes: 1