Link failure on Linux

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Link failure on Linux

Post by ONEEYEMAN »

Hi, ALL,

Code: Select all

.libs/libdialogs_la-odbccredentials.o: In function `wxScopedCharTypeBuffer<wchar_t>::GetNullData()':
/home/igor/dbhandler/libdialogs/odbccredentials.cpp:14: multiple definition of `ODBCCredentials::ODBCCredentials(wxWindow*, int, wxString const&, wxString const&, wxString const&, wxString const&, wxPoint const&, wxSize const&, long)'
.libs/libdialogs_la-odbccredentials.o:/home/igor/dbhandler/libdialogs/odbccredentials.cpp:14: first defined here
.libs/libdialogs_la-odbccredentials.o: In function `ODBCCredentials::set_properties()':
/home/igor/dbhandler/libdialogs/odbccredentials.cpp:30: multiple definition of `ODBCCredentials::set_properties()'
.libs/libdialogs_la-odbccredentials.o:/home/igor/dbhandler/libdialogs/odbccredentials.cpp:30: first defined here
.libs/libdialogs_la-odbccredentials.o: In function `ODBCCredentials::do_layout()':
/home/igor/dbhandler/libdialogs/odbccredentials.cpp:38: multiple definition of `ODBCCredentials::do_layout()'
.libs/libdialogs_la-odbccredentials.o:/home/igor/dbhandler/libdialogs/odbccredentials.cpp:38: first defined here
.libs/libdialogs_la-odbccredentials.o: In function `wxScopedCharTypeBuffer<wchar_t>::GetNullData()':
/home/igor/dbhandler/libdialogs/odbccredentials.cpp:14: multiple definition of `ODBCCredentials::ODBCCredentials(wxWindow*, int, wxString const&, wxString const&, wxString const&, wxString const&, wxPoint const&, wxSize const&, long)'
.libs/libdialogs_la-odbccredentials.o:/home/igor/dbhandler/libdialogs/odbccredentials.cpp:14: first defined here
.libs/libdialogs_la-odbccredentials.o: In function `ODBCCredentials::GetUserIDControl()':
/home/igor/dbhandler/libdialogs/odbccredentials.cpp:74: multiple definition of `ODBCCredentials::GetUserIDControl()'
.libs/libdialogs_la-odbccredentials.o:/home/igor/dbhandler/libdialogs/odbccredentials.cpp:74: first defined here
.libs/libdialogs_la-odbccredentials.o: In function `ODBCCredentials::GetPasswordControl()':
/home/igor/dbhandler/libdialogs/odbccredentials.cpp:79: multiple definition of `ODBCCredentials::GetPasswordControl()'
.libs/libdialogs_la-odbccredentials.o:/home/igor/dbhandler/libdialogs/odbccredentials.cpp:79: first defined here
collect2: error: ld returned 1 exit status
Does anybody know what might be the issue?
The code for the class is following:

Code: Select all

#ifndef ODBCCREDENTIALS_H
#define ODBCCREDENTIALS_H

class ODBCCredentials: public wxDialog
{
public:
    // begin wxGlade: ODBCCredentials::ids
    // end wxGlade

    ODBCCredentials(wxWindow *parent, wxWindowID id, const wxString& title, const wxString &dsn, const wxString &userID, const wxString &password, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE);
    const wxTextCtrl &GetUserIDControl();
    const wxTextCtrl &GetPasswordControl();

private:
    wxString m_dsn;
    // begin wxGlade: ODBCCredentials::methods
    void set_properties();
    void do_layout();
    // end wxGlade

protected:
    // begin wxGlade: ODBCCredentials::attributes
    wxPanel *m_panel;
    wxStaticText* label_1;
    wxTextCtrl* m_userID;
    wxStaticText* label_2;
    wxTextCtrl* m_password;
    // end wxGlade
}; // wxGlade: end class


#endif // ODBCCREDENTIALS_H

Code: Select all

#include <wx/wx.h>
#include "odbccredentials.h"

