Вопрос

I'm using an unordered set for the first time for my Data Structures Class. When I try to run this code on our schools server, it tells me its the wrong architecture. Here is my main code(RAJ.cpp):

#include<iostream>
#include<tr1/unordered_set>
#include "nflData.h"

using namespace std;
using std::tr1::unordered_set;
struct ihash: std::unary_function<NFLData, std::size_t> {
    std::size_t operator()(const NFLData& x) const
    {
        return x.getDown();//Currently just trying to return a value, will not be actual has function.
    }
};

int main(){
        string a = "20070906_NO@IND,1,46,42,IND,NO,2,6,27,(1:42) P.Manning pass deep left to M.Harrison for 27 yards TOUCHDOWN.,0,0,2007";
        string b = "20070906_NO@IND,1,46,42,IND,NO,3,6,27,(1:42) P.Manning pass deep left to [88'] for 27 yards TOUCHDOWN.,0,0,2007";
        string c = "20070906_NO@IND,1,46,42,IND,NO,,,27,A.Vinatieri extra point is GOOD Center-J.Snow Holder-H.Smith.,0,0,2007";

        unordered_set<NFLData, ihash> myset;
        cout << "\ninsert data a";
        myset.insert(NFLData(a));
        cout << "\ninsert data b";
        myset.insert(NFLData(b));
}

And here is the main error I receive when trying to run after successfully compiling with g++:

./test:  Exec format error. Wrong Architecture.

It should be noted, this same code works fine when templated for an integer type

Это было полезно?

Решение

You need to compile the program for the type of machine you're going to run it on. The type of machine you compiled this for does not match your school's computer.

If the school has a compiler installed on its server, use it to compile your program.

You can see what type of executable you have with the file command under UNIX, Linux and MacOS X. For example:

$ file /bin/ls    # on my Linux box
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

$ file /bin/ls    # on my MacBook Pro
/bin/ls: Mach-O usiversal binary with 2 architectures
/bin/ls (for architecture x86_64):      Mach-O 64-bit executable x86_64
/bin/ls (for architecture i386):        Mach-O executable i386

Usually, different operating systems are able to at least minimally identify executables for foreign systems, but not always. That is, it'll identify that it's foreign, but might not be able to identify which foreign system.

If you are compiling the code on your school's server, then something else strange is afoot. The file command above should help rule out certain things. BTW, you might list out what compiler flags you're using, and the output of file for the version that works and the version that does not.

One other thing to check: Make sure your final compile step does not include the -c flag to g++. That flag tells G++ that you're building an intermediate object, not the final object.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top