Linking errors 2028 and 2019 in C++ program

Hi,
I am a beginner to C++ coding and I have managed to write the following code. I had successfully cleared all my coding and syntax errors. Now, I am stuck up with Linking errors 2028 and 2019. I googled for these errors on the internet and added all the additional dependencies libraries like kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wininet.lib. Moreover, I have also checked the Inherit from project or parent defaults checkbox.

I was hoping my errors would get solved but thats not the case.
I am working on Visual C++ 2010 Express.
By the way, this code is primarily written to read and write I2C data using a FTDI chip.

This is my code:


#include <stdio.h>
#include <windows.h>
#include <tchar.h>
#using <mscorlib.dll>

using namespace System;

#using <System.dll>
using namespace System::Diagnostics;
#include "FTCI2C.h"
#include "eeprom24C16.h"



#define MAX_FREQ_M24C64_CLOCK_DIVISOR 15 // equivalent to 400KHz
//#define MAX_FREQ_M24C64_CLOCK_DIVISOR 60 // equivalent to 100KHz
#define I2C_SPEED_400KHZ 15 // equivalent to 400KHz
#define I2C_SPEED_100KHZ 60 // equivalent to 100KHz

//Globals

//Local function prototypes
FTC_STATUS SetUpInterface( FTC_HANDLE *ftHandle, int speed );
void eepromTest( void );


int _tmain(int argc, _TCHAR* argv[])
{
boolean loop_exit = false;
int selection;

while( loop_exit == false )
{
//Present the user with a promt to select what test to run
// 1 = 24C16 eeprom test
// 2 = quit
Console::WriteLine( S"1=24c16 eeprom, 2=LM75 tsensor, 3=PCF8475 IO, 4=quit" );
Console::Write( S">" );
selection = Console::Read();
Console::ReadLine();//flush CRLF

//Do the test
switch( selection )
{
case 0x31:
eepromTest();
break;

case 0x32:
loop_exit = true;
break;
}
}//while( loop_exit == false )

return( 0 );
}

/*
SetUpInterface

Sets up the connection to the i2c driver.
*/
FTC_STATUS SetUpInterface( FTC_HANDLE *ftHandle, int clock_divisor )
{
FTC_STATUS Status;
DWORD dwNumDevices = 0;
char szDeviceName[100];
DWORD dwLocationID = 0;
DWORD dwClockFrequencyHz = 0;

Status = I2C_GetNumDevices( &dwNumDevices );
if( (Status == FTC_SUCCESS) && (dwNumDevices > 0) )
{
if( dwNumDevices == 1 )
{
Status = I2C_GetDeviceNameLocID(0, szDeviceName, 100, &dwLocationID);
if( Status == FTC_SUCCESS )
{
Status = I2C_OpenEx(szDeviceName, dwLocationID, ftHandle);
}
}
else
{
if (dwNumDevices == 2)
{
Status = I2C_GetDeviceNameLocID(1, szDeviceName, 50, &dwLocationID);

if (Status == FTC_SUCCESS)
{
Status = I2C_OpenEx(szDeviceName, dwLocationID, ftHandle);
}
}
}
}

if ((Status == FTC_SUCCESS) && (dwNumDevices > 0))
{
if (Status == FTC_SUCCESS)
{
Status = I2C_GetClock(clock_divisor, &dwClockFrequencyHz);
}

if (Status == FTC_SUCCESS)
{
Status = I2C_InitDevice(*ftHandle, clock_divisor); //65535
}
}

return( Status );
}

