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- [C++ Error] CPort.hpp(686): E2238 Multiple declaration for '_fastcall EComPort::EComPort(int)'
- [C++ Error] CPort.hpp(677): E2344 Earlier declaration of '_fastcall EComPort::EComPort(int)'
- [C++ Error] CPort.hpp(698): E2238 Multiple declaration for '_fastcall EComPort::EComPort(int,int)'
- [C++ Error] CPort.hpp(676): E2344 Earlier declaration of '_fastcall EComPort::EComPort(int,int)'
- [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- [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- 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- #ifndef DONT_USE_WINSPOOL_SETPORTA
- BOOL
- WINAPI
- SetPortA (
- __in LPSTR pName,
- __in LPSTR pPortName,
- __in DWORD dwLevel,
- __in LPBYTE pPortInfo
- );
- BOOL
- WINAPI
- SetPortW (
- __in LPWSTR pName,
- __in LPWSTR pPortName,
- __in DWORD dwLevel,
- __in LPBYTE pPortInfo
- );
- #ifdef UNICODE
- #define SetPort SetPortW
- #else
- #define SetPort SetPortA
- #endif // !UNICODE
- #endif //!DONT_USE_WINSPOOL_SETPORTA
For those interested in the Borland compatible CPort comport library, you can find the CPort project here