Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Error in compiling c++ in visual studio 2010

Status
Not open for further replies.

syedshan

Advanced Member level 1
Joined
Feb 27, 2012
Messages
463
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,308
Location
Jeonju, South Korea
Activity points
5,134
Dear all


1>------ Build started: Project: trainmaterial_step1_temp, Configuration: Debug Win32 ------
1> step1_tempcode2.cpp
1>step1_tempcode2.obj : error LNK2019: unresolved external symbol __4FM_ReceiveData referenced in function _main
1>step1_tempcode2.obj : error LNK2019: unresolved external symbol __4FM_SendData referenced in function _main
1>step1_tempcode2.obj : error LNK2019: unresolved external symbol __4FM_SelectTarget referenced in function _main
1>step1_tempcode2.obj : error LNK2019: unresolved external symbol __4FM_ResetDevice referenced in function _main
1>step1_tempcode2.obj : error LNK2019: unresolved external symbol __4FM_OpenDeviceEx referenced in function _main
1>step1_tempcode2.obj : error LNK2019: unresolved external symbol __4FM_CloseDevice referenced in function "void __cdecl exit_handler(void *,void *,struct tag_4FM_DeviceContext *)" (?exit_handler@@YAXPAX0PAUtag_4FM_DeviceContext@@@Z)
1>C:\Users\Syedshan\Desktop\VS shan\trainmaterial_step1_temp\Debug\trainmaterial_step1_temp.exe : fatal error LNK1120: 6 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have added the relevant include files and library files paths as well and I am sure (at least by my part) that the function called is quite visible to the compiler...
I tried everything but the error does not remove. I have attached the code as well below

Code:
#include <stdio.h>		// printf()
#include <stdlib.h>               // srand(), rand()
#include <time.h>		// time()
#include <string.h>              // memcmp()
#include <4FM.h>			// 4DSP's  Application Programming Interface header
#include <malloc.h>		// _aligned_malloc/free(), this is a windows specific header

#define _MEMORY_SIZE	4096		// 4096 bytes is the maximum size we can transfer without to overflow FIFOs in the ifpga interface.

// function called to free buffers, handle to the 4DSP's device and then exit the application
void exit_handler(void *buf1, void *buf2, _4FM_DeviceContext *dev_ctx)
{
	// Release the instance to the hardware
	if(dev_ctx!=NULL)
		_4FM_CloseDevice(dev_ctx);

	// Free the buffers
	if(buf1!=NULL)
		_aligned_free(buf1);
	if(buf2!=NULL)
		_aligned_free(buf2);

	// Exit the application
	exit(0);
}

int main(int argc, char* argv[])
{
_4FM_error_t api_status;		// the variable receiving status of the API
	_4FM_DeviceContext dev_ctx;		// handle to the device opened
	char *dma_buffer_in;			// buffer used for our DMA transactions ( hardware to host )
	char *dma_buffer_out;			// buffer used for our DMA transactions ( host to hardware )
	char devicetype[1024];			// receive the device type ( during _4FM_OpenDEviceEx() call )
	int devicenumber;				// receive the device number ( during _4FM_OpenDEviceEx() call )

	// DMA ( Direct Memory Access ) implementation requires 4k aligned buffers in the memory.
	// we allocate both buffers.
	dma_buffer_in = (char *)_aligned_malloc(_MEMORY_SIZE, 4096);
	dma_buffer_out = (char *)_aligned_malloc(_MEMORY_SIZE, 4096);
	
	// Open the 4DSP hardware 
	api_status = _4FM_OpenDeviceEx(&dev_ctx, devicetype, &devicenumber, OPEN_MODE_FIRST_DEVICE_FOUND);
	if(api_status!=_4FM_OK) {
		printf("No devices found in the system, exiting...\n");
		exit_handler(dma_buffer_in, dma_buffer_out, &dev_ctx);
	}
	printf("Found device %s at index %d\n", devicetype, devicenumber);

	// Place software, firmware and hardware into a known sane state
	api_status = _4FM_ResetDevice(&dev_ctx);
	if(api_status!=_4FM_OK) {
		printf("Could not reset, exiting...\n");
		exit_handler(dma_buffer_in, dma_buffer_out, &dev_ctx);
	}

	// We tell the firmware to route DMA transaction between the host and FPGA B, the main FPGA
	api_status = _4FM_SelectTarget(&dev_ctx, tgMainFPGA);
	if(api_status!=_4FM_OK) {
		printf("Could not tell the hardware to route DMA transaction to the main fpga exiting...\n");
		exit_handler(dma_buffer_in, dma_buffer_out, &dev_ctx);
	}

	// Create random data, this data is sent to the firmware afterwards
	srand((unsigned int)time(0));
	for(int i = 0; i < _MEMORY_SIZE; i++)
		dma_buffer_out[i] = (char)rand();

	// Send the data to the hardware using direct memory address operations
	api_status = _4FM_SendData(&dev_ctx, dma_buffer_out, _MEMORY_SIZE);
	if(api_status!=_4FM_OK) {
		printf("Could not send random data to the hardware device...\n");
		exit_handler(dma_buffer_in, dma_buffer_out, &dev_ctx);
	}

	// Receive the data from the hardware using direct memory address operations
	api_status = _4FM_ReceiveData(&dev_ctx, dma_buffer_in, _MEMORY_SIZE);
	if(api_status!=_4FM_OK) {
		printf("Could not receive random data from the hardware device...\n");
		exit_handler(dma_buffer_in, dma_buffer_out, &dev_ctx);
	}

	// compare the buffer send to the hardware and the buffer received from the hardware.
	// they should be equal as the hardware looped-back the data.
	if(memcmp(dma_buffer_out, dma_buffer_in, _MEMORY_SIZE))
		printf("Error, the data echoed by the hardware does not match the data we've sent out\n");
	else
	  printf("Success, the data echoed by the hardware does match the data we've sent out\n");
				
	printf("The test has finished!\n");

	// Terminate properly
	exit_handler(dma_buffer_in, dma_buffer_out, &dev_ctx);
}

later while searching it has something to do with the .obj file...
How can I link the libraries in .obj files... what actually is it?
 
Last edited:

Try adding an external declaration of functions at file-scope, just before the exit_handler function, e.g.

Code:
extern <ret_type> _4FM_CloseDevice(...);

Cheers
 

Capture.PNGHey thanks for your reply brother

I tried including extern as well with the function declaration. But it is not working...

It just gives the messages...unresolved external symbol....
What to do.... can bear this any more... :(

Well I have also uploaded the image... I have added all the libraries all right but why this things happening.

Bests,
Shan
 

Hi there,

Now the errors are less than in the previous post, isn't it? This means that the extern tip I suggested you could work if you extern all the other functions for which you got the error (although this is not the best way to do it :wink:). So, how are those functions declared in the header file?

Cheers
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top