Issue with my compiler not using C++11 with CLion on a Mac

  • Context: C/C++ 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Compiler Mac
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
12 replies · 5K views
member 428835
The compiler is not using C++11 or greater on CLion. My CMakeLists.txt reads:
cmake_minimum_required(VERSION 3.24)
project(main)

set(CMAKE_CXX_STANDARD 17)

add_executable(main main.cpp)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

Any idea what's happening? C++11 worked when I first created the project, but now that I closed it the compiler seems to not work. Any help is greatly appreciated. I'd provide more files if I knew what was relevant.
 
Physics news on Phys.org
joshmccraney said:
The compiler is not using C++11 or greater on CLion.
How do you know? Does your program use C++11 features that aren't present in whatever C++ standard that your compiler is actually using?
joshmccraney said:
Any idea what's happening? C++11 worked when I first created the project, but now that I closed it the compiler seems to not work.
What does "C++11 worked" mean? Telling us that something didn't work doesn't give us much to go on. How do you know that C++11 isn't working now? E.g., compiler error/warning messages, runtime errors, program behavior.
 
Reply
  • Like
Likes   Reactions: Vanadium 50
Mark44 said:
E.g., compiler error/warning messages, runtime errors, program behavior.
And this isn't the first time either we've asked about error messages and their ilk,

It's pretty clear you ain't buyin' what were sellin' with respect to error messages and such. How do we convince you?
 
Mark44 said:
How do you know? Does your program use C++11 features that aren't present in whatever C++ standard that your compiler is actually using?
Yes, as an immediate example, the line: std::vector<int> v = {2, 6, 5, 3, 8, 7, 1, 0};
gives the error:
error: non-aggregate type 'std::vector<int>' cannot be initialized with an initializer list
std::vector<int> v = {2, 6, 5, 3, 8, 7, 1, 0};

Also warnings with range-based for loops, etc.
Mark44 said:
What does "C++11 worked" mean? Telling us that something didn't work doesn't give us much to go on. How do you know that C++11 isn't working now? E.g., compiler error/warning messages, runtime errors, program behavior.
This means I wasn't getting these errors until I restarted CLion. It doesn't work now from the errors above and the c++11 warnings, which would not occur if I was actually using c++11 or higher. All I do is press the green arrow to run the code from the CLion interface.
 
What you wrote gives us more to go on, so that's appreciated. However, since I don't use a Mac or CLion, I'm unable to extricate you from your problem. I'm hopeful that someone who is familiar with those computers and tools can weigh in here.
 
Reply
  • Like
Likes   Reactions: member 428835
joshmccraney said:
All I do is press the green arrow to run the code from the CLion interface.
Given that support for makefiles is an experimental feature in CLion you need to do a bit more than that. In particular, unless you are very confident in all three of the following:
  1. using makefiles outside the CLion IDE (e.g. by running gcc from the command line);
  2. working with CLion to adjust settings and tools used in the compile path; and
  3. combining information from system documentation, error messages and other debugging techniques to work out what is going wrong and how to fix it,
I would say that you should either stop using makefiles and let CLion manage the build the way it is designed to or stop using CLion and use an IDE that is designed to work with makefiles.
 
Reply
  • Like
Likes   Reactions: member 428835, Mark44 and Vanadium 50
Okay, I found the issue, which has a simple fix. It's detailed at CLion's website here. Attached is a screenshot for anyone who may struggle with this in the future: just change the run configs (see the arrow) from the .cpp file to the project. Very obvious now that I'm aware. Thanks for the help!
Screenshot 2023-03-09 at 8.20.46 PM.png
 
Mark44 said:
A black arrow against a nearly identical black background isn't the easiest thing to read...
Yea couldn't figure out how to change it so i made i super thick. It stands out very clear to me though. I'd say the bigger issue is why the screenshot quality is so poor.
 
joshmccraney said:
I'd say the bigger issue is why the screenshot quality is so poor.
  1. Your screen shot includes the whole screen. Including just a portion of the screen would have been clearer.
  2. White characters against a black background is not as clear as black characters against a white background.
 
Mark44 said:
  1. Your screen shot includes the whole screen. Including just a portion of the screen would have been clearer.
  2. White characters against a black background is not as clear as black characters against a white background.
I assume you didn't look at the link I posted?
 
joshmccraney said:
I assume you didn't look at the link I posted?
No, I didn't. I don't have any reason to look at documentation for a product I don't use. My focus was on the mostly unreadable screenshot you posted.
 
Mark44 said:
No, I didn't. I don't have any reason to look at documentation for a product I don't use. My focus was on the mostly unreadable screenshot you posted.
Okay, thanks for your interest. My post details how I solved it