Author Topic: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error [solved]  (Read 11382 times)

Offline Joe

  • Multiple posting newcomer
  • *
  • Posts: 10
Greeting All!

Code::Blocks is exactly what I was looking for, and you guys did a great job!
I have an issue with a simple C++ program, using a string variable. Below, I have included the code from a file named StringTest.cpp:

----------- Code: StringTest.cpp -----------------------

1.  #include <iostream>
2.  #include <string>
3.  
4.  int main()
5.  {
6.      using namespace std;
7.  
8.      string aName = "Hello World";
9.      cout << "Hello World\n" << endl;
10.     cout << aName;
11.
12.     return 0;
13. }

--------------------------------------------------------

The program builds with no errors or warnings. Below I have included the ouput from the build:


-------------- Build: Debug in StringWork ---------------

bcc32.exe -q -w -x  -v    -IC:\Borland\BCC55\Include  -oobj\Debug\StringTest.obj -c StringTest.cpp
StringTest.cpp:
ilink32.exe -q -ap -v  -LC:\Borland\BCC55\lib -LC:\Borland\BCC55\lib\psdk  c0x32 obj\Debug\StringTest.obj ,bin\Debug\StringWork.exe,,cw32mt.lib import32.lib ,,
Output size is 119.50 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
 
---------------------------------------------------------

When I run the executable from within Code::Blocks (or by just double clicking the .exe file) I first get an error from Windows that says:

-------------- Error: Windows XP Home SP3----------------

StringWork.exe has encountered a problem and needs to close.  We are sorry for the inconvenience.

---------------------------------------------------------

Then the console, started by Code::Blocks, displays:

------------- Information: Code::Blocks 10.05 -----------

Process returned -1073741819 (0xC0000005)   execution time : 12.344  s
Press any key to continue.

---------------------------------------------------------

If I comment out line 10 [cout << aName;], the program compiles and runs as expected.


OS: Windows XP Home SP3
Code::Blocks: 10.05
Compiler: Borland 5.5, 5.82 (sp1, sp2)

Thank you for your help.
« Last Edit: November 30, 2010, 06:41:56 am by Joe »
Joe Long
WinXP Home/SP3
Code::Blocks/10.05
Borland 5.5/SP2
C++ Student

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #1 on: November 29, 2010, 01:07:13 am »
Correction, your code fails the C::B sample code works; your C++ code has a problem and BCC 5.1 has a bug.

The C::B sample code Works for me using C::B 10.05 and Borland 5.5

I saw no difference from your build log; my Borland installation is in "C:\GreenApps\BCC55".

OS Windows 7 32 Bit; I have some of the Win 7 security turned off.

Tim S.

Code
bcc32.exe -q -w -x  -v    -IC:\GreenApps\BCC55\Include  -oobj\Debug\main.obj -c main.cpp
main.cpp:
ilink32.exe -q -ap  -v  -LC:\GreenApps\BCC55\Lib -LC:\GreenApps\BCC55\Lib\PSDK  c0x32 obj\Debug\main.obj ,bin\Debug\testbcc55.exe,,cw32mt.lib import32.lib ,,
Output size is 119.00 KB
« Last Edit: November 29, 2010, 01:16:07 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #2 on: November 29, 2010, 01:15:32 am »
Code
using namespace std;

The using must NOT be inside a function; BCC 5.5 has a bug. I suggest using a newer Compiler.
The fixed code worked OK using BCC 6.1.

This IS NOT an Code::Blocks issue; this thread is likely to be locked.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Joe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #3 on: November 29, 2010, 01:34:50 am »
Thank you for your quick response Tim.

1.) The code sample I posted compiles and runs perfectly from the command line.
2.) Based on your second response, I have moved [using namespace std;] to below the includes and above the [int main()] declaration.

Recompiling the program and running produces the same error as previously described.

