我正在尝试将c ++方言的版本更改为c ++ 11,并且该标志似乎没有生效。
以下是我的makefile片段:
#Path Definitions
PATHT = test/
PATHI = inc/
PATHB = build/
PATHS = src/
#Files of interest
CODER_C = $(PATHS)E8b9b.cpp
CODER_O = $(PATHB)E8b9b.o
CODER_H = $(PATHI)E8b9b.hpp
CODER_C_T = $(PATHT)Test_E8b9b_encoder.cpp
CODER_O_T = $(PATHB)Test_E8b9b_encoder.o
TRAN_C = $(PATHS)TransactionID.cpp
TRAN_O = $(PATHB)TransactionID.o
TRAN_H = $(PATHI)TransactionID.hpp
TRAN_C_T = $(PATHT)Test_TransactionID.cpp
TRAN_O_T = $(PATHB)Test_TransactionID.o
SIGV_C = $(PATHS)SigView.cpp
SIGV_O = $(PATHB)SigView.o
SIGV_H = $(PATHI)SigView.hpp
SIGV_C_T = $(PATHT)Test_SigView.cpp
SIGV_O_T = $(PATHB)Test_SigView.o
TESOUT = $(PATHB)Test.out
RUNOUT = $(PATHB)Run.out
#Libraries of interest
BOOSTL = -lboost_unit_test_framework
INCH = -Iinc
#Tool Definitions
CC=g++
FLAGS = -std=c++11 -Wall
test: $(CODER_O_T) $(CODER_O) $(TRAN_O_T) $(TRAN_O) $(SIGV_O_T) $(SIGV_O)
g++ $(FLAGS) $(CODER_O_T) $(CODER_O) $(TRAN_O_T) $(TRAN_O) $(SIGV_O_T) $(SIGV_O) $(BOOSTL) \
-o $(TESOUT) 2> buildLog.txt
./$(TESOUT) 1> buildLog.txt
$(CODER_O_T): $(CODER_C_T) $(CODER_H)
g++ $(FLAGS) $(INCH) -c $< -o $@ 2> buildLog.txt
$(CODER_O): $(CODER_C) $(CODER_H)
g++ $(FLAGS) $(INCH) -c $< -o $@ 2> buildLog.txt
$(TRAN_O_T): $(TRAN_C_T) $(TRAN_H)
g++ $(FLAGS) $(INCH) -c $< -o $@ 2> buildLog.txt
$(TRAN_O): $(TRAN_C) $(TRAN_H)
g++ $(FLAGS) $(INCH) -c $< -o $@ 2> buildLog.txt
$(SIGV_O_T): $(SIGV_C_T) $(SIGV_H)
g++ $(FLAGS) $(INCH) -c $< -o $@ 2> buildLog.txt
$(SIGV_O): $(SIGV_C) $(SIGV_H)
g++ $(FLAGS) $(INCH) -c $< -o $@ 2> buildLog.txt
我正在用以下单元测试检查方言:
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "SigView.hpp"
#include <fstream>
#include <string>
#include <stdio.h> // For the __cplusplus define
/*
These are the C++ standards and what value you should be able to expect in __cplusplus:
C++ pre-C++98: __cplusplus is 1.
C++98: __cplusplus is 199711L.
C++98 + TR1: This reads as C++98 and there is no way to check that I know of.
C++11: __cplusplus is 201103L.
C++14: __cplusplus is 201402L.
*/
BOOST_AUTO_TEST_CASE(RandomSystemTest)
{
BOOST_TEST_REQUIRE(__cplusplus == 201103L, "c++ dialect is " << __cplusplus);
}
测试用例失败并输出以下内容:
fatal error: in "RandomSystemTest": c++ v is 199711
该版本仍然陈述199711。
我尝试了多个没有区别的标志:
c11
c++11
c++0x
gnu++11
g ++版本= 4.8.4 Ubuntu版本14.04.4 LTS
编辑:
根据要求输出make:
$ make test
g++ --std=c++11 -Wall -Iinc -c test/Test_SigView.cpp -o build/Test_SigView.o 2> buildLog.txt
g++ --std=c++11 -Wall build/Test_E8b9b_encoder.o build/E8b9b.o build/Test_TransactionID.o build/TransactionID.o build/Test_SigView.o build/SigView.o -lboost_unit_test_framework \
-o build/Test.out 2> buildLog.txt
./build/Test.out
Running 11 test cases...
*** No errors detected
现在它有效!我不知道为什么。我唯一的区别是执行g ++ -std = c ++ 11 -dM -E -xc ++ / dev / null | @Dietrich Epp建议的grep __cplusplus
答案 0 :(得分:0)
从查看您的Makefile看起来您的链接顺序是错误的。将-std = c ++ 11放在源代码文件之后。我学到的一个最佳实践是始终将源.cpp文件放在g ++之后。