subodh1989
subodh1989

Reputation: 716

invalid elf header linux

I have ported a c++ code from an open solaris OS to Redhat 4 OS. In this code snippet iam am getting an error :

    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);

The error i am getting is :

invalid elf header linux

It is not able to open the so file.Here is the relevant log for it

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

Upvotes: 3

Views: 11880

Answers (2)

Karoly Horvath
Karoly Horvath

Reputation: 96258

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

That's a static library (archive), and should be .a, not .so. You cannot open it with dlopen.

Upvotes: 3

Sdra
Sdra

Reputation: 2347

You probably copied libGCVCore.so from a Solaris machine to a RedHat machine. Most likely the Solaris machine have a different architecture (Sparc?) than the RedHat one. You can have a confirmation by typing:

file libGCVCore.so

This command should print info about the target architecture of the library you are trying to link.

Upvotes: 0

Related Questions