/*
eeprom24C16Test

Erases the device
Writes a test pattern to the device
Verifies the test pattern
*/
void eepromTest( void )
{
FTC_HANDLE ftHandle;
FTC_STATUS Status = FTC_SUCCESS;
C24C16 *eeprom;

//Set up link to hardware
Status = SetUpInterface( &ftHandle, I2C_SPEED_400KHZ );
if( Status != FTC_SUCCESS )
{
Console::WriteLine( "Failed to set up hardware" );
return;
}

eeprom = new C24C16( &ftHandle );

//Erase
Console::WriteLine( "Erasing..." );
Status = eeprom->Erase();
if( Status != FTC_SUCCESS )
{
Console::WriteLine( "Erase failed." );
return;
}

Sleep(200);

//Write test pattern
Console::WriteLine( "Writing test pattern..." );
Status = eeprom->WriteTestPattern();
if( Status != FTC_SUCCESS )
{
Console::WriteLine( "Failed writing test pattern." );
return;
}

Sleep( 200 );

//Verify
Console::WriteLine( "Verifying..." );
Status = eeprom->VerifyTestPattern();
if( Status == FTC_SUCCESS )
{
Console::WriteLine( "Verify succeeded" );
}
else
{
Console::WriteLine( "Verify failed" );
}

//Housekeeping
I2C_Close(ftHandle);
}
error LNK2028: unresolved token (0A00002E) "extern "C" unsigned long __stdcall I2C_Close(unsigned long)" (?I2C_Close@@$$J14YGKK@Z) referenced in function "void __cdecl eepromTest(void)" (?eepromTest@@$$FYAXXZ)
1>main.obj : error LNK2028: unresolved token (0A000035) "extern "C" unsigned long __stdcall I2C_GetClock(unsigned long,unsigned long *)" (?I2C_GetClock@@$$J18YGKKPAK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2028: unresolved token (0A000095) "extern "C" unsigned long __stdcall I2C_GetDeviceNameLocID(unsigned long,char *,unsigned long,unsigned long *)" (?I2C_GetDeviceNameLocID@@$$J216YGKKPADKPAK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2028: unresolved token (0A000096) "extern "C" unsigned long __stdcall I2C_GetNumDevices(unsigned long *)" (?I2C_GetNumDevices@@$$J14YGKPAK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2028: unresolved token (0A00009A) "extern "C" unsigned long __stdcall I2C_OpenEx(char *,unsigned long,unsigned long *)" (?I2C_OpenEx@@$$J212YGKPADKPAK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2028: unresolved token (0A0000A3) "extern "C" unsigned long __stdcall I2C_InitDevice(unsigned long,unsigned long)" (?I2C_InitDevice@@$$J18YGKKK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall I2C_InitDevice(unsigned long,unsigned long)" (?I2C_InitDevice@@$$J18YGKKK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall I2C_GetClock(unsigned long,unsigned long *)" (?I2C_GetClock@@$$J18YGKKPAK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall I2C_OpenEx(char *,unsigned long,unsigned long *)" (?I2C_OpenEx@@$$J212YGKPADKPAK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall I2C_GetDeviceNameLocID(unsigned long,char *,unsigned long,unsigned long *)" (?I2C_GetDeviceNameLocID@@$$J216YGKKPADKPAK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall I2C_GetNumDevices(unsigned long *)" (?I2C_GetNumDevices@@$$J14YGKPAK@Z) referenced in function "unsigned long __cdecl SetUpInterface(unsigned long *,int)" (?SetUpInterface@@$$FYAKPAKH@Z)
1>main.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall I2C_Close(unsigned long)" (?I2C_Close@@$$J14YGKK@Z) referenced in function "void __cdecl eepromTest(void)" (?eepromTest@@$$FYAXXZ)


Can someone help me with this error??
Thanks for your time and efforts.

theHermes5
Last edited on
This looks like a linker error. So it is possible that certain libraries still don't link.
Also, this isn't standard C++ code... which is why this forum below might be a better place for you to post this:

http://social.msdn.microsoft.com/Forums/en/category/visualc
Where are this I2C_... functions defined the linker is complaining of? Certainly not in those standard windows libs you added to the project.

A standard windows application cannot access hardware addresses directly...
These I2C functions are defined in a seperate header file. This is the code written in FTC12C.h. I did not change anything in this header file.


#ifndef FTCI2C_H
#define FTCI2C_H
#ifdef FTCI2C_EXPORTS
#define FTCI2C_API __declspec(dllexport)
#else
#define FTCI2C_API __declspec(dllimport)
#endif

typedef DWORD FTC_HANDLE;
typedef ULONG FTC_STATUS;

#define NO_WRITE_TYPE 0
#define BYTE_WRITE_TYPE 1
#define PAGE_WRITE_TYPE 2

#define BYTE_READ_TYPE 1
#define BLOCK_READ_TYPE 2

#define STANDARD_MODE 1
#define FAST_MODE 2

#define FTC_SUCCESS 0 // FT_OK
#define FTC_INVALID_HANDLE 1 // FT_INVALID_HANDLE
#define FTC_DEVICE_NOT_FOUND 2 //FT_DEVICE_NOT_FOUND
#define FTC_DEVICE_NOT_OPENED 3 //FT_DEVICE_NOT_OPENED
#define FTC_IO_ERROR 4 //FT_IO_ERROR
#define FTC_INSUFFICIENT_RESOURCES 5 // FT_INSUFFICIENT_RESOURCES

#define FTC_FAILED_TO_COMPLETE_COMMAND 20 // cannot change, error code mapped from FT2232c classes
#define FTC_FAILED_TO_SYNCHRONIZE_DEVICE_MPSSE 21 // cannot change, error code mapped from FT2232c classes
#define FTC_INVALID_DEVICE_NAME_INDEX 22 // cannot change, error code mapped from FT2232c classes
#define FTC_NULL_DEVICE_NAME_BUFFER_POINTER 23 // cannot change, error code mapped from FT2232c classes
#define FTC_DEVICE_NAME_BUFFER_TOO_SMALL 24 // cannot change, error code mapped from FT2232c classes
#define FTC_INVALID_DEVICE_NAME 25 // cannot change, error code mapped from FT2232c classes
#define FTC_INVALID_LOCATION_ID 26 // cannot change, error code mapped from FT2232c classes
#define FTC_DEVICE_IN_USE 27 // cannot change, error code mapped from FT2232c classes
#define FTC_TOO_MANY_DEVICES 28 // cannot change, error code mapped from FT2232c classes
#define FTC_EXTERNAL_DEVICE_NOT_FOUND 29
#define FTC_INVALID_CLOCK_DIVISOR 30
#define FTC_NULL_CONTROL_DATA_BUFFER_POINTER 31
#define FTC_INVALID_NUMBER_CONTROL_BYTES 32
#define FTC_CONTROL_ACKNOWLEDGE_TIMEOUT 33
#define FTC_NULL_WRITE_DATA_BUFFER_POINTER 34
#define FTC_INVALID_NUMBER_DATA_BYTES_WRITE 35
#define FTC_DATA_ACKNOWLEDGE_TIMEOUT 36
#define FTC_INVALID_WRITE_TYPE 37
#define FTC_NUMBER_BYTES_TOO_SMALL_PAGE_WRITE 38
#define FTC_NULL_PAGE_WRITE_BUFFER_POINTER 39
#define FTC_NULL_READ_DATA_BUFFER_POINTER 40
#define FTC_INVALID_NUMBER_DATA_BYTES_READ 41
#define FTC_INVALID_READ_TYPE 42
#define FTC_INVALID_COMMS_MODE 43
#define FTC_NULL_DLL_VERSION_BUFFER_POINTER 44
#define FTC_DLL_VERSION_BUFFER_TOO_SMALL 45
#define FTC_NULL_LANGUAGE_CODE_BUFFER_POINTER 46
#define FTC_NULL_ERROR_MESSAGE_BUFFER_POINTER 47
#define FTC_ERROR_MESSAGE_BUFFER_TOO_SMALL 48
#define FTC_INVALID_LANGUAGE_CODE 49
#define FTC_INVALID_STATUS_CODE 50

#ifdef __cplusplus
extern "C" {
#endif

FTCI2C_API
FTC_STATUS WINAPI I2C_GetNumDevices(LPDWORD lpdwNumDevices);

FTCI2C_API
FTC_STATUS WINAPI I2C_GetDeviceNameLocID(DWORD dwDeviceNameIndex, LPSTR lpDeviceNameBuffer, DWORD dwBufferSize, LPDWORD lpdwLocationID);

FTCI2C_API
FTC_STATUS WINAPI I2C_OpenEx(LPSTR lpDeviceName, DWORD dwLocationID, FTC_HANDLE *pftHandle);

FTCI2C_API
FTC_STATUS WINAPI I2C_Open(FTC_HANDLE *pftHandle);

FTCI2C_API
FTC_STATUS WINAPI I2C_Close(FTC_HANDLE ftHandle);

FTCI2C_API
FTC_STATUS WINAPI I2C_InitDevice(FTC_HANDLE ftHandle, DWORD dwClockDivisor);

FTCI2C_API
FTC_STATUS WINAPI I2C_GetClock(DWORD dwClockDivisor, LPDWORD lpdwClockFrequencyHz);

FTCI2C_API
FTC_STATUS WINAPI I2C_SetClock(FTC_HANDLE ftHandle, DWORD dwClockDivisor, LPDWORD lpdwClockFrequencyHz);

FTCI2C_API
FTC_STATUS WINAPI I2C_SetLoopback(FTC_HANDLE ftHandle, BOOL bLoopbackState);

FTCI2C_API
FTC_STATUS WINAPI I2C_SetMode(FTC_HANDLE ftHandle, DWORD dwCommsMode);

#define MAX_WRITE_CONTROL_BYTES_BUFFER_SIZE 256 // 256 bytes

typedef BYTE WriteControlByteBuffer[MAX_WRITE_CONTROL_BYTES_BUFFER_SIZE];
typedef WriteControlByteBuffer *PWriteControlByteBuffer;

typedef struct FTC_Page_Write_Data{
DWORD dwNumPages;
DWORD dwNumBytesPerPage;
}FTC_PAGE_WRITE_DATA, *PFTC_PAGE_WRITE_DATA;

#define MAX_WRITE_DATA_BYTES_BUFFER_SIZE 65536 // 64k bytes

typedef BYTE WriteDataByteBuffer[MAX_WRITE_DATA_BYTES_BUFFER_SIZE];
typedef WriteDataByteBuffer *PWriteDataByteBuffer;

FTCI2C_API
FTC_STATUS WINAPI I2C_Write(FTC_HANDLE ftHandle, PWriteControlByteBuffer pWriteControlBuffer,
DWORD dwNumControlBytesToWrite, BOOL bControlAcknowledge, DWORD dwControlAckTimeoutmSecs,
BOOL bStopCondition, DWORD dwDataWriteTypes, PWriteDataByteBuffer pWriteDataBuffer, DWORD dwNumDataBytesToWrite,
BOOL bDataAcknowledge, DWORD dwDataAckTimeoutmSecs, PFTC_PAGE_WRITE_DATA pPageWriteData);

#define MAX_READ_DATA_BYTES_BUFFER_SIZE 65536 // 64k bytes

typedef BYTE ReadDataByteBuffer[MAX_READ_DATA_BYTES_BUFFER_SIZE];
typedef ReadDataByteBuffer *PReadDataByteBuffer;

FTCI2C_API
FTC_STATUS WINAPI I2C_Read(FTC_HANDLE ftHandle, PWriteControlByteBuffer pWriteControlBuffer,
DWORD dwNumControlBytesToWrite, BOOL bControlAcknowledge, DWORD dwControlAckTimeoutmSecs,
DWORD dwDataReadTypes, PReadDataByteBuffer pReadDataBuffer, DWORD dwNumDataBytesToRead);

FTCI2C_API
FTC_STATUS WINAPI I2C_GetDllVersion(LPSTR lpDllVersionBuffer, DWORD dwBufferSize);

FTCI2C_API
FTC_STATUS WINAPI I2C_GetErrorCodeString(LPSTR lpLanguage, FTC_STATUS StatusCode,
LPSTR lpErrorMessageBuffer, DWORD dwBufferSize);


#ifdef __cplusplus
}
#endif


#endif

@coder777 did you mean to ask for this header file code in your question when you meant that the I2C.. functions are not defined? If not, then can you elaborate on what is it that I need to do?
Last edited on
Is this what you meant in your question coder777?
Nope, they are declared in the header (not defined).

Obviously it's a DLL. You need to link against the appropriate lib that comes with this kind of SDK
How do I search and link to the appropriate library?I looked up at the company which produces these chips' website and all I could find was a folder to help programmers and that folder included a sample program ( incomplete), chip;s header file and the usual stadfx.h and stadfx.cpp file. Am I missing something here?
Sarching to google I found this:
http://www.ftdichip.com/Projects/MPSSE/FTCI2C.htm
And this:
http://ftdi-guyvo.blogspot.ro/2008/09/ftci2c-dll-functionalities.html

So you need to add ftci2c.lib to linker input and distribute ftci2c.dll with your application. Of course, .NET Framework 4.0 runtime must also be installed in user computer, as your program depends on it (no, it is not written in c++ as you could think).
Where did you get the header from? Usually it's tied together...

Look at this:

http://ftdi-guyvo.blogspot.de/2008/09/ftci2c-dll-functionalities.html
Thanks for your quick replies.

I have downloaded the ftci2c.lib,ftci2c.dll file and copied them onto my project that contains other file. I have also added this ftci2c.lib onto my additional dependencies libraries and I have also added the directory of the ftci2c.lib into my additional library directories.

But,I have no clue about .NET and so can you advise as to what I must do to distribute ftci2c.dll file with it?

That dll file must be in same folder as your program when it is executed, no need to include the dll in your project, only the *.lib file is neccessary.

The .NET 4./0 runtime can be downloaded from here:
http://www.microsoft.com/en-us/download/details.aspx?id=17718

This must be installed in users computer to be able to run your program.

My advice is to get rid of C++/CLI crap and use only pure win32 console application, that way there will be no need for any .NET runtime.
Last edited on
modoran wrote:
My advice is to get rid of C++/CLI crap and use only pure win32 console application, that way there will be no need for any .NET runtime.
I agree with that. Just create a new win32 console project.

Instead of Console::WriteLine( "Verify succeeded" ); you'd use cout << "Verify succeeded" << endl;
I have added the FTCI2C.lib file in my additional dependencies libraries, copied FTCI2C.dll file in the same folder as other files. But, still I get this linking error error LNK2019: unresolved external symbol __imp__I2C_SetMode@8 referenced in function _main and I don't know what to do to overcome this error.?
Everything was created in a win32 console project.

Thanks for your time.
You need to add the path to the lib as well (the linker silently ignores the lib it can't find)
Topic archived. No new replies allowed.