Error: Symbol 'chrono' could not be resolved & ‘chrono’ is not a namespace-name

This is my source code:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <chrono>

//using namespace std;

int main() {
	using namespace std::chrono;

	return 0;
}

The compiler shows the following error in using namespace std::chrono;:
> ‘chrono’ is not a namespace-name

What does this error mean?
Thanks.
Last edited on
either your compiler is outdated or you didn't ask for c++11 mode.
show your compile command.
I'm using Eclipse Luna. Is there a way to see the compiler command being executed?
To ask for the c++11 mode I set the flag -std=c++0x (I am using gcc version 4.3.4):
1.- Right click on my project
2.- Properties -> C/C++ Build -> Settings -> Cross GCC Compiler -> Miscellaneus
3.- Append the flag -std=c++0x in the "Other flags" field

ne555 What do you mean with
your compiler is outdated
?
Last edited on
The <chrono> header is an addition to the standard added with the C++11 standard and older versions of the gcc compiler may not support this feature.

And since you happen to be using a very old version (4.3.4) which happens to be severely lacking in C++11 support you will likely run into problems.

You really should consider updating your compiler to a more current version like version 7.1 or higher so that you can use the current standard (C++14) and have access to parts of the next standard (C++17) available as well.

According to this page,
https://stackoverflow.com/a/23298857

gcc supports chrono from version 4.4


So I guess that confirms the diagnosis, since you are using gcc version 4.3.4, your compiler is outdated. You need a newer version.
Last edited on
For C++11, avoid any version of GCC earlier than 5.1
In versions earlier than that, the GNU library was a joke.
Thanks for your answers.

I followed this tutorial to install a new version of gcc:
http://mortenvp.com/installing-a-newer-gccg-on-ubuntu-12-04-lts/

I checked the installed version in the terminal:
% gcc -v
> gcc version 5.4.0 20160603 (Ubuntu 5.4.0-3ubuntu1~12.04)

However the compiler still shows problems in the same line but a different error:
Symbol 'chrono' could not be resolved


Any ideas?
Last edited on
I'll repeat myself: show your compile command.
The flag should be -std=c++11
----
The flag should be -std=c++11
----
The flag -std=c++11 is not available in % man gcc:
-std=
*c90
*c89
*iso9899:1990
Support all ISO C90 programs (certain GNU extensions that conflict with ISO C90 are disabled). Same as -ansi for C code.
*iso9899:199409
ISO C90 as modified in amendment 1.
*c99
*c9x
*iso9899:1999
*iso9899:199x
ISO C99. Note that this standard is not yet fully supported; see <http://gcc.gnu.org/gcc-4.6/c99status.html> for more
information. The names c9x and iso9899:199x are deprecated.
*c1x ISO C1X, the draft of the next revision of the ISO C standard. Support is limited and experimental and features enabled by
this option may be changed or removed if changed in or removed from the standard draft.
*gnu90
*gnu89
GNU dialect of ISO C90 (including some C99 features). This is the default for C code.
*gnu99
*gnu9x
*gnu++98
GNU dialect of -std=c++98. This is the default for C++ code.
*c++0x
The working draft of the upcoming ISO C++0x standard. This option enables experimental features that are likely to be
included in C++0x. The working draft is constantly changing, and any feature that is enabled by this flag may be removed from
future versions of GCC if it is not part of the C++0x standard.
*gnu++0x
GNU dialect of -std=c++0x. This option enables experimental features that may be removed in future versions of GCC.

----
show your compile command
:----
% g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testExercise1.d" -MT"src/testExercise1.d" -o "src/testExercise1.o" "../src/testExercise1.cpp"

