无效的精灵头linux

时间:2012-07-04 09:54:10

标签: c++ gcc

我已将开放式solaris OS的c ++代码移植到Redhat 4 OS。在此代码段中,我收到错误:

    AsciiFileName = new char [1024];
    cout<<"HandleFile is getting called "<<endl;
    /// Converting the file name to ascii.
    FileName += strFileName;
    FileName.ConvertToAscii( AsciiFileName );

    /// Get handle to the shared object file.
    Handle = dlopen( AsciiFileName, RTLD_LOCAL | RTLD_LAZY );
    cout<<"Handle = dlopen( AsciiFileName, RTLD_LOCAL | RTLD_LAZY ); is getting called AsciiFileName"<<AsciiFileName<<endl;
    if (!Handle)
    {
    cout<<"Handle is NULL"<<endl;
    cout<<dlerror()<<endl;
exit(EXIT_FAILURE);

我得到的错误是:

invalid elf header linux

无法打开so文件。这是相关的日志

Before ProcessSharedObject->IterateOnDir
 GCVDirectoryIterator::IterateOnDir:file name :/bin/ls /trnuser1/rmtrain/DevelopmentEnv/Telstra/USM/dat/CnEModules/*.so
 GCVDirectoryIterator::IterateOnDir:file opened  :/trnuser1/rmtrain/DevelopmentEnv/Telstra/USM/dat/CnEModules/libGCVCore.so

before GCVDirectoryIterator::AddFile
HandleFile is getting called
Handle = dlopen( AsciiFileName, RTLD_LOCAL | RTLD_LAZY ); is getting called AsciiFileName/trnuser1/rmtrain/DevelopmentEnv/Telstra/USM/dat/CnEModules/libGCVCore.so
Handle is NULL
/trnuser1/rmtrain/DevelopmentEnv/Telstra/USM/dat/CnEModules/libGCVCore.so: invalid ELF header

2 个答案:

答案 0 :(得分:2)

  

/trnuser1/rmtrain/DevelopmentEnv/Telstra/USM/dat/CnEModules/libGCVCore.so:sturrent ar archive

这是一个静态库(存档),应该是.a,而不是.so。您无法使用dlopen打开它。

答案 1 :(得分:0)

您可能已将libGCVCore.so从Solaris计算机复制到RedHat计算机。 Solaris机器很可能与RedHat架构有不同的架构(Sparc?)。您可以输入以下信息进行确认:

file libGCVCore.so

此命令应打印有关您尝试链接的库的目标体系结构的信息。