Author Topic: CB can't find iostream  (Read 11081 times)

Offline msm98lw

  • Single posting newcomer
  • *
  • Posts: 7
CB can't find iostream
« on: June 20, 2016, 05:42:46 pm »
I am new to code::blocks.

I installed cb mingw on a windows 7 machine. I used settings to specify the root directory for the compiler exes and linker settings to specify the path for the include files.

When I tried to compile Hello World (you have to start somewhere) I got a message "fatal error: iostream: no such file or directory".

What am I doing wrong?
Lew

Offline msm98lw

  • Single posting newcomer
  • *
  • Posts: 7
Re: CB can't find iostream - got that now no target
« Reply #1 on: June 20, 2016, 05:59:39 pm »
OK I found how to set the path for the include modules and the .h modules.

Now the compile message is "build file: "no target" in CS390 Learning (compiler: GNU GCC compiler)

As far as I can tell the target is set to debug.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline msm98lw

  • Single posting newcomer
  • *
  • Posts: 7
Re: CB can't find iostream
« Reply #3 on: June 20, 2016, 07:23:19 pm »
Thanks staht01, that helped get me through not finding a .h module.
Now it's blowing up on "namespace std _GLIBCXX_VISIBILITY (default)" which is a line in iostream.

Looks like it's hands on help from the instructor or ...

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: CB can't find iostream
« Reply #4 on: June 20, 2016, 07:50:58 pm »
If you post the full rebuild log; I might be able to see the causes of some simple errors.

For C or C++ programming questions/help I suggest, http://cboard.cprogramming.com/forum.php
Code
http://cboard.cprogramming.com/forum.php

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

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: CB can't find iostream
« Reply #5 on: June 20, 2016, 09:54:31 pm »
A wild guess, your file has ".c" as an extension and not ".cpp" ? Using <iostream> is strictly C++

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline msm98lw

  • Single posting newcomer
  • *
  • Posts: 7
Re: CB can't find iostream
« Reply #6 on: June 21, 2016, 03:58:08 pm »
The program code is at the bottom.
These compile/build errors (only the first few) are in memoryfwd.h:
-------------- Build: Debug in cb learning (compiler: GNU GCC Compiler)---------------

mingw32-gcc.exe -Wall -g -I"C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++" -I"C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\mingw32\bits" -I"C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\mingw32" -c "C:\Data\CS 390\code\cb learning\hello.c" -o obj\Debug\hello.o
In file included from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/bits/stringfwd.h:40:0,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/iosfwd:39,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/ios:38,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/ostream:38,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/iostream:39,
                 from C:\Data\CS 390\code\cb learning\hello.c:1:
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/bits/memoryfwd.h:50:1: error: unknown type name 'namespace'
 namespace std _GLIBCXX_VISIBILITY(default)
 ^

C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/bits/memoryfwd.h:51:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^

In file included from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/iosfwd:39:0,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/ios:38,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/ostream:38,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/iostream:39,
                 from C:\Data\CS 390\code\cb learning\hello.c:1:
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/bits/stringfwd.h:42:1: error: unknown type name 'namespace'
 namespace std _GLIBCXX_VISIBILITY(default)
 ^
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/bits/stringfwd.h:43:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/bits/postypes.h:40:0,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/iosfwd:40,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/ios:38,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/ostream:38,
                 from C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/iostream:39,
                 from C:\Data\CS 390\code\cb learning\hello.c:1:
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/cwchar:62:1: error: unknown type name 'namespace'
 namespace std
 ^
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/cwchar:63:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/cwchar:135:1: error: unknown type name 'namespace'
 namespace std _GLIBCXX_VISIBILITY(default)
 ^
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/cwchar:136:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++/cwchar:241:1: error: unknown type name 'namespace'
 namespace __gnu_cxx
 ^
---------
The code is:
#include <iostream>

using namespace std;

int main()
{
    cout << "hello world\n";
    return 0;
}
 

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: CB can't find iostream
« Reply #7 on: June 21, 2016, 04:03:27 pm »
Name the program file with the correct file extension instead of using the name "hello.c" try using "hello.cpp".

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

Offline msm98lw

  • Single posting newcomer
  • *
  • Posts: 7
Re: CB can't find iostream
« Reply #8 on: June 21, 2016, 04:19:32 pm »
I created a new project and named the source hello.cpp. On build I got these errors:

-------------- Build: Debug in test 2 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -g -I"C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++" -I"C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\mingw32\bits" -I"C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\mingw32" -c "C:\Data\CS 390\code\test 2\hello.cpp" -o obj\Debug\hello.o
mingw32-g++.exe  -o "bin\Debug\test 2.exe" obj\Debug\hello.o   "C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++" "C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\mingw32\bits" "C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\mingw32" "C:\Program Files (x86)\CodeBlocks\MinGW\bin"
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: cannot find C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++: Permission denied
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: cannot find C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\mingw32\bits: Permission denied
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: cannot find C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\mingw32: Permission denied
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: cannot find C:\Program Files (x86)\CodeBlocks\MinGW\bin: Permission denied
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
5 error(s), 0 warning(s) (0 minute(s), 3 second(s))

I've set the 5 error messages to bold and italic.

thanks
Lew
 

Offline msm98lw

  • Single posting newcomer
  • *
  • Posts: 7
Re: CB can't find iostream
« Reply #9 on: June 21, 2016, 04:47:56 pm »
I found ld.exe in C:\Program Files (x86)\CodeBlocks\MinGW\mingw32\bin and added that path to the global compiler settings. I got the same result except this time there were 6 errors.

Thanks
Lew

Offline msm98lw

  • Single posting newcomer
  • *
  • Posts: 7
Re: CB can't find iostream
« Reply #10 on: June 21, 2016, 05:27:13 pm »
Thanks stahta01. I found another post, about permission denied, where you linked to the answer.

I had added directories to the linker setting/link libraries in random attempts to solve my problems. When I removed all the directories, it compiled and ran correctly.

Thanks
Lew

Offline RealHighlander

  • Single posting newcomer
  • *
  • Posts: 2
Re: CB can't find iostream
« Reply #11 on: June 30, 2016, 03:39:08 pm »
If it is of any help, in order for C:B to find precompiled headers like iostream, you must set up a project and then a program in the project should work fine for all C++ headers.