Sign in to follow this  
Chamlung

Linking Error in C++ ----"Solved"

Recommended Posts

I am having a very hard time with this linking error ------ LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/Basic.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. ------- I am using Visual C++. I have tried my best to solve it. Even browsed the web to seach for the solution. Seems I can't find the solution. Please Help..... I am stuck [Edited by - Chamlung on December 7, 2004 6:32:22 AM]

Share this post


Link to post
Share on other sites
You are creating a Windows app, but your project settings create a console app. Change the target to "Application (exe)" in your project settings.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Make sure you compile each .cpp file individually before you build.

Share this post


Link to post
Share on other sites
Thanks for your replies...

Anonymous Poster---> I have complied every cpp files... does not work

darookie--> It is a windows application. And tried your option too, does not work.

Ainokea--> I am using DirextX 8.0 (msdk)
The source code is....
Have linked all the header and the library files... Yet the same error..
------------------------

#define STRICT
#include <tchar.h>
#include <math.h>
#include <stdio.h>
#include <D3DX8.h>
#include "D3DApp.h"
#include "D3DFont.h"
#include "D3DUtil.h"
#include "DXUtil.h"
#include "resource.h"

//A stru for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT x,y,z,rhw; //the transformed pos for the vertex
FLOAT tu,tv; //texture coordinates
};

//Our custom FVF, which describes our custom vertex stru
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_TEX1)

//------------------
//CMYD3DApplication
//Application class. The base class CD3DApplication provides the generic
//functionality needed in all Direct3D samples.
//CMyD3DApplication adds functionality specific to this sample program
//-----------------
class CMyD3DApplication:public CD3DApplication
{
CD3DFont* m_pFont;
LPDIRECT3DVERTEXBUFFER8 m_pVB; //Buffer to hold vertices
DWORD m_dwSizeofVertices;
LPDIRECT3DINDEXBUFFER8 m_pIB;
DWORD m_dwSizeofIndices;

LPDIRECT3DTEXTURE8 m_pBackgroundTexture;
HRESULT ConfirmDevice(D3DCAPS8*,DWORD,D3DFORMAT);
protected:
HRESULT OneTimeSceneInit();
HRESULT InitDeviceObjects();
HRESULT RestoreDeviceObjects();
HRESULT InvalidateDeviceObjects();
HRESULT DeleteDeviceObjects();
HRESULT Render();
HRESULT FrameMove();
HRESULT FinalCleanup();

public:
CMyD3DApplication();
};

//---------------
//WinMain
//Entry pt. to the program. Initializes everything, and goes into a
//message-processing loop. Idle time is used to render th scene
//---------------
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
CMyD3DApplication d3dApp;
if(FAILED(d3dApp.Create(hInst)))
return 0;
return d3dApp.Run();
}

//---------------
//CMyD3DApplication()
//Application consructor. Sets attributes for the app
//---------------
CMyD3DApplication::CMyD3DApplication()
{
m_strWindowTitle = _T("Dipenra Basic3");
m_bUseDepthBuffer = FALSE;
m_pVB=NULL;
m_pIB=NULL;
m_pFont= new CD3DFont( _T("Arial"),12, D3DFONT_BOLD);
}

//---------------
//OneTimeSceneInit()
//Called during initial app startup, this function performs all the
//permanent initialization
//---------------

HRESULT CMyD3DApplication::OneTimeSceneInit()
{
return S_OK;
}

//-----------
//FrameMove()
//Called once per frame, the call is the entry pt. for animating
//the scene
//-----------
HRESULT CMyD3DApplication::FrameMove()
{
return S_OK;
}

//-----------
//Render()
//called once per every frame, the call is ht eentry pt. for 3d
//rendering. This function sets up render states, clears the viewport, and renders the scene
//-----------
HRESULT CMyD3DApplication::Render()
{
//Begin the Scene
if(SUCCEEDED(m_pd3dDevice->BeginScene()))
{
m_pd3dDevice->SetTexture(0,m_pBackgroundTexture);
m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);

m_pd3dDevice->SetStreamSource(0,m_pVB,sizeof(CUSTOMVERTEX));
m_pd3dDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
m_pd3dDevice->SetIndices(m_pIB,0);
m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,4,0,2);

//output statistics
m_pFont->DrawText(2,0,D3DCOLOR_ARGB(255,255,255,0),m_strFrameStats);
m_pFont->DrawText(2,20,D3DCOLOR_ARGB(255,255,255,0),m_strDeviceStats);

//End the scene
m_pd3dDevice->EndScene();
}
return S_OK;
}

//----------------------
//InitDeviceObjects()
//Initialize scene objects
//----------------------
HRESULT CMyD3DApplication::InitDeviceObjects()
{
m_pFont->InitDeviceObjects(m_pd3dDevice);
//Load the texture for the background image
if(FAILED(D3DUtil_CreateTexture(m_pd3dDevice,_T("Dpr.bmp"),&m_pBackgroundTexture)))
return D3DAPPERR_MEDIANOTFOUND;
return S_OK;
}

