# CMake tutorial step4 code has no effect when setting cxx\_std\_98

**URL:** <https://discourse.cmake.org/t/cmake-tutorial-step4-code-has-no-effect-when-setting-cxx-std-98/13773>\
**Category:** Usage\
**Tags:** os:linux\
**Created:** [March 18, 2025, 4:22am UTC](https://discourse.cmake.org/t/cmake-tutorial-step4-code-has-no-effect-when-setting-cxx-std-98/13773 "2025-03-18T04:22:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kruno\_Peric](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kruno_peric/32/5415_2.png) [@Kruno\_Peric](https://discourse.cmake.org/u/Kruno_Peric)\
**Post date:** [March 18, 2025, 4:22am UTC](https://discourse.cmake.org/t/cmake-tutorial-step4-code-has-no-effect-when-setting-cxx-std-98/13773/1 "2025-03-18T04:22:53Z")

</div>

When i use CMake on my ubuntu machine (it is cmake version 3.28.3) and i download the Step4 tutorial code for the tutorial on the CMake website, changing **cxx\_std\_11** to **cxx\_std\_98** has no effect, but it should throw a compile error. To reduce this problem down to the bare minimum, I made my own tiny project. It has the following source code ( **test.cpp** ):

> #include \<iostream\>
> 
> int main()  
> {  
> std::cout \<\< std::stod(“300”) \<\< std::endl;
> 
> ```
> return 0;
> 
> ```
> 
> }

and the following CMakeLists.txt in the same directory:

> cmake\_minimum\_required(VERSION 3.10)
> 
> # specify the C++ standard  
> add\_library(test\_compiler\_flags INTERFACE)  
> target\_compile\_features(test\_compiler\_flags INTERFACE cxx\_std\_98)
> 
> # add the executable  
> add\_executable(test test.cpp)
> 
> target\_link\_libraries(test PUBLIC test\_compiler\_flags)

This does not generate a compile error but it should because im using std::stod().

Here is the version of c++ compiler im using and a demonstration that it throws an error if i manually compile it with -std=c++98:

> kruno@ubuntupad:~/repos/cmake\_tutorial/test$ c++ --version  
> c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0  
> Copyright (C) 2023 Free Software Foundation, Inc.  
> This is free software; see the source for copying conditions. There is NO  
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> kruno@ubuntupad:~/repos/cmake\_tutorial/test$ c++ test.cpp  
> kruno@ubuntupad:~/repos/cmake\_tutorial/test$ ./a.out  
> 300  
> kruno@ubuntupad:~/repos/cmake\_tutorial/test$ c++ test.cpp -std=c++98  
> test.cpp: In function ‘int main()’:  
> test.cpp:6:23: error: ‘stod’ is not a member of ‘std’  
> 6 | std::cout \<\< std::stod(“300”) \<\< std::endl;  
> | ^~~~  
> test.cpp:6:23: note: ‘std::stod’ is only available from C++11 onwards

Also, when I export the cmake verbose commands to JSON, I do not see -std=c++98 anywhere in the compilation step. It’s like the compile features library is being ignored.

> [  
> {  
> “directory”: “/home/kruno/repos/cmake\_tutorial/test”,  
> “command”: “/usr/bin/c++ -o CMakeFiles/test.dir/test.cpp.o -c /home/kruno/repos/cmake\_tutorial/test/test.cpp”,  
> “file”: “/home/kruno/repos/cmake\_tutorial/test/test.cpp”,  
> “output”: “CMakeFiles/test.dir/test.cpp.o”  
> }  
> ]

---

<div class="post-metadata">

**Author:** ![Kruno\_Peric](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kruno_peric/32/5415_2.png) [@Kruno\_Peric](https://discourse.cmake.org/u/Kruno_Peric)\
**Post date:** [March 18, 2025, 5:04am UTC](https://discourse.cmake.org/t/cmake-tutorial-step4-code-has-no-effect-when-setting-cxx-std-98/13773/2 "2025-03-18T05:04:01Z")

</div>

Ok, i just read into the documentation a bit more and cxx\_std\_98 doest mean it will add the -std=c++98 flag, it simply means that it will require that the compiler AT LEAST support that standard. Here is some more info from the docs:

 ![Screenshot_20250318_000141_Chrome](https://discourse.cmake.org/uploads/default/original/2X/f/f85f4ca82e1fce67f30308fd2bfdc577598c6765.jpeg)

So im curious then, what would be the way in modern cmake to specifically specify u want the flag -std=c++98? I guess if cmake has a way to specify compiler flags u could use that method. Probabaly as i work through the tutorial, this question will be answered.

---

<div class="post-metadata">

**Author:** ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)\
**Post date:** [March 18, 2025, 8:02am UTC](https://discourse.cmake.org/t/cmake-tutorial-step4-code-has-no-effect-when-setting-cxx-std-98/13773/3 "2025-03-18T08:02:58Z")

</div>

does it help? [Determining the compiler default C++ standard - #13 by adaldev](https://discourse.cmake.org/t/determining-the-compiler-default-c-standard/10389/13)

---

<div class="post-metadata">

**Author:** ![Kruno\_Peric](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kruno_peric/32/5415_2.png) [@Kruno\_Peric](https://discourse.cmake.org/u/Kruno_Peric)\
**Post date:** [March 18, 2025, 2:16pm UTC](https://discourse.cmake.org/t/cmake-tutorial-step4-code-has-no-effect-when-setting-cxx-std-98/13773/4 "2025-03-18T14:16:15Z")

</div>

Yes thanks!

---

<div class="post-metadata">

**Author:** ![Kruno\_Peric](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kruno_peric/32/5415_2.png) [@Kruno\_Peric](https://discourse.cmake.org/u/Kruno_Peric)\
**Post date:** [March 20, 2025, 12:57am UTC](https://discourse.cmake.org/t/cmake-tutorial-step4-code-has-no-effect-when-setting-cxx-std-98/13773/5 "2025-03-20T00:57:04Z")

</div>

I have a followup question to this reply: Can you also just manually specify that you want to use the compiler argument “-std=c++98”? Or would that be a very non-CMake thing to do because you take away the abstraction of being compiler agnostic?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [February 19, 2026, 9:44pm UTC](https://discourse.cmake.org/t/cmake-tutorial-step4-code-has-no-effect-when-setting-cxx-std-98/13773/6 "2026-02-19T21:44:27Z")

</div>

Correct; you’re going behind CMake’s back here and may get unexpected behaviors.
