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.
(default) 11 queries took 6 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`221
4DESCRIBE `categories`221
5DESCRIBE `posts_tags`220
6DESCRIBE `categories_posts`221
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'borland-cport-multiple-declaration-and-unresolved-linker-setporta-function' LIMIT 1110
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (81) 001
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 81 AND `PostsTag`.`tag_id` = `Tag`.`id`) 660
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 81 AND `CategoriesPost`.`category_id` = `Category`.`id`) 110
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 8110