【发布时间】:2013-12-22 06:45:29
【问题描述】:
我有一些源文件(例如 layout.cpp)。我可以在本地 MAC 机器上使用“make”命令。 make 成功后,我将所有文件复制到远程 Linux 机器上。但是,我的 MAC 机器上的可执行文件无法在远程 Linux 机器上执行。错误信息如下。
布局不是二进制可执行文件
我认为失败是由于布局文件格式为“Mach-O 64-bit executable”,无法在 linux 机器上运行。
因此,我尝试在远程 linux 机器上制作源文件。但是,它显示了很多如下错误消息。
layout.cpp:75: 错误:'exit' 未在此范围内声明
layout.cpp:88: 错误:'strcpy' 未在此范围内声明
但是这些错误并没有在 MAC 的 make 过程中显示出来。这些错误是由 MAC 和 Linux 中的编译器不同引起的吗?由于有很多不同的错误,因此我们不能简单地添加 '#include cstdlib' 或 '#include string.h' 来解决这个问题。谢谢。
源代码:
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <string>
#include <deque>
#include <vector>
using namespace std;
// layout routines and constants
#include <layout.h>
#include <parse.h>
#include <graph.h>
// MPI
#ifdef MUSE_MPI
#include <mpi.h>
#endif
int main(int argc, char **argv) {
// initialize MPI
int myid, num_procs;
#ifdef MUSE_MPI
MPI_Init ( &argc, &argv );
MPI_Comm_size ( MPI_COMM_WORLD, &num_procs );
MPI_Comm_rank ( MPI_COMM_WORLD, &myid );
#else
myid = 0;
num_procs = 1;
#endif
// parameters that must be broadcast to all processors
int rand_seed;
float edge_cut;
char int_file[MAX_FILE_NAME];
char coord_file[MAX_FILE_NAME];
char real_file[MAX_FILE_NAME];
char parms_file[MAX_FILE_NAME];
int int_out = 0;
int edges_out = 0;
int parms_in = 0;
float real_in = -1.0;
// user interaction is handled by processor 0
if ( myid == 0 )
{
if ( num_procs > MAX_PROCS )
{
cout << "Error: Maximum number of processors is " << MAX_PROCS << "." << endl;
cout << "Adjust compile time parameter." << endl;
#ifdef MUSE_MPI
MPI_Abort ( MPI_COMM_WORLD, 1 );
#else
exit (1);
#endif
}
// get user input
parse command_line ( argc, argv );
rand_seed = command_line.rand_seed;
edge_cut = command_line.edge_cut;
int_out = command_line.int_out;
edges_out = command_line.edges_out;
parms_in = command_line.parms_in;
real_in = command_line.real_in;
strcpy ( coord_file, command_line.coord_file.c_str() );
strcpy ( int_file, command_line.sim_file.c_str() );
strcpy ( real_file, command_line.real_file.c_str() );
strcpy ( parms_file, command_line.parms_file.c_str() );
}
// now we initialize all processors by reading .int file
#ifdef MUSE_MPI
MPI_Bcast ( &int_file, MAX_FILE_NAME, MPI_CHAR, 0, MPI_COMM_WORLD );
#endif
graph neighbors ( myid, num_procs, int_file );
// finally we output file and quit
float tot_energy;
tot_energy = neighbors.get_tot_energy ();
if ( myid == 0 )
{
neighbors.write_coord ( coord_file );
cout << "Total Energy: " << tot_energy << "." << endl
<< "Program terminated successfully." << endl;
}
// MPI finalize
#ifdef MUSE_MPI
MPI_Finalize ();
#endif
}
【问题讨论】:
-
如果你需要帮助,你应该展示一些源代码......
-
如果你的代码太草率以至于你没有声明
exit和strcpy,你需要在移植之前在Mac OS X上编译好代码。 Sanely 至少意味着gcc -Wall;我经常使用gcc -O3 -g -std=c11 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Werror(我在 Mac OS X 10.9.1 和 GCC 4.8.2 上使用这些)。当您的代码使用这些选项在 Mac OS X 上干净地编译时,请考虑移植到其他地方。<cstdlib>是不合适的,除非你真的在 C++ 中工作,但是你根本不应该使用strcpy()! -
请注意,C++ 标准头文件的一个“特性”是它们可以相互包含。在 Mac OS X 上,您可能包含一个标头,而该标头又包含
<cstdlib>和<cstring>,但 Linux 上没有相同的标头 - 因此您必须相应地修复您的代码。如果您使用标题中的函数,请包含该标题;不要依赖其他一些标题来为您包含它。 -
@BasileStarynkevitch 我已经添加了源代码。我发现编译器已在我的设置文件中定义。它是'g++ 03'。我对这个错误感到困惑。谢谢!