----Here the full log in Eclipse:----
>make all
>Building file: ../src/testExercise1.cpp
>Invoking: Cross G++ Compiler
>g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testExercise1.d" -MT"src/testExercise1.d" -o >"src/testExercise1.o" "../src/testExercise1.cpp"
>In file included from /usr/include/c++/4.6/chrono:35:0,
> from ../src/testExercise1.cpp:10:
>/usr/include/c++/4.6/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library >support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be >enabled with the -std=c++0x or -std=gnu++0x compiler options.
>../src/testExercise1.cpp: En la función ‘int main()’:
>../src/testExercise1.cpp:15:23: error: ‘chrono’ no es un nombre-de-espacio-de-nombres
>../src/testExercise1.cpp:15:29: error: expected namespace-name before ‘;’ token
>make: *** [src/testExercise1.o] Error 1
Last edited on
Clearly, Eclipse is still using the old system compiler.
> Symbol 'chrono' could not be resolved
I don't see that in your log, just the old error «‘chrono’ is not a namespace-name»

you are compiling in c++98 mode and not using your new version
/usr/include/c++/4.6/chrono


make it explicit, /usr/bin/g++-5.4
I have been working on how to set a new gcc version in eclipse.

So it seems that the environmental variable ${COMMAND} has to be modified. The value of this environmental variable is taken from every project from the field "Command":
* Right click on the project -> Properties -> Settings -> Cross GCC Compiler -> field "Command"

So I changed "gcc" by "gcc-5" and I noticed that new includes where pulled in my project:
- /usr/lib/gcc/i686-linux-gnu/5/include
- /usr/lib/gcc/i686-linux-gnu/5/include-fixed

However the snipped is still not compiling. The compiler shows the error in the same line:
Symbol 'chrono' could not be resolved

---- These are the eclipse logs: ----
make all
Building file: ../src/test2.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test2.d" -MT"src/test2.d" -o "src/test2.o" "../src/test2.cpp"
../src/test2.cpp:10:20: error fatal: chrone.h: No existe el archivo o el directorio /*The file or directory does not exist*/
compilación terminada.
make: *** [src/test2.o] Error 1

My project now contains includes from two gcc versions. Here I list the includes:
- /usr/include
- /usr/include/c++/4.6
- /usr/include/c++/4.6/backward
- /usr/include/c++/4.6/i686-linux-gnu
- /usr/lib/gcc/i686-linux-gnu/4.6/include
- /usr/lib/gcc/i686-linux-gnu/4.6/include-fixed
- /usr/local/include
- /usr/lib/gcc/i686-linux-gnu/5/include
- /usr/lib/gcc/i686-linux-gnu/5/include-fixed

I was thinking to add the new includes manually and I did an "ls" into /usr/include/c++/:
> 4.6 4.6.4 4.9 4.9.4 5 5.4.0

In conclusion I have not a lot of experience with eclipse and I think I'm messing the configuration of gcc in Eclipse... Could anybody tell me how can I solve the current mess and do a proper installation?
Thanks.
Hi,

Just wondering why you installed version 5 of gcc, the earlier advice was saying version 5.4 is the minimum required; the latest version is 7.1 Then you can use c++17 and c++14 features, and not be stuck with something that is already several standards behind. One may not want or need to use c++17 features, but remember later compilers may do things better than previous ones. I always have the latest installed, I even built version 7.1 a few months before it was officially released. I do the same with the IDE.

When installing gcc, it is fairly normal to make the latest installed version to be associated with the g++ command. That is, g++ would execute g++ version 7.1 say. It is also possible via the gcc installation configuration settings to append the version number to the g++ command (g++-7.1 say). One would do that if they really wanted to choose which compiler to use. Personally I always use the latest one defaulted to g++.

You might need to explicitly set the full path to the g++ executable in the Eclipse settings. Another thing to do is make a link, so that g++ will run the latest version of the compiler. This is easier than trying to manually set includes. But you shouldn't have to do any of that if g++ runs the latest version.

In Eclipse, one has to set which compiler is being used in 2 places: 1 for the compiler itself; another for the indexer (which allows for errors and warnings to appear in the code as one types - like intellisense in VS)
Here is a link on how to do that:

https://wiki.eclipse.org/CDT/User/FAQ#CDT_does_not_recognize_C.2B.2B11_features

So this is mainly for specifying which c++ standard you wish to use

While you are there, set other warning options like -pedantic-errors -Wextra as well as -Wall. I routinely use these other options as well - warnings are your friend :
http://www.cplusplus.com/forum/general/183731/#msg899203

I also advise to join the eclipse forum - lots of info and help there.

Hope this all works out for you :+)
Thank you for yours answers.

Just wondering why you installed version 5 of gcc

Yes, I shoud install the last available gcc version. This is the repository where the available gcc versions for Ubuntu are:
https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
The latter available version for Ubuntu 12.04 is gcc-6. So I installed this one:
Than I changed the /usr/bin/gcc and /usr/bin/g++ links to point to the new version (before I forgot to update the last one "g++" therefore I had includes from two different versions)

Specifying which c++ standard you wish to use

I checked the information of the link:
https://wiki.eclipse.org/CDT/User/FAQ#CDT_does_not_recognize_C.2B.2B11_features
This link was also useful:
https://stackoverflow.com/questions/17457069/enabling-c11-in-eclipse-juno-kepler-luna-cdt
* For the compiler itself, I did the following:
1) Right click on the project->C/C++ Build->Settings->Cross GCC Compiler-> Dialect
2) In the "Language standard" drop-down menu I selected: ISO C11(-std=c11)
3) Close everything
4) Right click on the project-> C/C++ General->Preprocessor Include Paths, Macros etc. Providers-> CDT GCC Built-in Compiler Settings
5) Uncheck "Use global provider shared between projects"
6) In the Command to get compiler specs:", append "-std=c++11" after ${FLAGS}
7) Move the "CDT GCC Build-in Compiler Settings" entries to the top
8) Apply and OK

* for the indexer, I did the following:
1) Right click on the project-> C/C++ General-> Indexer
2) Check "Index all header variants" and "Index source and header files opened in editor"

* Finally I refreshed the Indexer and build the project:
1) Project->C/C++ Index->Re-resolve Unresolved Includes
2) Project->C/C++ Index-> Rebuild
3) Build the project

--- Result: Eclipse logs ----
make all
Building file: ../src/testFinal1.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testFinal1.d" -MT"src/testFinal1.d" -o "src/testFinal1.o" "../src/testFinal1.cpp"
../src/testFinal1.cpp:10:20: fatal error: chrone.h: No existe el archivo o el directorio
#include <chrone.h>
^
compilation terminated.
make: *** [src/testFinal1.o] Error 1

Observation1: I only have the includes related with the version 6
Observation2: I don't see the -std=c++11 flag on my command, although I set it in my Eclipse Compiler Setting :(.
Any ideas?

Observation1: I only have the includes related with the version 6
"../src/testFinal1.cpp"
../src/testFinal1.cpp:10:20: fatal error: chrone.h: No existe el archivo o el directorio
#include <chrone.h>

Do you realize that this is not a standard C++ header file? This appears to be a header file that you must produce for your program, not a standard C++ header. All standard C++ headers don't have an extension, ie: <chrono>


Observation2: I don't see the -std=c++11 flag on my command, although I set it in my Eclipse Compiler Setting :(.
Any ideas?

Does Eclipse have project settings? Normally, with most IDEs, you need to setup each project separately from the actual compiler setup. And normally the standard to be used is a project setting not a "compiler" setting.

Hi,

This whole thing is a problem in Eclipse, I messed about with this for 2 days when I first acquired Eclipse. Apart from that initial glitch I like like the IDE a lot.

In the Command to get compiler specs:", append "-std=c++11" after ${FLAGS}


On my system (Eclipse Oxygen - it might be different on yours), I put it at the very end, it looks like this:

${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}" -std=c++1z -Wall -Wextra -pedantic-errors -Wswitch -Wswitch-default -Wconversion

Note I am using c++17.

./src/testFinal1.cpp:10:20: fatal error: chrone.h: No existe el archivo o el directorio
#include <chrone.h>
^


Normally it is:

#include <chrono>

Do the header files have different names for different spoken language versions of compilers? I mean, are the names of the other include files in Spanish too? Maybe chrone.h was a typo :+) The c++11 include files don't have a .h extension.

