c header files

Pages: 12
cc1.exe: error: unrecognised command line option '-std=c11'


The correct option would be -std=c++11.
is -std+c++11 not for code written in c++ I am trying to learn c
is -std+c++11 not for code written in c++ I am trying to learn c


You are correct. I didn't pay close enough attention.
Hi Rodney,

try :

-std=gnu11


This is the gnu extensions to the c11 standard, not sure why the other option didn't work. For your code it might not matter, the default could be just fine.

Any way as I said earlier, read the manual try other options.

BTW, really try not to use goto in your code, use a loop instead.

Also make more use of functions.

Edit: The function call is Sleep with a capital S in windows.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298%28v=vs.85%29.aspx


HTH
Last edited on
> I copied the code below into my new file where the gcc 4.8.1 is.

Don't do that; you may inadvertently do something that breaks GCC.
Do not write anything into the installation directory C:\GCC_4_8_1 or any of the directories under it.

For each of your new programs, create a fresh directory. For instance, c:\learn_c\console_clrs for this program.


> I tried to compile it with the following which I cut and pasted and amended from number 5. Above.
> gcc -std=c11 -Wall -Wextra -pedantic-errors -c cur_con.c

Each time you open a new command window, before you try to compile anything, first type C:\GCC_4_8_1\MinGW\set_distro_paths.bat at the command prompt.
You need to do this only once, right at the beginning.



>then tried to compile it using gcc cur_con.c -o cur_con and then I get a really weird message
> c:\users\RODNEY~1\AppData\Local1\Temp\cc3o17Le.o:cur_con.c:<.text+0x2df>: undefined reference to sleep'

Compile with gcc -std=c11 -Wall -Wextra -pedantic-errors cur_con.c
Note: omit -c, you want to compile and link.

You would get an error: error: implicit declaration of function 'sleep'

Fix the error (change 'sleep' to 'Sleep' with an upper case 'S'), recompile.
You would get a few warnings about unused variables. (Ideally you should fix these by removing the variables that you never use.)
Run the program to test it.
SORRY !! :)

Still have a problem I ran it exactly as your instructions and when I tried to test I typed cur_con in the command prompt and got cur_con is not recognised as an internal or external command,operable programor batch file.

I compiled the code as instructed, and got the warning messages as you said I would.




I Noticed That in the text editor when I save the code the sleep, if, int etc don't change colour like they used to

[/i][/u]
Last edited on
> I tried to test I typed cur_con in the command prompt and got
> cur_con is not recognised as an internal or external command,operable programor batch file.

Did you miss either of these?
Note: omit -c, you want to compile and link
Fix the error (change 'sleep' to 'Sleep' with an upper case 'S')

Compile and link with:
gcc -std=c11 -Wall -Wextra -pedantic-errors cur_con.c && echo **** SUCCESS! ****

If there were no errors while compiling and linking, the last line printed out would be:
**** SUCCESS! ****



> I Noticed That in the text editor when I save the code the sleep, if, int etc don't change colour like they used to

See: http://vim.wikia.com/wiki/Change_the_color_scheme
I typed in the below

gcc -std=c11 -Wall -Wextra -pedantic-errors cur_con.c && echo **** SUCCESS! ****

I changed all the lowercase s in sleep to capitals.

The error this time is cc1.exe: error: unrecognised command line option 'std=11'

I then changed std=11 to std=99 got the warning unused variable ****SUCCESS****

then I tried to test the code and got cur_con is not recognised as an internal or external command, operable program or batch file.




I am really messing you around and am totally total confused now. Should I delete everything and set it all up again?
Last edited on
> Should I delete everything and set it all up again?

No. Just pay attention to the messages from the compiler.

> error: unrecognised command line option 'std=11'

You typed -std=11 instead of -std=c11


**** EDIT: added ****

To create an executable file cur_con.exe (instead of a.exe), add -ocur_con.exe:

gcc -std=c11 -Wall -Wextra -pedantic-errors -ocur_con.exe cur_con.c && echo **** SUCCESS! ****
Last edited on
Hi I am sure you must shudder when you see my reply's.

I have been working through this all day and its starting to make a little sense.

I have compiled

using

gcc -std=c11 -Wall -Wextra -pedantic-errors -occ1.exe cc1.c && echo **** SUCCESS! ****

I changed the file name to cc1 for ease of typing.

When compiling the warnings for unused variables as you said would come do,

in order to understand what I am doing when compiling where can I read an explanation on the above.

2. How do I save the compiled program to a flash stick to see if it will run on another machine. Do I just copy all the files into a folder and save to a flash drive.

3. Before I compile each time do I first enter at the command line the following


C:\GCC_4_8_1\MinGW\set_distro_paths.bat

Now I can get on with the headers I originally started trying to learn.

Once again many thanks for your help

Rodney

> in order to understand what I am doing when compiling where can I read an explanation on the above.

Tutorial: http://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html

To read up on gcc options, start here:
http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Option-Summary.html#Option-Summary


> How do I save the compiled program to a flash stick to see if it will run on another machine.
> Do I just copy all the files into a folder and save to a flash drive.

First, create the executable file. For instance,

gcc -std=c11 -Wall -Wextra -pedantic-errors -O3 -static-libgcc -omy_program.exe my_program.c

-O3 Optimize
http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Optimize-Options.html#Optimize-Options

-static-libgcc Make the program self contained and portable by linking statically to the library
http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Link-Options.html#Link-Options

Then, copy just the executable (my_program.exe in the above example) to the flash drive, and you can run it on other windows machines.



> 3. Before I compile each time do I first enter at the command line the following
> C:\GCC_4_8_1\MinGW\set_distro_paths.bat

Do it just once when you first open the command window. It adds the directory containing the compiler and other tools required to build the program to the PATH environment variable.
https://en.wikipedia.org/wiki/PATH_(variable)

Once you have done that, you can compile as many times as you want, till you close the command window.


Last edited on
I have managed now to compile and work through the header example I am not 100% sure of it yet but will keep at it and as I progress ask the necessary questions.

Topic archived. No new replies allowed.
Pages: 12