//-----------
//RestoreDeviceObjects()
//Initialize scene objects
//-----------
HRESULT CMyD3DApplication::RestoreDeviceObjects()
{
m_pFont->RestoreDeviceObjects();

//Set the transform matrices
D3DXVECTOR3 vEyePt = D3DXVECTOR3(0.0f,0.0f,2.0f);
D3DXVECTOR3 vLookatPt= D3DXVECTOR3(0.0f,0.0f,1.0f);
D3DXVECTOR3 vUpVec = D3DXVECTOR3(0.0f,1.0f,0.0f);
D3DXMATRIX matWorld, matView, matProj;

D3DXMatrixIdentity( &matWorld);
D3DXMatrixLookAtLH(&matView,&vEyePt,&vLookatPt,&vUpVec);
FLOAT fAspect= m_d3dsdBackBuffer.Width/(FLOAT)m_d3dsdBackBuffer.Height;
D3DXMatrixPerspectiveFovLH(&matProj,D3DX_PI/4,fAspect,1.0f,500.0f);

m_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
m_pd3dDevice->SetTransform(D3DTS_VIEW,&matView);
m_pd3dDevice->SetTransform(D3DTS_PROJECTION,&matProj);

//fill the vertex buffer with the new data
D3DVIEWPORT8 vp;
m_pd3dDevice->GetViewport(&vp);

//Initialize four vertices for rendering two triangles
CUSTOMVERTEX cvVertices[]=
{
{0.0f,0.0f,0.5f,1.0f,0.0f,0.0f,},//x,y,z,rhw,tu,tv
{(float)vp.Width,0.0f,0.5f,1.0f,1.0f,0.0f,},
{(float)vp.Width,(float)vp.Height,0.5f,1.0f,1.0f,1.0f,},
{0.0f,(float)vp.Height,0.5f,1.0f,0.0f,1.0f},
};

m_dwSizeofVertices=sizeof(cvVertices);

//Create the vertex buffer
if(FAILED(m_pd3dDevice->CreateVertexBuffer(m_dwSizeofVertices,0,D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,&m_pVB)))
return E_FAIL;

VOID* pVertices;
if(FAILED(m_pVB->Lock(0,m_dwSizeofVertices,(BYTE**)&pVertices,0)))
return E_FAIL;
memcpy(pVertices,cvVertices,m_dwSizeofVertices);
m_pVB->Unlock();

//Initialize the Index Buffer
WORD dwIndices[]={0,1,2,0,2,3};

m_dwSizeofIndices= sizeof(dwIndices);

//Create the index buffer
if(FAILED(m_pd3dDevice->CreateIndexBuffer(m_dwSizeofIndices,0,D3DFMT_INDEX16,D3DPOOL_MANAGED,&m_pIB)))
return E_FAIL;
VOID* pIndices;
if(FAILED(m_pIB->Lock(0,m_dwSizeofIndices,(BYTE**)&pIndices,0)))
return E_FAIL;
memcpy(pIndices,dwIndices,sizeof(dwIndices));
m_pIB->Unlock();

return S_OK;
}

//--------------
//InvalidateDeviceObjects()
//called when the app is exiting, or the device is being changed
//this function deletes any device dependent objects
//-----------------
HRESULT CMyD3DApplication::InvalidateDeviceObjects()
{
m_pFont->InvalidateDeviceObjects();
SAFE_RELEASE(m_pVB);
SAFE_RELEASE(m_pIB);
return S_OK;
}

//----------
//DeleteDeviceObjects()
//called when the app is exiting, or the device is being changed,
//this function deletes any device dependent objects
//----------
HRESULT CMyD3DApplication::DeleteDeviceObjects()
{
m_pFont->DeleteDeviceObjects();
SAFE_RELEASE(m_pBackgroundTexture);
return S_OK;
}

//----------
//FinalCleanup()
//called before the app exits, this function gives the app the chance
//to cleanup after itself
//---------
HRESULT CMyD3DApplication::FinalCleanup()
{
return S_OK;
}

///------------------
//ComfirmDevice()
//Called during devie intialization, this code checks the device
//for some minimum set of capabilities
//-----------------
HRESULT CMyD3DApplication::ConfirmDevice(D3DCAPS8* pCaps,DWORD dwBehavior, D3DFORMAT Format)
{
return S_OK;
}



Share this post


Link to post
Share on other sites
Well it appears to be looking for main so for testing purposes you could stick...

int main ( void )
{
return 0;
}

in there just to see if it will link and if it does then there is probably a problem with your configuration of the project. Yet LIBCD.lib has me wondering if that may not be the problem, are you getting any other errors/warnings?

edit:
Oh and in VS .Net 2003, only one i have so im not sure about 6 or .Net but should be somewhat the same, check in your project properties->linker->system and check that subsystem is windows not console.

Share this post


Link to post
Share on other sites
remember that when you create applications you need to include the main function unless you are using mfc or similiar libraries. The reason for the main function is that the compiler needs to know where to the actually program begins and since we are using c/c++ the main and winmain is the topical place the compiler looks you could always implement a library like sdl to call other functions instead of the main i believe there's start at the functions console_main() but im not sure

Share this post


Link to post
Share on other sites
You have a windows application but your project is set up for a console applications. Change your project seetings and it should work (linker/system/subsystem).

Share this post


Link to post
Share on other sites
Hey thanks for your help guys

I have finally solved it. Thanks for the help given by Wolfdog and VolkerG.
Well the Problem lied in the setting of my project.

To fix it, I had to go to
--------------------------
- Project/setting
- "Link" tab
and in the
- "Project Option"
had to change
"/subsystem:consol" to "/subsystem:windows"
----------------------------

Hope this will be helpful to someone having the same problem

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this