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

  • #1
joshmccraney
Gold Member
2,253
143
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.
 

Answers and Replies

  • #2
36,881
8,933
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?
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.
 
  • Like
Likes Vanadium 50
  • #3
Vanadium 50
Staff Emeritus
Science Advisor
Education Advisor
29,948
15,643
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?
 
  • #4
joshmccraney
Gold Member
2,253
143
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.
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.
 
  • #5
36,881
8,933
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.
 
  • Like
Likes joshmccraney
  • #6
pbuk
Science Advisor
Homework Helper
Gold Member
4,084
2,411
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.
 
  • Like
Likes joshmccraney, Mark44 and Vanadium 50
  • #7
joshmccraney
Gold Member
2,253
143
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
 
  • #8
36,881
8,933
A black arrow against a nearly identical black background isn't the easiest thing to read...
 
  • Like
Likes Vanadium 50
  • #9
joshmccraney
Gold Member
2,253
143
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.
 
  • #10
36,881
8,933
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.
 
  • #11
joshmccraney
Gold Member
2,253
143
  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?
 
  • #12
36,881
8,933
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.
 
  • #13
joshmccraney
Gold Member
2,253
143
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
 

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

  • Last Post
Replies
8
Views
385
  • Last Post
Replies
1
Views
154
Replies
4
Views
461
  • Last Post
Replies
16
Views
827
  • Last Post
Replies
1
Views
395
Replies
8
Views
2K
  • Last Post
4
Replies
118
Views
5K
  • Last Post
Replies
19
Views
640
Replies
20
Views
2K
Top