Which forum should this be posted in Tim?
Joe Long
WinXP Home/SP3
Code::Blocks/10.05
Borland 5.5/SP2
C++ Student

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #4 on: November 29, 2010, 01:40:10 am »
1.) The code sample I posted compiles and runs perfectly from the command line.

Are you sure, it works from the Command line running the exact same command to Compile and Link?
It FAILS the same way for me on the command line.

Which forum should this be posted in Tim?

If it is a compiler bug, you need to find a site that supports the Compiler!

Tim S.
« Last Edit: November 29, 2010, 01:50:16 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Joe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #5 on: November 29, 2010, 02:10:46 am »
Hello again Tim.

I am using the (and have been for some time) command console in Windows to compile the source file. I have used the same flags as C::B used for it's compile, and again it compiles, links and runs as expected.

It is not a compiler bug. It is either a user bug :) or perhaps I have misconfigured something in the C::B IDE Environment. Although, I must admit that I simply installed C::B, selected Borland 5.5 from the options and accepted all the defaults.

Thank you for your patience and help in this matter. It means a lot to me Tim.

 
Joe Long
WinXP Home/SP3
Code::Blocks/10.05
Borland 5.5/SP2
C++ Student

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #6 on: November 29, 2010, 02:36:28 am »
If you run "bcc32 -v" on the command line with the same setup as to compile the code what do you get?

I get this.

Code
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Error E2266: No file names given

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Joe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #7 on: November 29, 2010, 02:50:07 am »
I get the same output (version) as you did Tim. [bcc32 -v]

Hey! I think I stumbled on to the solution. I finally found a place where I can work with the compiler flags and the Linker flags. /Project/Build options.../Linker settings/Add    and then by adding all of the libraries available in borland/bcc55/lib and all the libraries available in borland/bcc55/lib/psdk   like magic, the source file compiles, links and runs from the C::B IDE.

I will work my way back, through trial and error, and see if I can nail down which libraries are required for the Borland 5.5 sp2 compiler, and post that information, in case some other rookie, like me, ever runs in to the same issue.

Any idea which libraries should be included Tim?
Joe Long
WinXP Home/SP3
Code::Blocks/10.05
Borland 5.5/SP2
C++ Student

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #8 on: November 29, 2010, 03:18:22 am »
Any idea which libraries should be included Tim?

No, I just use BCC every few months to test the patches for wxWidgets works.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #9 on: November 30, 2010, 01:11:59 am »
How to set up Borland outside of Code::Blocks; this is the way I normally use Borland with Code::Blocks.
Inside Code::Blocks, I have no search folders for Linker or Compilers.

http://cboard.cprogramming.com/faq-board/31181-faq-please-help-use-borland-compiler.html

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Joe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Code::Blocks/Borland Compiler 5.5/ cout << stringVar error
« Reply #10 on: November 30, 2010, 06:25:02 am »
Problem Solved:

The issue boils down to the linker libraries included in your project.
There are two library files that need to be present, and there are two places within C::B where you can add them.

By default, when I create a console application in C::B, two library files are automatically added to the project:
   - cw32mt.lib
   - import32.lib

I found these files in the C::B IDE on the main menu:
   - Project/Build Options.../[Project build options form will open.]
   - In the listbox hierarchy select the [project name]
      - Not the [Debug] or [Release] options
   - Select the [Linker settings] tab
      - [Link libraries] listbox contains the library files for the project
   - On my system the files cw32mt.lib and import32.lib are listed
      
I changed the cw32mt.lib file to cw32.lib and the console application compiled, linked and ran as expected.

The second place in C::B to add, remove or change libraries can be found on the main menu:
   - Settings/Compiler and debugger.../[Compiler and debugger settings form will open.]
   - In the listbox hierarchy select [Global compiler settings]
   - Select the [Linker settings] tab
   - Libraries can be added, removed here and will be included with every project.

If I add the needed libraries in the global compiler section, it includes them as well as those two default files in the project section. Working on that issue now.
Joe Long
WinXP Home/SP3
Code::Blocks/10.05
Borland 5.5/SP2
C++ Student