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

  • C/C++
  • Thread starter member 428835
  • Start date
  • Tags
    Compiler Mac
In summary: 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 sent.
  • #1
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.
 
Technology news on Phys.org
  • #2
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.
 
  • Like
Likes Vanadium 50
  • #3
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?
 
  • #4
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.
 
  • #5
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 member 428835
  • #6
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.
 
  • Like
Likes member 428835, Mark44 and Vanadium 50
  • #7
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
A black arrow against a nearly identical black background isn't the easiest thing to read...
 
  • Like
Likes Vanadium 50
  • #9
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.
 
  • #10
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.
 
  • #11
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?
 
  • #12
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.
 
  • #13
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
 

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

1. Why is my compiler not using C++11 with CLion on a Mac?

One possible reason for this issue is that the CMakeLists.txt file in your project may not be configured to use the C++11 standard. You can add the following line to your CMakeLists.txt file to enable C++11 support: set(CMAKE_CXX_STANDARD 11).

2. How can I check if my compiler is using C++11 with CLion on a Mac?

You can check the compiler flags being used by CLion by going to Preferences > Build, Execution, Deployment > CMake and checking the "Build options" field. Look for any flags related to C++11 support, such as -std=c++11 or -std=c++0x.

3. I have set the C++11 standard in my CMakeLists.txt file, but my compiler is still not using C++11. What could be the problem?

It is possible that your compiler may not support the C++11 standard. Make sure you are using a compatible compiler, such as Clang or GCC, which have full support for C++11. You can also try updating your compiler to the latest version.

4. Is there a way to force CLion to use C++11 even if my compiler does not support it?

If your compiler does not support C++11, you can try adding the following line to your CMakeLists.txt file to force CLion to use C++11: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11"). However, this may not work with all compilers and could lead to compilation errors.

5. I have followed all the steps to enable C++11 support in CLion, but I am still facing issues. What else can I try?

If you have tried all the above steps and are still facing issues, you can try cleaning and rebuilding your project in CLion. Sometimes, old build artifacts can cause conflicts with the C++11 settings. You can also try restarting CLion or your computer to see if that resolves the issue.

Similar threads

  • Programming and Computer Science
Replies
0
Views
526
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
6
Views
9K
  • Programming and Computer Science
Replies
20
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
2
Replies
39
Views
3K
  • Programming and Computer Science
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
920
Back
Top