What happens if you compile the example found here? :

http://en.cppreference.com/w/cpp/chrono/duration

You say the latest version of gcc you can use is 6, that link to the repositories showed version gcc7.1 available, is it dependent on which version of ubuntu you have? Maybe you should upgrade that as well?

If you really wanted to, you can build your own version of gcc rather than installing a binary, but this is only worth it if you want the latest, and can't obtain it by any other means. It might seem a bit daunting at first, there is a lot to read on the gcc installation page. Last time I did it, I didn't have to specify much; left most of the default settings. IIRC one does have to specify which languages to install, so one doesn't get all of them (Fortran, Ada etc). It does take a while to do, about an hour or so on my i7 machine with 16GB Ram and using the make option to use multiple processors.
Thanks for your answers. Now it is working :))))!

@jlb
All standard C++ headers don't have an extension, ie: <chrono>

Thanks I learned smth else "<chrone.h>" was a typo.

@TheIdeasMan
I messed about with this for 2 days when I first acquired Eclipse

Lucky you! I mess already for about 7 days :/

Regarding the "-std=c++11 " argument I was setting it in the wrong compiler C/C++ Settings:
* Right click on the project-> Properties-> C/C++ Build-> Settings-> Cross GCC Compiler -> Miscellaneous -> Other flags (Incorrect)
instead of:
* Right click on the project-> Properties-> C/C++ Build-> Settings-> Cross G++ Compiler -> Miscellaneous -> Other flags (Correct)
This make me wonder what is the difference between these compiler C/C++ Settings and also the difference between gcc and g++... I read already smth like "gcc compiles also c code" and g++ "only c++ code". That makes me wonder if for cpp development the installation of gcc is really need it...

the names of the other include files in Spanish too?

If the include files were written in Spanish I wouldn't have language typo problems xD...

Maybe you should upgrade that as well?

Yes I should upgrade my Ubuntu version... This is in my TO DO list after learning cpp ':/.

If you really wanted to, you can build your own version of gcc rather than installing a binary

This is such a really interesting task I will added to my TO DO list too.

There is a lot to read on the gcc installation page

Would you suggest a source specifically?
Hi,

Pleased it is working now :+D

About gcc:

gcc is the gnu compiler collection, so it can compile C , C++, Objective C, Fortran, Go, Ada. So to compile C programs, one uses the gcc command; to compile C++ programs, one uses the g++ command. So that is why there are different settings for each of these in Eclipse or any other IDE. There is no separate g++ installation. One can use g++ to compile C programs too, that is because C is a generally subset of C++, nearly all of the C constructs also work in C++. I read somewhere that it is recommended to use a C++ compiler to compile C programs. IIRC the reason was the C++ compiler will find those C constructs that don't work in C++, so this allows one to rewrite them and have better code in the end.

Would you suggest a source specifically?

https://gcc.gnu.org/
https://gcc.gnu.org/install/

About upgrading things:

As I mentioned earlier, I like to have everything up to date: the OS, compilers, software including IDE's. I get a new version of the OS as soon as it comes out (every 6 months for Fedora); my software gets system updates every day automatically and this includes new kernels which arrive about every 2 weeks.

I found that in the past, things would get out of hand if one leaves updating too long. I had Fedora 17 and didn't upgrade until Fedora 24, and I didn't do daily updates, so everything was really old including the kernel. The problem is that version of things like the compiler binaries are only available until a certain version (sounds like gcc6.4 in your case) for particular versions of the OS, so to get anything later one has it build it. This applies to all the other software as well.

Yes I should upgrade my Ubuntu version... This is in my TO DO list after learning cpp ':/.


"Learning C++" could be a life long thing - always new things to learn :+) Whereas upgrading the OS is a much shorter time frame - every 6 months say, and it should take only 1 hour or less to do it.


About updating Eclipse:

On this page it talks about what to do with any plugins you had in your previous version, the new version needs to have the directories which hold them copied from the previous version or the plugin re-installed. This includes the C/C++ plugins. I had to do this, I have a new version of Fedora (26) and consequently a new version of Eclipse (Oxygen)

