Question

Hey Everyone,

I was having a problem compiling an Adept 2 project on Ubuntu using GCC. This is the error I'm getting.

Also, here is the code. It's really, really, hacked together but it's just because I couldn't get it working in either Visual Studio 2019 or Linux. I already install the Runtime, SDK, and utilities on both my Windows and Linux machine but to no avail, I still get assembly errors. Any help would be appreciated :)



#define	_CRT_SECURE_NO_WARNINGS

/* ------------------------------------------------------------ */
/*					Include File Definitions					*/
/* ------------------------------------------------------------ */

#if defined(WIN32)

	/* Include Windows specific headers here.*/
#include <windows.h>

#else

#endif

#define DPCAPI 
#define DACI_INCLUDED

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


#include "/usr/include/digilent/adept/dpcdecl.h"
#include "/usr/include/digilent/adept/dmgr.h"
#include "/usr/include/digilent/adept/depp.h"
#include "/usr/include/digilent/adept/daci.h"
#include "/usr/include/digilent/adept/dpcutil.h"
#include "/usr/include/digilent/adept/dpcdefs.h"
	/* ------------------------------------------------------------ */
	/*					Local Type and Constant Definitions			*/
	/* ------------------------------------------------------------ */

const int cchSzLen = 1024;
const int cbBlockSize = 1000;

/* ------------------------------------------------------------ */
/*					Global Variables							*/
/* ------------------------------------------------------------ */

BOOL			fGetReg;
BOOL			fPutReg;
BOOL			fGetRegRepeat;
BOOL			fPutRegRepeat;
BOOL			fDvc;
BOOL			fFile;
BOOL			fCount;
BOOL			fByte;

char szDvc[64] = "CmodS6";


char			szAction[cchSzLen];
char			szRegister[cchSzLen];
//char			szDvc[cchSzLen];
char			szFile[cchSzLen];
char			szCount[cchSzLen];
char			szByte[cchSzLen];

HIF				hif = hifInvalid;

FILE* fhin = NULL;
FILE* fhout = NULL;


/* ------------------------------------------------------------ */
/*				Local Variables									*/
/* ------------------------------------------------------------ */


/* ------------------------------------------------------------ */
/*					Forward Declarations						*/
/* ------------------------------------------------------------ */

BOOL		FParseParam(int cszArg, char* rgszArg[]);
void		ShowUsage(char* sz);
BOOL		FInit();
void		ErrorExit();

void		DoDvcTbl();
void		DoPutReg();
BYTE		DoGetReg(BYTE idReg[]);
void		DoPutRegRepeat();
void		DoGetRegRepeat();

void		StrcpyS(char* szDst, size_t cchDst, const char* szSrc);


// Making the Error Code pointer
ERC* error;


/* ------------------------------------------------------------ */
/*				Procedure Definitions							*/
/* ------------------------------------------------------------ */
/***	main
**
**	Synopsis
**		int main(cszArg, rgszArg)
**
**	Input:
**		cszArg		- count of command line arguments
**		rgszArg		- array of command line arguments
**
**	Output:
**		none
**
**	Errors:
**		Exits with exit code 0 if successful, else non-zero
**
**	Description:
**		main function of DEPP Demo application.
*/

int main(int cszArg, char* rgszArg[]) {

	//if (!FParseParam(cszArg, rgszArg)) {
	//	ShowUsage(rgszArg[0]);
	//	return 1;
	//}

	// First initializing the device, returns false if can't initialize

	if (!DpcInit(error))
		return 0;

	// DMGR API Call: DmgrOpen
	if (!DmgrOpen(&hif, szDvc)) {
		printf("DmgrOpen failed (check the device name you provided)\n");
		return 0;
	}

	// DEPP API call: DeppEnable
	if (!DeppEnable(hif)) {
		printf("DeppEnable failed\n");
		return 0;
	}

	BYTE request_bit = {00000000};
	BYTE * bit_storage = 0;
	DWORD value = 0;
	char * choice = NULL;


	// This is for getting the registers forever
	while (true)
	{
		printf("Please enter the values of bits you'd like to find!");
		
		//scanf("%c", choice);

		request_bit = { 0x0 };

		if (fGetReg) {
			DeppGetReg(hif, request_bit, bit_storage, value);	/* Get single byte from register */

			printf("%c",value);


		}

		

	}

	return 0;

}


/* ------------------------------------------------------------ */
/***	FParseParam
**
**	Parameters:
**		cszArg		- number of command line arguments
**		rgszArg		- array of command line argument strings
**
**	Return Value:
**		none
**
**	Errors:
**		Returns fTrue if not parse errors, fFalse if command line
**		errors detected.
**
**	Description:
**		Parse the command line parameters and set global variables
**		based on what is found.
*/