ODBCCredentials::ODBCCredentials(wxWindow *parent, wxWindowID id, const wxString& title, const wxString &dsn, const wxString &userID, const wxString &password, const wxPoint& pos, const wxSize& size, long style):
    wxDialog(parent, id, title, pos, size, wxCAPTION)
{
    m_dsn = dsn;
    // begin wxGlade: ODBCCredentials::ODBCCredentials
    m_panel = new wxPanel( this, wxID_ANY );
    label_1 = new wxStaticText( this, wxID_ANY, _( "User ID" ) );
    m_userID = new wxTextCtrl( this, wxID_ANY, userID );
    label_2 = new wxStaticText( this, wxID_ANY, _( "Password" ) );
    m_password = new wxTextCtrl( this, wxID_ANY, password, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD );
    set_properties();
    do_layout();
    // end wxGlade
}

void ODBCCredentials::set_properties()
{
    // begin wxGlade: ODBCCredentials::set_properties
    SetTitle( _( "Connecting to " ) + m_dsn );
    // end wxGlade
}


void ODBCCredentials::do_layout()
{
    // begin wxGlade: ODBCCredentials::do_layout
    wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer* sizer_1 = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer* sizer_2 = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer* sizer_3 = new wxBoxSizer( wxVERTICAL );
    wxStdDialogButtonSizer *m_stdbuttonsizer = new wxStdDialogButtonSizer();
    m_stdbuttonsizer->AddButton( new wxButton( m_panel, wxID_OK, _( "OK" ) ) );
    m_stdbuttonsizer->AddButton( new wxButton( m_panel, wxID_CANCEL, _( "Cancel" ) ) );
    m_stdbuttonsizer->Realize();
    wxFlexGridSizer* grid_sizer_1 = new wxFlexGridSizer( 2, 2, 5, 5 );
    grid_sizer_1->AddGrowableCol( 1, 1 );
    sizer_1->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_2->Add( 5, 5, 0, wxEXPAND, 0 );
    grid_sizer_1->Add( label_1, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND, 0 );
    grid_sizer_1->Add( m_userID, 1, wxEXPAND, 0 );
    grid_sizer_1->Add( label_2, 0, 0, 0 );
    grid_sizer_1->Add( m_password, 1, wxEXPAND, 0 );
    sizer_3->Add( grid_sizer_1, 1, wxEXPAND, 0 );
    sizer_3->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_3->Add( m_stdbuttonsizer, 1, wxALIGN_RIGHT, 0 );
    sizer_2->Add( sizer_3, 1, 0, 0 );
    sizer_2->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_1->Add( sizer_2, 1, 0, 0 );
    sizer_1->Add( 5, 5, 0, wxEXPAND, 0 );
    m_panel->SetSizer( sizer_1 );
    sizer->Add( m_panel, 0, wxEXPAND, 0 );
    SetSizer( sizer );
    sizer->Fit( this );
    Layout();
    wxSize size = GetMinSize();
    SetMinSize( wxSize( size.GetWidth() * 3, size.GetHeight() ) );
    // end wxGlade
}

const wxTextCtrl &ODBCCredentials::GetUserIDControl()
{
    return *m_userID;
}

const wxTextCtrl &ODBCCredentials::GetPasswordControl()
{
    return *m_password;
}
As you can see there is no double definition anywhere. And the header is guard-protected with the "#ifndef".

Thank you.

Makefile:505: recipe for target 'libdialogs.la' failed
make[2]: *** [libdialogs.la] Error 1
make[2]: Leaving directory '/home/igor/dbhandler/Debug/libdialogs'
Makefile:501: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/igor/dbhandler/Debug'
Makefile:412: recipe for target 'all' failed
make: *** [all] Error 2
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Link failure on Linux

Post by DavidHart »

Hi,

Did it used to work? If so, what changed? And might there be a previous version of that lib, that also contains those functions, that's getting linked? 'make clean'?

What are your compilation and link commands?

Can you create and post a minimal compilable program that demonstrates the problem? (Preferably one that doesn't require wxGlade.)

Regards,

David
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: Link failure on Linux

Post by Manolo »

Can it be a "hidden" char that makes ODBCCredentials::ODBCCredentials different in .h and .cpp files?

Can it be that your IDE is passing to the linker the same .o file twice?

Can it be a pre-compiled headers issue?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

[SOLVED]]: Re: Link failure on Linux

Post by ONEEYEMAN »

Hi,
Sorry for the noise. For some reason this file appeared twice in the Makefile.
After cleaning this up, everything compiles fine.

Thank you.
Post Reply