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.
#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;
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;
}
//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.
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:
@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?
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?
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).
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.
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.