BOOL FParseParam(int cszArg, char* rgszArg[]) {

	int		iszArg;

	/* Initialize default flag values */
	fGetReg = fFalse;
	fPutReg = fFalse;
	fGetRegRepeat = fFalse;
	fPutRegRepeat = fFalse;
	fDvc = fFalse;
	fFile = fFalse;
	fCount = fFalse;
	fByte = fFalse;

	// Ensure sufficient paramaters. Need at least program name, action flag, register number
	if (cszArg < 3) {
		return fFalse;
	}

	/* The first parameter is the action to perform. Copy the
	** the first parameter into the action string.
	*/
	StrcpyS(szAction, cchSzLen, rgszArg[1]);

	if (strcmp(szAction, "-g") == 0) {
		fGetReg = fTrue;
	}
	else if (strcmp(szAction, "-p") == 0) {
		fPutReg = fTrue;
	}
	else if (strcmp(szAction, "-s") == 0) {
		fGetRegRepeat = fTrue;
	}
	else if (strcmp(szAction, "-l") == 0) {
		fPutRegRepeat = fTrue;
	}
	else { // unrecognized action
		return fFalse;
	}

	/* Second paramater is target register on device. Copy second
	** paramater to the register string */
	StrcpyS(szRegister, cchSzLen, rgszArg[2]);


	/* Parse the command line parameters.
	*/
	iszArg = 3;
	while (iszArg < cszArg) {

		/* Check for the -d parameter which is used to specify
		** the device name of the device to query.
		*/
		if (strcmp(rgszArg[iszArg], "-d") == 0) {
			iszArg += 1;
			if (iszArg >= cszArg) {
				return fFalse;
			}
			StrcpyS(szDvc, cchSzLen, rgszArg[iszArg++]);
			fDvc = fTrue;
		}

		/* Check for the -f parameter used to specify the
		** input/output file name.
		*/
		else if (strcmp(rgszArg[iszArg], "-f") == 0) {
			iszArg += 1;
			if (iszArg >= cszArg) {
				return fFalse;
			}
			StrcpyS(szFile, cchSnMax, rgszArg[iszArg++]);
			fFile = fTrue;
		}

		/* Check for the -c parameter used to specify the
		** number of bytes to read/write from file.
		*/
		else if (strcmp(rgszArg[iszArg], "-c") == 0) {
			iszArg += 1;
			if (iszArg >= cszArg) {
				return fFalse;
			}
			StrcpyS(szCount, cchUsrNameMax, rgszArg[iszArg++]);
			fCount = fTrue;
		}

		/* Check for the -b paramater used to specify the
		** value of a single data byte to be written to the register
		*/
		else if (strcmp(rgszArg[iszArg], "-b") == 0) {
			iszArg += 1;
			if (iszArg >= cszArg) {
				return fFalse;
			}
			StrcpyS(szByte, cchUsrNameMax, rgszArg[iszArg++]);
			fByte = fTrue;
		}

		/* Not a recognized parameter
		*/
		else {
			return fFalse;
		}
	} // End while

	/* Input combination validity checks
	*/
	if (!fDvc) {
		printf("Error: No device specified\n");
		return fFalse;
	}
	if (fPutReg && !fByte) {
		printf("Error: No byte value provided\n");
		return fFalse;
	}
	if ((fGetRegRepeat || fPutRegRepeat) && !fFile) {
		printf("Error: No filename provided\n");
		return fFalse;
	}

	return fTrue;

}

/* ------------------------------------------------------------ */
/***	ShowUsage
**
**	Synopsis
**		VOID ShowUsage(sz)
**
**	Input:
**		szProgName	- program name as called
**
**	Output:
**		none
**
**	Errors:
**		none
**
**	Description:
**		prints message to user detailing command line options
*/

void ShowUsage(char* szProgName) {

	printf("\nDigilent DEPP demo\n");
	printf("Usage: %s <action> <register> -d <device name> [options]\n", szProgName);

	printf("\n\tActions:\n");
	printf("\t-g\t\t\t\tGet register byte\n");
	printf("\t-p\t\t\t\tPut Register byte\n");
	printf("\t-l\t\t\t\tStream file into register\n");
	printf("\t-s\t\t\t\tStream register into file\n");

	printf("\n\tOptions:\n");
	printf("\t-f <filename>\t\t\tSpecify file name\n");
	printf("\t-c <# bytes>\t\t\tNumber of bytes to read/write\n");
	printf("\t-b <byte>\t\t\tValue to load into register\n");

	printf("\n\n");
}



