linkink erro Topic is solved

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
marcelovvm
Experienced Solver
Experienced Solver
Posts: 58
Joined: Tue Mar 28, 2006 7:18 am
Location: Rio de Janeiro - Brasil
Contact:

linkink erro

Post by marcelovvm »

Dear friends,

I'm triyng to do socket server follow the example at the wxWidgets book (code bellow), but when I build the app same errors are show. I'm using VS2005 + PSDK + wxWidgets 2.6.3

main.h

Code: Select all

#ifndef INCLUDED_SOCKETAPP_H
#define INCLUDED_SOCKETAPP_H
 
class MyFrame: public wxFrame 
{ 
public:

	MyFrame( const wxString& title );

	void OnServerStart( wxCommandEvent& event );

	void OnServerEvent(wxSocketEvent& event );

	void OnSocketEvent(wxSocketEvent& event);

	wxSocketServer* m_server;

	DECLARE_EVENT_TABLE()
};

class MyApp: public wxApp 
{ 
	bool OnInit();
}; 

#endif
main.cpp

Code: Select all


#include "wx/wx.h"
#include "wx/socket.h"
#include "main.h"

enum 
{ 
	SERVER_START = 100,
	SERVER_STOP,
	SERVER_ID,
	SOCKET_ID
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(SERVER_START, MyFrame::OnServerStart)
    EVT_SOCKET(SERVER_ID,  MyFrame::OnServerEvent)
    EVT_SOCKET(SOCKET_ID,  MyFrame::OnSocketEvent)
END_EVENT_TABLE()

MyFrame::MyFrame ( const wxString& title ): wxFrame(NULL, wxID_ANY, title)
{ 
	// Criando a barra de menus - menuBar
	wxMenuBar *menuBar = new wxMenuBar;

	// Criando o primeiro item de menu - menuFile
	wxMenu *menuServer = new wxMenu;
	menuBar->Append( menuServer , "&Server" );
	menuServer->Append( SERVER_START , "&Start" , "Start Server" );
	menuServer->Append( SERVER_STOP , "&Stop" , "Stop Server" );
	//menuServer->Append( wxID_SAVE , "&Save...\tCtrl+S" , "Open account" );
	//menuServer->Append( wxID_CLOSE , "&Close\tCtrl+F4" , "Close this account" );
	
	// Anexando o menuBar criado ao MenuBar do frame
	SetMenuBar( menuBar );
}

void MyFrame::OnServerStart(wxCommandEvent& WXUNUSED(event))
{
    // Create the address - defaults to localhost:0 initially
    wxIPV4address addr;
    addr.Service(3000);

    // Create the socket. We maintain a class pointer so we can
    // shut it down
	
	m_server = new wxSocketServer(addr);

    // We use Ok() here to see if the server is really listening
    if (! m_server->Ok())
    {
        return;
    }

    // Set up the event handler and subscribe to connection events
    m_server->SetEventHandler(*this, SERVER_ID);
    m_server->SetNotify(wxSOCKET_CONNECTION_FLAG);
    m_server->Notify(true);
}

void MyFrame::OnServerEvent(wxSocketEvent& WXUNUSED(event))
{
    // Accept the new connection and get the socket pointer
    wxSocketBase* sock = m_server->Accept(false);

    // Tell the new socket how and where to process its events
    sock->SetEventHandler(*this, SOCKET_ID);
    sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
    sock->Notify(true);
}

void MyFrame::OnSocketEvent(wxSocketEvent& event)
{
    wxSocketBase *sock = event.GetSocket();

    // Process the event
    switch(event.GetSocketEvent())
    {
        case wxSOCKET_INPUT:
        {
            char buf[10];

            // Read the data
            sock->Read(buf, sizeof(buf));

            // Write it back
            sock->Write(buf, sizeof(buf));

            // We are done with the socket, destroy it
            sock->Destroy();

            break;
        }
        case wxSOCKET_LOST:
        {
            sock->Destroy();
            break;
        }
    }
}


bool MyApp::OnInit()
{
	MyFrame *frame = new MyFrame( "Socket Application" );
	frame->CreateStatusBar();
	frame->SetStatusText("Socket");
	frame->Show(TRUE);
	SetTopWindow(frame);
	return true;
}


Debug error (using static lib)

------ Build started: Project: socket, Configuration: Debug Win32 ------
Compiling...
main.cpp
Linking...
wxbase26d_net.lib(sckaddr.obj) : error LNK2019: unresolved external symbol "public: void __thiscall wxStringData::Free(void)" (?Free@wxStringData@@QAEXXZ) referenced in function "public: void __thiscall wxStringData::Unlock(void)" (?Unlock@wxStringData@@QAEXXZ)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
Debug/socket.exe : fatal error LNK1120: 2 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Marcelo Magalh
Marcelo V. V. Magalhães, CSM
E+D Consultores Associados
Análise, Projeto e Desenolvimento de sistemas
www.emaisd.com.br
Rio de Janeiro - R.J.
Cel.: +55 (21) 96140028
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

in your source file you need to do IMPLEMENT_APP(MyApp) to let wxWidgets know your app entry point.

-Joel
micros
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Sat Mar 18, 2006 10:41 am
Location: Ustek, Bohemia

Post by micros »

The StringData:: unresolved externals are most likely caused by using different CRT libraries. Make sure you link against the same C runtime when building wxWidgets and your app (Project Properties -> C/C++ -> Code Generation -> Runtime Library (hope the location didn't change in VS2005)).
marcelovvm
Experienced Solver
Experienced Solver
Posts: 58
Joined: Tue Mar 28, 2006 7:18 am
Location: Rio de Janeiro - Brasil
Contact:

Post by marcelovvm »

Dear micros,

I cheked the Runtime Library and it is configured for DLL exactaly the configuration when I build wxWidgets. I builded wxWidgets as static and DLL. How can I know here is the conflit beetwen this libraries CRT?

[]s.
Marcelo V. V. Magalhães, CSM
E+D Consultores Associados
Análise, Projeto e Desenolvimento de sistemas
www.emaisd.com.br
Rio de Janeiro - R.J.
Cel.: +55 (21) 96140028
HK
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu Apr 20, 2006 8:13 am
Location: China(Taiwan)

Post by HK »

It works at Linux OS, if
IMPLEMENT_APP(MyApp)
added.
dsilvia
Earned some good credits
Earned some good credits
Posts: 145
Joined: Sun May 29, 2005 3:42 pm
Location: Bettendorf, Iowa, USA (aka, BFE)

Post by dsilvia »

As per C:\wxWidgets-2.6.3\src\common\string.cpp

Code: Select all


// ===========================================================================
// wxStringData class deallocation
// ===========================================================================

#if defined(__VISUALC__) && defined(_MT) && !defined(_DLL)
#  pragma message (__FILE__ ": building with Multithreaded non DLL runtime has a performance impact on wxString!")
void wxStringData::Free()
{
    free(this);
}
#endif

Which means that your wxWidgets libraries in vc_lib and your current code you're working with in Visual Studio 2005 must be in synch. If one qualifies to have the subject member function defined and included, so must the other, and the converse is true.

I had built my vc_lib using DialogBlocks which defaults to DLLs, so, the above code was never compiled into my wxWidgets libraries for vc_lib. Now, I went to Visual Studio 2005 Express to build some existing code and it defaulted to /MT. This meant that the above code was compiled into my application, so up popped the unresolved references. On changing to /MD everything was hunkey-dorey! :D

HTH,
Dave S.
Post Reply