http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-2.htm

About C++ standards:

C++11 was a major improvement, there was a large amount added. C++14 was a comparatively minor improvement, but it has some very useful things like the change in the meaning of the auto keyword. So try to learn c++11 and c++14 at the same time. When you get a compiler that can do c++17, maybe try to learn a few things from it too.

About compiler vendors:

The reason I am mentioning this is because it is sometimes instructive to compile code with different compilers. If the code is not too complicated in terms of lots of files and directories, you could use an online compiler like Coliru.

Another main vendor is LLVM which provides the clang compiler. There seems to be an arms race between vendors, I am not sure at the moment which seems to be in front. clang has version 4.0.1 which seems to support most of c++17, but not so many of the other Technical Specifications.

Regards :+)
Last edited on
Thank you for such valuable information I am sure I will come back to this topic :).

Whereas upgrading the OS is a much shorter time frame - every 6 months say, and it should take only 1 hour or less to do it


Well I would like to try something for the first time to update my OS. I will try to find time in between but 1st priority is C++ for me.But you are right not as long as learning C++, however I think it will take more than an hour:

1.- I want to try the last LTS Ubunutu OS with a Live CD to see if everything works fine in my Laptop
2.- I want to clone the current Ubuntu partition. So in case of problem with the drivers of the new partition with my computer I can restore it back...
I will use Gparted for cloning it
3.- I also want to tar my current "/home" directory and put it on a new partition
4.- Store in a text file my current repositories and installed software. So then I can create an script to add the repositories and install the software.
5.- I will format the disk and create 4 primary partitions:
* One for Windows (40GB)
* One for Ubuntu (60GB)
* One for the old Ubuntu "/home" partition (75 GB)
* Partition for DATA - my documents (The rest of the hard drive)
6.- From the Ubuntu primary partition I will create a logical partition for the swap. My Laptop has about 4 GB RAM. So I will book 4 GB for the swap

I also would like to try other Linux distros when I have time...
@TheIdeasMan You said you use Fedora, How is it? Would you recommend it?

Regards
Hi,

With regard to upgrading the OS, it is a good idea to back up your existing data, just in case things go wrong somewhere. However, on my system at least, it is possible to upgrade to a new version in-situ. That is, the upgrade takes care of all your existing software and set up. I have just done an upgrade to Fedora26, it took 30 minutes, but I have a fast internet connection which sometimes can go at 12MB/s.

It sounds like you want to reorganise things quite a bit, so your strategy sounds good.

With partitions, mine is organised like this:

/boot 2 GB the upgrade system uses this partition, grub2 lives here
/ 50 GB
/home 20 GB
/usr 186 GB software that comes with the system is here
/opt 132 GB other software, like my CAD system
/var 46 GB various log files live here, if it fills up one can still use the rest of the system

The sizes are probably not ideal: there is too much space in root; not enough in /home (already at 75%). I do have a LVM partition (Logical Volume Manager) which all of the partitions except /boot live in, so I should be able to alter partition sizes without destroying anything. I would recommend LVM, so you could do the same in the future. LVM can also span devices, so that is handy if you add another drive later (take out the optical drive and put a SSD or HD there instead) I would also recommend having an external HD drive, for backups or just some where to put stuff.

I also have a separate disk for Windows.


@TheIdeasMan You said you use Fedora, How is it? Would you recommend it?


Well I have had versions 9, 13, 17, 24, 25 and 26, so I guess I have been happy with it. I prefer the KDE Desktop, am not really a fan of Gnome. Before Fedora I had Yggdrasil circa 1991, one of the first Linux distros. I have heard lots of good things about Ubuntu though.

I too would like to try different distros, one has to choose their battles .... I did attempt Ubuntu, but my Laptop is in the invidious position of having dual graphics cards, but not Optimus, so I can't configure the NVIDIA correctly. Ubuntu attempts install graphics driver on installation, so this fails, as does every flavour of Ubuntu.

Regards
Topic archived. No new replies allowed.