程序:在STDC非法指令++
#include <stdio.h>
#include <sstream>
int main()
{
std::stringstream ss;
ss << "hello world " << 1234 << "\n";
std::string str = ss.str();
printf(str.c_str());
return 0;
}
生成文件:
CC=/usr/local/gcc-4.6.2/bin/g++
CFLAGS=-g -c -W -m32 -Wa,-mtune=pentiumiii
LINKFLAGS=-m32 -static-libgcc -static-libstdc++ -Wl,-rpath,./runtime,--dynamic-linker,./runtime/ld-linux.so.2
all:test
test: list_test.o
$(CC) $(LINKFLAGS) list_test.o -o test
list_test.o: list_test.cpp
$(CC) $(CFLAGS) list_test.cpp
clean:
rm *.o ./test -f
我建立它在64位Linux。當它運行在帶有pentinum(R)III cpu的32位Linux上時有一條非法指令。
非法指令如下:
(gdb) disas 0x0804f77a 0x0804f77b
Dump of assembler code from 0x804f77a to 0x804f77b:
0x0804f77a <std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::_M_sync(std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::char_type*, std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::__size_type, std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::__size_type)+138>: movq %xmm0,0xc(%esp)
彙編轉儲結束。
如何解決此問題?
我相信'-Wa, ''在'CFLAGS'中沒用,應該是'CFLAGS = -g -Wall -m32 -mtune = pentiumiii' –
/usr/local/gcc-4.6.2/bin/g++ -g -c -W -m32 -mno -sse -mtune = pentiumiii list_test.cpp list_test.cpp:1:0:錯誤:壞值(pentiumiii)-mtune =開關 –