/* ------------------------------------------------------------ */
/***	StrcpyS
**
**	Parameters:
**		szDst - pointer to the destination string
**		cchDst - size of destination string
**		szSrc - pointer to zero terminated source string
**
**	Return Value:
**		none
**
**	Errors:
**		none
**
**	Description:
**		Cross platform version of Windows function strcpy_s.
*/
void StrcpyS(char* szDst, size_t cchDst, const char* szSrc) {

#if defined (WIN32)

	strcpy_s(szDst, cchDst, szSrc);

#else

	if (0 < cchDst) {

		strncpy(szDst, szSrc, cchDst - 1);
		szDst[cchDst - 1] = '\0';
	}

#endif
}

/* ------------------------------------------------------------ */

/************************************************************************/





 

 

Screenshot from 2019-08-13 16-21-15.png

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Nah, I still get the same linker errors. In the Daci Demo, I still have the link time error. I'm wondering if you may have some source code so I can recompile the libraries in Ubuntu 18 or like what else I could try? Also, thanks for answering my Run time question! If I can't figure it out this way I think I'll just make a script to do it.

- Blaine

Share this post


Link to post
Share on other sites
  • 0

Hi @k16blfurm,

I believe this is a linking issue. I would try having all of the functions in the same folder as your main file. Then just #include "dpcdecl.h" instead of 

#include "/usr/include/digilent/adept/dpcdecl.h" I would also link all of the file explicitly instead of with the *.cpp like: "g++ main.cpp function_file.cpp"

best regards,

Jon

 

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Hey jpeyron, I kinda figured it wasn't linking but I just tried moving all of the header files into one directory and still got the same issue.

 

blaine@blaine-MacBookAir:~/Downloads$ tree
.
├── Adept2Test.h
├── Adept2Test.h.gch
├── Adept2Test.Linux.cpp
├── daci.h
├── daio.h
├── demc.h
├── depp.h
├── dgio.h
├── djtg.h
├── dmgr.h
├── dmgt.h
├── dpcdecl.h
├── dpcdefs.h
├── dpcutil.h
├── dpio.h
├── dpti.h
├── dspi.h
├── dstm.h
└── dtwi.h

0 directories, 19 files
blaine@blaine-MacBookAir:~/Downloads$ g++ Adept2Test.Linux.cpp
/tmp/ccT0M1Oc.o: In function `main':
Adept2Test.Linux.cpp:(.text+0x1a): undefined reference to `DpcInit(int*)'
Adept2Test.Linux.cpp:(.text+0x40): undefined reference to `DmgrOpen(unsigned int*, char*)'
Adept2Test.Linux.cpp:(.text+0x6c): undefined reference to `DeppEnable(unsigned int)'
Adept2Test.Linux.cpp:(.text+0xda): undefined reference to `DeppGetReg(unsigned int, unsigned char, unsigned char*, int)'
collect2: error: ld returned 1 exit status

 

I'm curious if it's a bad symbolic link but I install all the packages from the Adept 2 download page through debs on my Macbook Air running Ubuntu 18.04 LTS and from source on my Linux machine at home. Also, thanks for the reply.

 

Edit:

Forgot to show how I put the headers at the top.

#define	_CRT_SECURE_NO_WARNINGS

/* ------------------------------------------------------------ */
/*					Include File Definitions					*/
/* ------------------------------------------------------------ */

#if defined(WIN32)

	/* Include Windows specific headers here.*/
#include <windows.h>

#else

#endif

#define DPCAPI 
#define DACI_INCLUDED

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


// #include "/usr/include/digilent/adept/dpcdecl.h"
// #include "/usr/include/digilent/adept/dmgr.h"
// #include "/usr/include/digilent/adept/depp.h"
// #include "/usr/include/digilent/adept/daci.h"
// #include "/usr/include/digilent/adept/dpcutil.h"
// #include "/usr/include/digilent/adept/dpcdefs.h"
#include "dpcdecl.h"
#include "dmgr.h"
#include "depp.h"
#include "daci.h"
#include "dpcutil.h"
#include "dpcdefs.h"
  
... Demo Code continues....

 

Edited by k16blfurm
Forgot to put header shown in code

Share this post


Link to post
Share on other sites
  • 0

Ok, I think I figured it out. By default, the Makefile for the Demos point to the 32 bit libraries, when I only installed 64 bit. I fixed it by modifying the Libraries to what I installed.

Share this post


Link to post
Share on other sites
  • 0

Hi @k16blfurm,

Glad to hear you were able to get your program to compile. Thank you for sharing it was a conflict between 32 and 64 bit libraries.

best regards,

Jon

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