Hi Hasan,

Based on the comment that it works in a .c file but not a .cc file, it
sounds like you may need to wrap your C function prototypes in with extern
"C" { }; in your header file for the library. The c++ compiler will mangle
the symbols (hence linker errors) and this will prevent that.

i.e.,

extern "C" {

     int write_mem( unsigned int, int, char* );
     void fw_init( unsigned char );

};


-- 
Matt Poremba
Ph.D. Candidate
111N IST Building
Pennsylvania State University
University Park, PA 16802
Phone: 814-689-9447
Email: [email protected]


On Wed, Apr 24, 2013 at 7:52 AM, Hasan Ijaz <[email protected]> wrote:

>
>
> Sorry for replying so late. I was actually busy with some other "high
> priority" work at office.
>
> When I call functions in the disk_image.cc file that are defined in my
> library I am getting this error just when the linking starts:
>
>  [  RANLIB]  -> gzstream/libgzstream.a
>  [    LINK]  -> X86/gem5.debug
> build/X86/dev/disk_image.do: In function `SsdDiskImage':
> /home/opensilicon/Codes/gem5-stable/build/X86/dev/disk_image.cc:84:
> undefined reference to `write_mem(unsigned int, int, char*)'
> /home/opensilicon/Codes/gem5-stable/build/X86/dev/disk_image.cc:84:
> undefined reference to `write_mem(unsigned int, int, char*)'
> collect2: ld returned 1 exit status
> scons: *** [build/X86/gem5.debug] Error 1
> scons: building terminated because of errors.
>
>
> With the verbose option '--verbose' I get the following lines:
>
> gcc -o build/X86/dev/ssd_Apis.do -c -pipe -fno-strict-aliasing -Wall
> -Wno-sign-compare -Wundef -ggdb3 -Werror -DDEBUG -DTRACING_ON=1
> -Ibuild/gzstream -Ibuild/libelf -Iext -I/usr/include/python2.7
> -Isrc/dev/framework/include -Ibuild/X86 build/X86/dev/ssd_Apis.c
>
> g++ -o build/X86/gem5.debug build/X86/sim/main.do ...............
> build/X86/dev/disk_image.do build/X86/dev/dma_device.do
> build/X86/dev/etherbus.do
> build/X86/dev/etherdevice.do................................................................................................................................................................................
>
> ..........................................................................................................................................................................................................................
> ...build/X86/base/date.do -Lbuild/gzstream -Lbuild/libelf -L/usr/lib
> -L/usr/lib/python2.7/config -Lsrc/dev -lfw -lpthread -ldl -lutil -lm
> -lpython2.7 -lz -lrt -lelf -lgzstream
>
> So I guess the -lfw option appears after disk_image.do.  I have defined it
> here in Sconstruct file:
> ########################################################################
> #
> # Set up the main build environment.
> #
> ########################################################################
> use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH',
> 'PATH',
>                  'PYTHONPATH', 'RANLIB', 'SWIG' ])
>
> use_env = {}
> for key,val in os.environ.iteritems():
>     if key in use_vars or key.startswith("M5"):
>         use_env[key] = val
>
> main = Environment(ENV=use_env)
> main.Decider('MD5-timestamp')
> main.root = Dir(".")         # The current directory (where this file
> lives).
> main.srcdir = Dir("src")     # The source directory
>
>
> # add the framework library path to the main environment
> main.Append(CPPPATH =
> ['/home/opensilicon/Codes/gem5-stable/src/dev/framework/include'])
> main.Append(LIBPATH = ['/home/opensilicon/Codes/gem5-stable/src/dev'])
> main.Append(LIBS = ['fw'])
>
> Help!!!
>
>
>
>   ------------------------------
>  *From:* Andreas Hansson <[email protected]>
> *To:* Hasan Ijaz <[email protected]>
> *Sent:* Thursday, April 18, 2013 11:58 AM
>
> *Subject:* Re: [gem5-users] Error while Linking static Library with GEM5
>
>  Where did you add the main.Append(LIBS=…)? Could it be that the –lfw
> appears before disk_image.o on the linker command line? Once again, use the
> –v to see the linker command line.
>
>  Andreas
>
>   From: Hasan Ijaz <[email protected]>
> Reply-To: Hasan Ijaz <[email protected]>
> Date: Thursday, 18 April 2013 06:11
> To: Andreas Hansson <[email protected]>
> Cc: "[email protected]" <[email protected]>
>
> Subject: Re: [gem5-users] Error while Linking static Library with GEM5
>
>   I am sorry I meant to say that when I call my fw_init() function in A.c
> the whole system compiles and links succesfully however it does not in the
> case when I call my fw_init function in the disk_image.cc file.
>
>  The fw_init() function is defined in the library!
>
>  Regards,
> Hasan Ijaz
>
>   ------------------------------
> *From:* Andreas Hansson <[email protected]>
> *To:* Hasan Ijaz <[email protected]>; gem5 users mailing list <
> [email protected]>
> *Sent:* Wednesday, April 17, 2013 7:02 PM
> *Subject:* Re: [gem5-users] Error while Linking static Library with GEM5
>
>  I am confused. Is the fw_init definition (not just an extern
> declaration) in the source you compile in (A.c or disk_image.cc)? If so,
> why do you need the library?
>
>  The "-v" has to go at the end. You don't want to know the version of
> scons, but tell it to be verbose :-)
>
>  Andreas
>
>   From: Hasan Ijaz <[email protected]>
> Reply-To: Hasan Ijaz <[email protected]>, gem5 users mailing list <
> [email protected]>
> Date: Wednesday, 17 April 2013 08:59
> To: "[email protected]" <[email protected]>
> Subject: Re: [gem5-users] Error while Linking static Library with GEM5
>
>
>  Hi,
>
> I figured something out. Here is the scenario. In the
> gem5-stable/dev/Sconscript file I have these two files:
>
> Source('A.c')
> Source('disk_image.cc')
>
>  Consider the function fw_inti(). If i place my function fw_init() in the A.c
> file it compiles and links successfully. However if I put it in the
> disk_image.cc file it does not.
>
>  And if I remove the line
>
>  main.Append(LIBS = ['fw']) in the SConstruct file
>
>  the function stops being linked in both the files. Which means that
> scons is taking the right library path and is linking the function
> fw_init() when it is placed in the A.c file. However it is unable to link
> when the function is in the .cc file.
>
>  Does this seem absurd? What am I missing?
>
>  Regards,
>  Hasan Ijaz
>   ------------------------------
> *From:* Andreas Hansson <[email protected]>
> *To:* Hasan Ijaz <[email protected]>; gem5 users mailing list <
> [email protected]>
> *Sent:* Wednesday, April 17, 2013 5:04 PM
> *Subject:* Re: [gem5-users] Error while Linking static Library with GEM5
>
>  Hi Hasan,
>
>  What you have done looks absolutely right, with the exception that you
> should not inlude "lib" in the library name. Thus, LIBS = ['fw']. You can
> always run scons with "-v" and have a look at the linking command line to
> ensure it is correct.
>
>  Good luck.
>
>  Andreas
>
>   From: Hasan Ijaz <[email protected]>
> Reply-To: Hasan Ijaz <[email protected]>, gem5 users mailing list <
> [email protected]>
> Date: Wednesday, 17 April 2013 06:54
> To: "[email protected]" <[email protected]>
> Subject: [gem5-users] Error while Linking static Library with GEM5
>
>   Hi,
>
>          I am trying to compile a software framework with GEM5. I have
> compiled my code into a static library using make. After that I have added
> these lines to SContruct file:
>
>  # add the framework library path to the main environment
> main.Append(CPPPATH =
> ['/home/opensilicon/Codes/gem5-stable/src/dev/framework/include'])
> main.Append(LIBPATH = ['/home/opensilicon/Codes/gem5-stable/src/dev'])
> main.Append(LIBS = ['libfw'])
>
>      I am calling functions from the library in the Disk_Image.cc file.
> It compiles successfully but during Linking I get the following error:
>
>  In function `SsdDiskImage':
> /home/opensilicon/Codes/gem5-stable/build/X86/dev/disk_image.cc:63:
> undefined reference to `fw_init(unsigned char)'
>
>  Although this function compiles suceessfully and is in the lib. What am
> I missing?
>
>  Regards,
>  Hasan Ijaz
>
> -- IMPORTANT NOTICE: The contents of this email and any attachments are
> confidential and may also be privileged. If you are not the intended
> recipient, please notify the sender immediately and do not disclose the
> contents to any other person, use it for any purpose, or store or copy the
> information in any medium. Thank you.
>
>
>
>
>
> -- IMPORTANT NOTICE: The contents of this email and any attachments are
> confidential and may also be privileged. If you are not the intended
> recipient, please notify the sender immediately and do not disclose the
> contents to any other person, use it for any purpose, or store or copy the
> information in any medium. Thank you.
>
>
>
> -- IMPORTANT NOTICE: The contents of this email and any attachments are
> confidential and may also be privileged. If you are not the intended
> recipient, please notify the sender immediately and do not disclose the
> contents to any other person, use it for any purpose, or store or copy the
> information in any medium. Thank you.
>
>
>
>
>
>
>
> _______________________________________________
> gem5-users mailing list
> [email protected]
> http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
>
_______________________________________________
gem5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users

Reply via email to