Borland CPort multiple declaration and Unresolved linker SetPortA function

I better note this down before I have to figure this out yet another time, if you're having problems using the CPort 3.1 comport library for Borland C++ 6 or BDS 2006 and your getting multiple declarations and unresolved linker SetPortA errors, this is how to get things running.

The first compiler error will look similar to the following :-

Show Plain Text
Text code
  1. [C++ Error] CPort.hpp(686): E2238 Multiple declaration for '_fastcall EComPort::EComPort(int)'
  2. [C++ Error] CPort.hpp(677): E2344 Earlier declaration of '_fastcall EComPort::EComPort(int)'
  3. [C++ Error] CPort.hpp(698): E2238 Multiple declaration for '_fastcall EComPort::EComPort(int,int)'
  4. [C++ Error] CPort.hpp(676): E2344 Earlier declaration of '_fastcall EComPort::EComPort(int,int)'
  5. [C++ Error] FrmMain.cpp(168): E2277 Lvalue required

The solution in this case is just to comment out the CPort.hpp lines 686 and 698

Once you've done that you'll get the following linker error :-

Show Plain Text
Text code
  1. [Linker Error] Error: Unresolved external '__fastcall Cport::TCustomComPort::SetPortA(const System::AnsiString)' referenced from C:\SRC\C\YOUR_SOURCE.OBJ

The solution to this one is to add the following to your projects conditional defines

Show Plain Text
Text code
  1. DONT_USE_WINSPOOL_SETPORTA

Now you will need to find your borlands winspool.h file e.g. C:\Program Files\Borland\BDS\Include and add the following DONT_USE_WINSPOOL_SETPORTA defines :-

Show Plain Text
Text code
  1. #ifndef DONT_USE_WINSPOOL_SETPORTA
  2. BOOL
  3. WINAPI
  4. SetPortA (
  5.     __in LPSTR pName,
  6.     __in LPSTR pPortName,
  7.     __in DWORD dwLevel,
  8.     __in LPBYTE pPortInfo
  9. );
  10. BOOL
  11. WINAPI
  12. SetPortW (
  13.     __in LPWSTR pName,
  14.     __in LPWSTR pPortName,
  15.     __in DWORD dwLevel,
  16.     __in LPBYTE pPortInfo
  17. );
  18. #ifdef UNICODE
  19. #define SetPort  SetPortW
  20. #else
  21. #define SetPort  SetPortA
  22. #endif // !UNICODE
  23. #endif //!DONT_USE_WINSPOOL_SETPORTA

For those interested in the Borland compatible CPort comport library, you can find the CPort project here

0 Responses to “Borland CPort multiple declaration and Unresolved linker SetPortA function”

Sorry, comments have been closed for this post.