bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bluespec link failure with .cpp, irrespective of directory

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: Bluesim
View previous topic :: View next topic  
Author Message
vmurali



Joined: 30 Jul 2008
Posts: 11

PostPosted: Fri Aug 24, 2012 7:24 am    Post subject: Bluespec link failure with .cpp, irrespective of directory Reply with quote

Hi

I posted the same question here http://www.bluespec.com/forum/viewtopic.php?t=233 , but got no responses, so I am posting again.

I run into the same issue. I have double checked if I have included the .cpp file while calling bsc for linking. I also made sure that the c++ command includes the .o file for creating the a.out.so. Here is my code, my commands and compilation outputs:



TestBench.bsv:
Code:

import "BDPI" function Bit#(32) sysCall();

(* synthesize *)
module mkTestBench();
  rule test;
    $display("%d", sysCall());
  endrule
endmodule


system.cpp:
Code:

int sysCall() {
  return 42;
}


Quote:

$ bsc -u -sim ./TestBench.bsv
checking package dependencies
compiling ./TestBench.bsv
Foreign import file created: sysCall.ba
code generation for mkTestBench starts
Elaborated module file created: mkTestBench.ba
All packages are up to date.


$ bsc -u -sim -verbose -e mkTestBench *.ba *.cpp
Bluespec Compiler, version 2012.05.beta1 (build 28702, 2012-05-14)
Copyright 2000-2012 Bluespec, Inc.
Parts copyright 2002, The University Court of the University of Glasgow.
Parts copyright 1982-1999 Lennart Augustsson, Thomas Johnsson,
Chalmers University of Technology.
Parts copyright 1999-2000, Daan Leijen.
Parts copyright 1991, 1999 Free Software Foundation, Inc.
Parts copyright 1995-2012, Regents of the University of Colorado.
Parts copyright 2010, Don Stewart.
All rights reserved.
See documentation for license details.

Invoking command line:
bsc -u -sim -verbose -e mkTestBench mkTestBench.ba sysCall.ba system.cpp

starting license
license done
elapsed time: CPU 0.01s, real 0.09s

confirm C files exist
elapsed time: CPU 0.00s, real 0.09s

starting readelab
readelab done
elapsed time: CPU 0.01s, real 0.01s

starting simExpand
simExpand done
elapsed time: CPU 0.00s, real 0.00s

starting simDepend
simDepend done
elapsed time: CPU 0.00s, real 0.00s

starting simPackageOpt
simPackageOpt done
elapsed time: CPU 0.00s, real 0.00s

starting simMakeCBlocks
simMakeCBlocks done
elapsed time: CPU 0.00s, real 0.00s

starting simCOpt
simCOpt done
elapsed time: CPU 0.00s, real 0.00s

starting simBlocksToC
simBlocksToC done
elapsed time: CPU 0.00s, real 0.00s

starting genSystemC
genSystemC done
elapsed time: CPU 0.00s, real 0.00s

starting writeC
writeC done
elapsed time: CPU 0.00s, real 0.00s

starting bluesimcompile
exec: c++ -O3 -g -Wall -Wno-unused -D_FILE_OFFSET_BITS=64 -I"/afs/csail/group/csg/tools_lx86/bluespec/current/lib"/Bluesim -Wno-uninitialized -fpermissive -fPIC -c -o mkTestBench.o mkTestBench.cxx
Bluesim object created: mkTestBench.{h,o}
exec: c++ -O3 -g -Wall -Wno-unused -D_FILE_OFFSET_BITS=64 -I"/afs/csail/group/csg/tools_lx86/bluespec/current/lib"/Bluesim -Wno-uninitialized -fpermissive -fPIC -c -o model_mkTestBench.o model_mkTestBench.cxx
Bluesim object created: model_mkTestBench.{h,o}
compile generated C files
elapsed time: CPU 0.00s, real 0.60s

exec: c++ -O3 -g -Wall -Wno-unused -D_FILE_OFFSET_BITS=64 -fpermissive -fPIC -c -o system.o system.cpp
User object created: system.o
compile user-provided C files
elapsed time: CPU 0.00s, real 0.01s

bluesimcompile done
elapsed time: CPU 0.00s, real 0.61s

starting bluesimlink
linking
exec: c++ -O3 -g -Wall -Wno-unused -D_FILE_OFFSET_BITS=64 -shared -fPIC -Wl,-Bsymbolic -Wl,--version-script="/afs/csail/group/csg/tools_lx86/bluespec/current/lib/Bluesim/bs_linux_export_map.txt" -o a.out.so mkTestBench.o system.o model_mkTestBench.o /afs/csail/group/csg/tools_lx86/bluespec/current/lib/Bluesim/g++4_64/libbskernel.a /afs/csail/group/csg/tools_lx86/bluespec/current/lib/Bluesim/g++4_64/libbsprim.a -lm
exec: strip -x a.out.so
Simulation shared library created: a.out.so
Simulation executable created: a.out
bluesimlink done
elapsed time: CPU 0.00s, real 0.09s

total
elapsed time: CPU 0.02s, real 0.89s


$ ./a.out
Error: dlopen: ./a.out.so: undefined symbol: sysCall
invoked from within
"sim load $model_name $top_module"
invoked from within
"if {$wait} {
sim load $model_name $top_module wait
} else {
sim load $model_name $top_module
}"
(file "/afs/csail/group/csg/tools_lx86/bluespec/current/lib/tcllib/bluespec/bluesim.tcl" line 174)




Any ideas why this doesn't work? i dont seem to be able to link any C++ functions in bluespec anymore.
Back to top
View user's profile Send private message
patil.nikhil



Joined: 17 Aug 2007
Posts: 69
Location: University of Texas at Austin

PostPosted: Fri Aug 24, 2012 9:29 am    Post subject: Reply with quote

Murali,

I think you need to either (a) put sysCall into a .c file not .cpp, or (b) surround the sysCall function with:

extern "C" {
...
}

This prevents the C++ identifier name mangling.

nikhil
Back to top
View user's profile Send private message Visit poster's website
vmurali



Joined: 30 Jul 2008
Posts: 11

PostPosted: Sat Aug 25, 2012 7:55 am    Post subject: Reply with quote

Ok, this works. The function is indeed not present in the object file unless I put an extern "C".
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: Bluesim All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP