Code::Blocks Forums

User forums => Help => Topic started by: msm98lw on June 20, 2016, 05:42:46 pm

Title: CB can't find iostream
Post by: msm98lw 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
Title: Re: CB can't find iostream - got that now no target
Post by: msm98lw 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.
Title: Re: CB can't find iostream
Post by: stahta01 on June 20, 2016, 06:00:42 pm
http://wiki.codeblocks.org/index.php/FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php/FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)
Title: Re: CB can't find iostream
Post by: msm98lw 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 ...
Title: Re: CB can't find iostream
Post by: stahta01 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 (http://cboard.cprogramming.com/forum.php)
Code
http://cboard.cprogramming.com/forum.php

Tim S.
Title: Re: CB can't find iostream
Post by: yvesdm3000 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
Title: Re: CB can't find iostream
Post by: msm98lw 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;
}
 
Title: Re: CB can't find iostream
Post by: stahta01 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.
Title: Re: CB can't find iostream
Post by: msm98lw 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
 
Title: Re: CB can't find iostream
Post by: msm98lw 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
Title: Re: CB can't find iostream
Post by: msm98lw 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
Title: Re: CB can't find iostream
Post by: RealHighlander 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.