2016-11-29 64 views
2

之前,我得到一個堆棧跟蹤前主:C++內存設計缺陷主要GTEST

#include <gtest/gtest.h> 

using namespace std; 

int main(int argc, char **argv) { 
    ::testing::InitGoogleTest(&argc, argv); 
    return RUN_ALL_TESTS(); 
} 

堆棧跟蹤:

計劃接收信號SIGSEGV,分割過錯。 0x0000000000000000在?? ()

#0 0x0000000000000000 in ??() 
#1 0x00000000004e0b51 in std::locale::_S_initialize()() 
#2 0x00000000004e0b93 in std::locale::locale()() 
#3 0x000000000050d524 in std::ios_base::Init::Init()() 
#4 0x0000000000401581 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at /usr/include/c++/4.9/iostream:74 
#5 0x00000000004015b3 in _GLOBAL__sub_I_testsmain.cpp(void)() at ../../../bdf_cpp_tests/testsmain.cpp:18 
#6 0x000000000053cdd7 in __libc_csu_init() 
#7 0x000000000053c3de in generic_start_main() 
#8 0x000000000053c62a in __libc_start_main() 
#9 0x00000000004013f9 in _start() 

這是QMAKE 5.7和g ++ 4.9.4

我相信這是運行命令:我遇到這個問題上 :

g++ -c -m64 -pipe -std=gnu++11 -std=c++11 -Werror -pedantic -DTEST_RESOURCE_DIR=\"/home/eric/Documents/BDFCppLib/test_resources\" -DTEST_OUTPUT_DIR=\"/home/eric/Documents/BDFCppLib/test_resources/output\" -g -std=gnu++11 -Wall -W -fPIC -DDEBUG -I../../../bdf_cpp_tests -I/home/eric/Documents/BDFCppLib/shadow-ant/ubuntu64_gcc49_dev/bdf_cpp_tests -I../../../bdf_cpp_sdk/include -I../../../lib/ubuntu64_gcc49_dev/unpack/chunk_cpp/include -I../../../lib/ubuntu64_gcc49_dev/unpack/system/include -I/home/eric/Software/qt/5.7/gcc_64/mkspecs/linux-g++-64 -o testsmain.o ../../../bdf_cpp_tests/testsmain.cpp 

g++ -o ../../../build/ubuntu64_gcc49_dev/bin/bdf_cpp_run_tests testsmain.o testutils.o -pthread -lrt -L/home/eric/Documents/BDFCppLib/build/ubuntu64_gcc49_dev/lib -static -lbdf -L/home/eric/Documents/BDFCppLib/lib/ubuntu64_gcc49_dev/unpack/chunk_cpp/lib -static -lchunk -L/home/eric/Documents/BDFCppLib/lib/ubuntu64_gcc49_dev/unpack/system/lib -lgtest 

UPDATE 0 Ubuntu 16.04。我用14.04創建了一個虛擬機,將代碼複製過來,一切正常。沒有段錯誤。因此,16.04的某些事情似乎與此有關。

UPDATE 1: 我開始認爲這是由googletest引起的。我不知道爲什麼它會與14.04而不是16.06一起工作。任何包含並使用Google測試的內容都將無法運行,因爲會立即發生段錯誤。

+0

你的qmake文件是什麼樣的? – Samer

+0

「我相信這是運行的命令」它當然不是運行連接你崩潰的gtest程序的命令。 [mcve]需要。 –

+0

剛剛添加了其他行,這有幫助嗎? –

回答

3

爲什麼使用gcc?最好使用g++。上面的代碼使用g++進行編譯時,不會生成錯誤,並且在運行時,將argc的值輸出爲1,將argv輸出爲某個隨機地址,因爲沒有提供命令行參數。

__static_initialization_and_destruction_0由於gcc而發生。 gcc爲需要調用靜態構造函數的每個翻譯單元創建一個__static_initialization_and_destruction_0。然後它將__do_global_ctors_aux放入.ctors部分,然後在每個翻譯單元上調用__static_initialization_and_destruction_0

+0

對不起,這是使用g ++,我錯誤鍵入。我添加了符合我的問題的那一行。 –