我在OS X上,当我尝试在终端
中执行此命令时出现编译错误g ++ -Wall -o test_E test_E.cpp dynamic_array.cpp oracle.o
我的其他c ++文件,例如test_A.cpp
和test_B.cpp
在同一命令上运行正常,但没有最后一部分,例如。
g ++ -Wall -o test_A test_A.cpp dynamic_array.cpp
我也尝试在没有oracle.o
的情况下运行该命令并且它提供了相同的错误,但没有不受支持的文件格式
我该如何解决这个问题?
ld: warning: ignoring file oracle.o, file was built for unsupported file
format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 ) which is not the architecture being linked (x86_64): oracle.o
Undefined symbols for architecture x86_64:
"oracle::insert(int, int)", referenced from:
generate_oracle(oracle&, int, int, int) in test_E-2b7bb8.o
run_tests(dynamic_array&, oracle&) in test_E-2b7bb8.o
"oracle::operator[](unsigned int)", referenced from:
print_state(dynamic_array&, oracle&) in test_E-2b7bb8.o
compare_content(dynamic_array&, oracle&) in test_E-2b7bb8.o
"oracle::get_allocated_size() const", referenced from:
print_state(dynamic_array&, oracle&) in test_E-2b7bb8.o
compare_content(dynamic_array&, oracle&) in test_E-2b7bb8.o
"oracle::get_size() const", referenced from:
print_state(dynamic_array&, oracle&) in test_E-2b7bb8.o
compare_exceptions(dynamic_array&, oracle&) in test_E-2b7bb8.o
compare_content(dynamic_array&, oracle&) in test_E-2b7bb8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是test_E.cpp
#include <iostream>
#include "dynamic_array.h"
#include "oracle.h"
using namespace std;
void generate_cut(dynamic_array &cut, int start, int delta, int count) {
for (int i = 0; i < count; i++) {
cut.insert(start, i);
start += delta;
}
}
void generate_oracle(oracle &orc, int start, int delta, int count) {
for (int i = 0; i < count; i++) {
orc.insert(start, i);
start += delta;
}
}
void print_state(dynamic_array &cut, oracle &orc) {
cout << "***** cut" << endl;
cout << "size: " << cut.get_size() << endl;
cout << "allocated size: " << cut.get_allocated_size() << endl;
for (int i = 0; i < cut.get_size(); i++) {
cout << cut[i] << " ";
if (i > 50) { // avoid lengthy output
cout << " ...";
break;
}
}
cout << endl;
cout << "***** oracle" << endl;
cout << "size: " << orc.get_size() << endl;
cout << "allocated size: " << orc.get_allocated_size() << endl;
for (int i = 0; i < orc.get_size(); i++) {
cout << orc[i] << " ";
if (i > 50) { // avoid lengthy output
cout << " ...";
break;
}
}
cout << endl;
}
int const_f(const dynamic_array &cut, int i) {
return cut[i];
}
int compare_exceptions(dynamic_array &cut, oracle &orc) {
{
// ********** operator[]
int indexes[] = {orc.get_size(), orc.get_size()+1000};
int N = sizeof(indexes)/sizeof(int);
for (int i = 0; i < N; i++) {
int caught = 0;
try {
cut[indexes[i]];
} catch (dynamic_array::exception) {
caught = 1;
}
if (!caught) {
cout << "operator[]: uncaught index range exception at: ";
cout << indexes[i] << endl;
return 0;
}
}
}
{
// ********** operator[] const
int indexes[] = {orc.get_size(), orc.get_size()+1000};
int N = sizeof(indexes)/sizeof(int);
for (int i = 0; i < N; i++) {
int caught = 0;
try {
cut[indexes[i]];
} catch (dynamic_array::exception) {
caught = 1;
}
if (!caught) {
cout << "operator[] const: uncaught index range exception at: ";
cout << indexes[i] << endl;
return 0;
}
}
}
{
// ********** insert(int,int)
int indexes[] = {-1000, -1, orc.get_size()+1, orc.get_size()+1000};
int N = sizeof(indexes)/sizeof(int);
for (int i = 0; i < N; i++) {
int caught = 0;
try {
cut.insert(0, indexes[i]);
} catch (dynamic_array::exception) {
caught = 1;
}
if (!caught) {
cout << "insert(int,int): uncaught index range exception at: ";
cout << indexes[i] << endl;
return 0;
}
}
}
{
// ********** insert(dynamic_array&,int)
int indexes[] = {-1000, -1, orc.get_size()+1, orc.get_size()+1000};
int N = sizeof(indexes)/sizeof(int);
dynamic_array a;
for (int i = 0; i < N; i++) {
int caught = 0;
try {
cut.insert(a, indexes[i]);
} catch (dynamic_array::exception) {
caught = 1;
}
if (!caught) {
cout << "insert(dynamic_array&,int): uncaught index range exception at: ";
cout << indexes[i] << endl;
return 0;
}
}
}
{
// ********** remove(int)
int indexes[] = {-1000, -1, orc.get_size(), orc.get_size()+1000};
int N = sizeof(indexes)/sizeof(int);
for (int i = 0; i < N; i++) {
int caught = 0;
try {
cut.remove(indexes[i]);
} catch (dynamic_array::exception) {
caught = 1;
}
if (!caught) {
cout << "remove(int): uncaught index range exception at: ";
cout << indexes[i] << endl;
return 0;
}
}
}
{
// ********** remove(int,int)
// start out of range
int start_indexes[] = {-1000, -1, orc.get_size()+1, orc.get_size()+1000};
int N = sizeof(start_indexes)/sizeof(int);
for (int i = 0; i < N; i++) {
int caught = 0;
try {
cut.remove(start_indexes[i], orc.get_size());
} catch (dynamic_array::exception) {
caught = 1;
}
if (!caught) {
cout << "remove(int,int): uncaught index range exception at: ";
cout << start_indexes[i] << "," << orc.get_size() << endl;
return 0;
}
}
// end out of range
int end_indexes[] = {orc.get_size()+1, orc.get_size()+1000};
N = sizeof(end_indexes)/sizeof(int);
for (int i = 0; i < N; i++) {
int caught = 0;
try {
cut.remove(0, end_indexes[i]);
} catch (dynamic_array::exception) {
caught = 1;
}
if (!caught) {
cout << "remove(int,int): uncaught index range exception at: ";
cout << end_indexes[i] << "," << orc.get_size() << endl;
return 0;
}
}
// special case: 0 <= end < start < size
int caught = 0;
try {
cut.remove(1, 0);
} catch (dynamic_array::exception) {
caught = 1;
}
if (!caught) {
cout << "remove(int,int): uncaught index range exception at: 1,0" << endl;
return 0;
}
}
return 1; // no failures detected
}
int compare_content(dynamic_array &cut, oracle &orc) {
// check size
if (cut.get_size() != orc.get_size()) {
cout << "ERROR. ";
cout << "size. cut: " << cut.get_size();
cout << " orc:" << orc.get_size() << endl;
print_state(cut, orc);
return 0;
}
// check get_allocated_size
if (cut.get_allocated_size() != orc.get_allocated_size()) {
cout << "ERROR. ";
cout << "allocated_size. cut:" << cut.get_allocated_size();
cout << " orc:" << orc.get_allocated_size() << endl;
print_state(cut, orc);
return 0;
}
// check operator[] and operator[] const
for (int i = 0; i < orc.get_size(); i++) {
if (cut[i] != orc[i]) {
cout << "ERROR. ";
cout << "cut[" << i << "]:" << cut[i];
cout << " orc[" << i << "]:" << orc[i] << endl;
print_state(cut, orc);
return 0;
}
int x = const_f(cut, i);
if (x != orc[i]) {
cout << "ERROR. ";
cout << "cut[" << i << "]:" << cut[i];
cout << " orc[" << i << "]:" << x << endl;
print_state(cut, orc);
return 0;
}
}
return 1;
}
void run_tests(dynamic_array &cut, oracle &orc) {
compare_content(cut, orc);
compare_exceptions(cut, orc);
cut.insert(1, 0);
orc.insert(1, 0);
compare_content(cut, orc);
compare_exceptions(cut, orc);
}
int main() {
dynamic_array cut;
generate_cut(cut, 0, 2, 5);
oracle orc;
generate_oracle(orc, 0, 2, 5);
run_tests(cut, orc);
}
答案 0 :(得分:2)
在这种情况下,您的问题是您正在尝试链接Linux ELF二进制文件,如输出的标头的十六进制转储(0x45 0x4C 0x46
= ELF
)所证明。
基于您可用资源的可能解决方案: