ArticleDirectory
- System Environment
- Fault Cause
- Solution
- Practical drills
System Environment
- Centos 5.3 64bit
- GCC 4.1
- EMC 2.2
Operation Purpose
- Compile the EMC module into. So from externalProgramCall
Fault
- During compilation, GCC indicates that libsystemc. A needs to be compiled using the-FPIC switch, and the module cannot find the symbol.
Fault Cause
- Libsystemc. A needs to be compiled into pic to import the EMC module into. So.Code. By default, gcc4 does not enable the-FPIC switch.
Solution
- Open the configure. In file and add-FPIC to the-wall switch on the Linux x86_64 platform. Run the distinstall and bootup scripts in the config directory to generate new configurations. Then it works normally./configure, make, make install, and make clean.
Practical drills
- Declare a. So file named "trust", and then execute this. So file in an external program (in fact, manually execute the function in. So ). The code for the two files is as follows.
Code # Include < Iostream >
# Include < EMC. h >
Using NamespaceSTD;
SC _module (first_counter)
{
SC _ctor (first_counter ){
Cout<"Trust"<Endl;
}
};
Int SC _main ( Int Argc, Char * Argv [])
{
Cout < " SC _main running! " < Endl;
For ( Int I = 0 ; I < Argc; ++ I)
{
Cout < ' \ T ' < Argv [I] < Endl;
}
First_counter C1 ( " C1 " );
Return 0 ;
}
# DefineExport _ attribute _ (visibility ("default ")))
Extern " C "
{
Export
Void Fork ( Int N, Int M)
{
Char ** Argv = ( Char ** ) Malloc ( Sizeof ( Void * ) * 2 );
CharBuf [256];
Sprintf (BUF,"% D", N );
Argv [0]=Strdup (BUF );
sprintf (BUF, " % d " , m);
argv [ 1 ] = strdup (BUF);
SC _main (2, Argv );
Free (argv [0]);
Free (argv [1]);
Free (argv );
}
}
Code # Include < Dlfcn. h >
# Include < Iostream >
Using NamespaceSTD;
TypedefVoid(*Pfnvoidint )(Int,Int);
int main ( int argc, char * argv [])
{< br> void * handle = dlopen ( " /home/bo/projects/Trust/libtrust. so " , rtld_lazy );
Pfnvoidint forkfunc=(Pfnvoidint) dlsym (handle,"Fork");
If(Forkfunc)
Forkfunc (1234567890,1122334455);
Dlclose (handle );
Return 0;
}
the execution result is completely normal. The parameters are correctly transmitted to the EMC module. So.