Learning the C++ IDE - linker error

Hi all,

I am a brand new user to the C++ language in Windows environment, and the Visual Studio C++ Express 2010 Edition. I have written in C (some years ago), but nothing in the ++ world nor Windows versions. I am driven to use this language due to a tool I am using to explore robotics platform engineering.

I received a sample code for accessing a single board computer via USB, with this sample code. I installed the Visual C++ Studio 2010 Express, then built a Hello World simple application. Once I saw this program work, I integrated the sample code for my Digilent board into this program structure. I then learned how to resolve the references to remove the errors where .h include files could not be found.

Now I am expereincing linker errors when I compile. Just need a push in the right direction to figure out how to resolve these.

The error is: LINK : fatal error LNK1561: entry point must be defined

I did google this prior to asking, but most of the responses were regarding older compilers, and that the solutions were resolved in newer versions. The most repeated response was an additional "slash" that was not necessary at the end of a path. I did try replacing any of these found in my paths.

Here is the program as I have built it in the IDE:

#include "stdafx.h"
#define WIN32_LEAN_AND_MEAN

#if defined(WIN32)


#include <windows.h>

#else


#include <errno.h>
#include <time.h>

#endif

#include <stdio.h>
#include <stdlib.h>

#include "C:\digilent\dpcdecl.h"

#include "C:\digilent\dmgr.h"
#include "C:\digilent\dgio.h"



const int chnLed = 0;
const int chnSwt = 1;
const int chnBtn = 2;
const int chnDps = 3;

HIF hif;



char szDUT[] = "ioexp";


void ErrorExit();

void SleepMs( DWORD tms );


namespace DgioDemo


{

int main() {

int cprt;
int prt;
int chn;
DPRP dprp;
int ival;
DWORD dwLed;
DWORD dwSwt;
DWORD dwBtn;
DWORD dwDps;
DWORD dwMask;


if (!DmgrOpen(&hif, szDUT)) {
printf("Unable to open device: %s\n", szDUT);
ErrorExit();
}

if (DgioGetPortCount(hif, &cprt)) {
printf(" DGIO port count: %d\n", cprt);
}
else {
printf("DgioGetPortCount failed\n");
}


for (prt = 0; prt < cprt; prt++) {

DgioGetPortProperties(hif, prt, &dprp);
printf(" Port %d\n", prt);
printf(" Properties: %8.8X\n", dprp);
}


prt = 0;

if (DgioEnableEx(hif, prt)) {
printf(" DGIO port %d enabled\n", prt);
}
else {
printf(" Unable to enable DGIO port %d\n", prt);
}


for (chn = 0; chn < 4; chn++) {

if (DgioGetDiscreteMask(hif, chn, &dwMask)) {
printf(" DGIO Port 0, chan %d mask: %8.8X\n", chn, dwMask);
}
else {
printf(" DgioGetDiscreteMask failed\n");
}
}


dwLed = 1;
for (ival = 0; ival < 16; ival++) {

if (!DgioPutData(hif, 0, 0, &dwLed, 4, fFalse)) {
printf(" DgioPutData to LEDs failed\n");
}
dwLed = dwLed << 1;
SleepMs(500);
}
dwLed = 0;

DgioPutData(hif, 0, 0, &dwLed, 4, fFalse);


printf("Echoing switches, buttons, and dip switch to LEDs\n");
printf(" Set switches to 0x0A to exit\n");

while(fTrue) {

if (!DgioGetData(hif, 1, 0, &dwSwt, 4, fFalse)) {
printf(" DgioGetData on switches failed\n");
}

if (!DgioGetData(hif, 2, 0, &dwBtn, 4, fFalse)) {
printf(" DgioGetData on buttons failed\n");
}

if (!DgioGetData(hif, 3, 0, &dwDps, 4, fFalse)) {
printf(" DgioGetData on dip switch failed\n");
}
dwLed = dwSwt | (dwBtn << 8) | (dwDps << 12);

if (!DgioPutData(hif, 0, 0, &dwLed, 4, fFalse)) {
printf(" DgioPutData on LEDs failed\n");
}
if ((dwSwt & 0x0F) == 0x0A) {
break;
}
}

dwLed = 0;


DgioPutData(hif, 0, 0, &dwLed, 4, fFalse);

if(!DgioDisable(hif)) {
printf("Error: DgioDisable failed\n");
ErrorExit();
}


if(!DmgrClose(hif)) {
printf("DmgrClose failed");
ErrorExit();
}

return 0;
}


void ErrorExit() {
if(hif != hifInvalid) {


DgioDisable(hif);

DmgrClose(hif);
}

exit(1);
}



void SleepMs( DWORD tms ) {

#if defined(WIN32)



return Sleep(tms);

#else



struct timespec timeSleep;
struct timespec timeRemain;
int ret;

timeSleep.tv_sec = (time_t)( tms / 1000 );
timeSleep.tv_nsec = (long)(( tms % 1000 ) * 1000000 );

ret = nanosleep(&timeSleep, &timeRemain);
if ( 0 > ret ) {

if ( EINTR == errno ) {


timeSleep.tv_sec = timeRemain.tv_sec;
timeSleep.tv_nsec = timeRemain.tv_nsec;
ret = nanosleep(&timeSleep, &timeRemain);
while (( 0 > ret ) && ( EINTR == errno )) {

timeSleep.tv_sec = timeRemain.tv_sec;
timeSleep.tv_nsec = timeRemain.tv_nsec;
ret = nanosleep(&timeSleep, &timeRemain);
}

if ( 0 != ret ) {



return;
}
}
else if ( EINVAL == errno ) {



return;
}
else {



return;
}
}

return;

#endif
}



}




main may not be in any namespace.
Thanks, that got me past this error!
Topic archived. No new replies allowed.