3

我已经将一个 c++ 代码从一个开放的 solaris 操作系统移植到了 Redhat 4 操作系统。在此代码段中,我收到错误消息:

    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
4

2 回答 2

3

/trnuser1/rmtrain/DevelopmentEnv/Telstra/USM/dat/CnEModules/libGCVCore.so:当前 ar 存档

那是一个静态库(存档),应该是.a,而不是.so. 你不能用dlopen.

于 2012-07-04T16:24:45.637 回答
0

您可能将 libGCVCore.so 从 Solaris 机器复制到 RedHat 机器。Solaris 机器很可能具有与 RedHat 不同的体系结构(Sparc?)。您可以通过键入以下内容进行确认:

file libGCVCore.so

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

于 2012-07-04T10:14:00.170 回答