Ubuntu 16.04.3 LTS执行make命令遇C++11标准支持错误求助
Hey there! That error you're hitting means your code uses features from the C11 standard, but your compiler isn't being told to enable support for it. Don't stress—Ubuntu 16.04.3's default GCC (version 5.4.0) fully supports C11, we just need to tweak your Makefile to flip that support on.
Step 1: Understand the Root Cause
By default, the GCC version bundled with Xenial compiles C++ code using the older C98 standard. Since your code relies on C11-specific syntax or libraries, the compiler throws that error when it encounters stuff it doesn't recognize under the old standard.
Step 2: Modify Your Makefile
You need to add the -std=c++11 (or -std=c++14 if you need newer features) flag to your compile options. Here's how to adjust it based on your Makefile's structure:
Case 1: Your Makefile uses CXXFLAGS
If you already have a CXXFLAGS line, update it to include the standard flag:
CXXFLAGS += -std=c++11 -Wall # -Wall is optional but helps catch useful warnings
Case 2: No dedicated C++ flags in your Makefile
If your compile commands directly use gcc or g++, modify them to include the flag. Also, make sure you're using g++ (the C++ compiler) instead of gcc (for C code) for your C++ files. For example:
Before:
myapp: main.o helper.o gcc -o myapp main.o helper.o main.o: main.cpp gcc -c main.cpp
After:
CXX = g++ CXXFLAGS = -std=c++11 -Wall myapp: main.o helper.o $(CXX) $(CXXFLAGS) -o myapp main.o helper.o main.o: main.cpp $(CXX) $(CXXFLAGS) -c main.cpp
Step 3: Double-Check Your Compiler Version
Just to confirm your setup supports C++11, run this in your terminal:
g++ --version
You should see output like g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609—this version has full C++11 support, so we're good to go.
Step 4: Re-run make
After updating your Makefile, run make again. The error should vanish as long as your code doesn't have other unrelated issues.
内容的提问来源于stack exchange,提问作者Rodrigo Trindade




