2016-03-21 25 views
2

C++ lehçesi C++ 11 sürümüne değiştirmeye çalışıyorum ve bayrağı etkilemiyor gibi görünüyor.g ++ -std = C++ 11, bayrak etkili olmayacak

fatal error: in "RandomSystemTest": c++ v is 199711 
:

test durumu başarısız olur ve
#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); 
} 

aşağıdaki verir:

#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 [email protected] 2> buildLog.txt 

$(CODER_O): $(CODER_C) $(CODER_H) 
    g++ $(FLAGS) $(INCH) -c $< -o [email protected] 2> buildLog.txt 

$(TRAN_O_T): $(TRAN_C_T) $(TRAN_H) 
    g++ $(FLAGS) $(INCH) -c $< -o [email protected] 2> buildLog.txt 

$(TRAN_O): $(TRAN_C) $(TRAN_H) 
    g++ $(FLAGS) $(INCH) -c $< -o [email protected] 2> buildLog.txt 

$(SIGV_O_T): $(SIGV_C_T) $(SIGV_H) 
    g++ $(FLAGS) $(INCH) -c $< -o [email protected] 2> buildLog.txt 

$(SIGV_O): $(SIGV_C) $(SIGV_H) 
    g++ $(FLAGS) $(INCH) -c $< -o [email protected] 2> buildLog.txt 

aşağıdaki birim testi ile lehçesini kontrol ediyorum: Burada

benim makefile gelen snippet'idir

sürümü hala 199711'i gösterir.

bir fark yapmamış birden bayrakları denedi: g

c11 
c++11 
c++0x 
gnu++11 

Sürüm ++ = 4.8.4 Ubuntu sürümü 14.04.4 LTS

Düzenleme: As çıktısını talep

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 

Ve şimdi çalışıyor! Neden olduğuna dair hiçbir fikrim yok. Yaptığım tek fark g ++ -std = C++ 11 -dM -E-xC++/dev/null | grep __cplusplus @Dietrich tarafından önerildiği gibi

+0

Herhangi bir yerde '$ (A_OBJECT)' veya '$ (A_CFILE)' için bir tanım göremiyorum. Sadece '% .o:% .cpp' veya benzer bir şey kullanmamanın bir nedeni var mı? –

+0

Basitleştirmek için tanımları dışarıda bıraktım, aksi halde projede her dosya tanımlanmış ve her g ++ çağrısı için sıraya eklendim. Şu an itibariyle% .o: ve% .cpp'nin bunları nasıl kullanabileceğini anlayamıyorum. –

+0

Belki de bize derleme ve bağlantı listelerini gösterebilirsiniz. –

cevap

0

Makefile'ınıza bakmadan bağlantı sıranız yanlış görünüyor. Kaynak kod dosyanızdan sonra -std = C++ 11 koyun. Öğrendiğim en iyi uygulama, her zaman g ++ kaynağından sonra, .cpp dosyalarınızı ilk defa koymaktı.

+3

Bunun bir etkisi olmamalı. Bildiğim kadarıyla sadece linker bayrakları siparişten etkilenir. –