KMLM List
View email archives for the history of this mailing list.
|
|
|
|
systemc-forum - Re: [systemc-forum] Link Error
|
Message Thread:
Previous |
Next
|
- To: Shehzad Hussain <shehzad.hussain86@xxxxxxxxx>
- From: "Philipp A. Hartmann" <philipp.hartmann@xxxxxxxx>
- Date: Thu, 14 Oct 2010 09:19:06 +0200
- Cc: systemc-forum@xxxxxxxxxxxxxxxxx
- Send Email to systemc-forum@lists.systemc.org:
- Send new message
- Reply to this message
|
Shezad,
find some comments below.
On 14/10/10 04:26, Shehzad Hussain wrote:
>
> I am getting this link error when I compile my code. please, help.
>
> //counter.h
> #include <systemc.h>
You should use so-called "include guards" in your header files.
Something like:
#ifndef COUNTER_H_INCLUDED_
#define COUNTER_H_INCLUDED_
> template <class N, int T = 100>
> SC_MODULE(counter)
> {
> sc_in<bool> clock;
> sc_in<bool> load;
> sc_in<bool> reset;
> sc_in<sc_int<T> > data_in;
> sc_out<sc_int<T> > Q;
> void prc_counter();
> SC_HAS_PROCESS(counter);
> counter(sc_module_name name_): sc_module(name_)
>
> //SC_CTOR(counter)/*:clock("clock"), load("load"),
> reset("reset"),data_in("data_in"), Q("Q")*/
The use of the SC_CTOR macro is recommended, if you don't have
additional parameters in your constructor than the module name.
> {
> SC_METHOD(prc_counter)
> {
> sensitive << clock.pos();
> }
The additional braces around the sensitivity specification are not
needed, but don't do real harm here, though.
> }
> };
// closing include-guard
#endif // COUNTER_H_INCLUDED_
> //counter.cpp
>
> // counter.cpp
> #include <systemc.h>
> #include "counter.h"
> template <class N, int T>
> void counter<N,T>::prc_counter()
You can't separate the compilation of templates into their own
translation units (i.e. .cpp files). Read up on C++ templates and have
a look at the comp.lang.c++ FAQ at
http://www.parashift.com/c++-faq-lite/templates.html
- [35.12] Why can't I separate the definition of my templates class
from its declaration and put it inside a .cpp file?
- [35.13] How can I avoid linker errors with my template functions?
[snip process body]
> //top.h
// add include guards again
#ifndef TOP_H_INCLUDED_
#define TOP_H_INCLUDED_
> #include <systemc.h>
> SC_MODULE(top)
> {
>
> sc_signal<bool> d_load;
> sc_signal<bool> d_reset;
> sc_signal<sc_int<2> > d_out;
> sc_signal<sc_int<2> > q_in;
> sc_clock clk1;
>
> void prc_top();
> SC_CTOR(top)/*:d_load("d_load"),d_reset("d_reset"),d_out("d_out"),("q_in"),clk1("clk1")*/
No need to drop the initialiser list. ;)
> {
> SC_METHOD(prc_top)
> {
> sensitive<<clk1<<d_load<<d_reset<<d_out<<q_in;
> }
Additional braces, see above.
> }
> };
// closing include guard.
#endif // TOP_H_INCLUDED_
>
> //top.cpp
>
> #include "top.h"
> #include "counter.h"
You probably need to include "counter.h" from within top.h.
> void top::prc_top()
> {
> d_load=1;
> d_load=0;
> d_reset=0;
> q_in=1;
> sc_clock clk1("clk",10,SC_NS);
> counter<int,2> counter1("counter1");
prc_top() is an SC_METHOD. You can't instantiate structural components
like modules (counter) and channels (clk1) inside processes.
Make these members of top.h and initialise the inside top's constructor.
> counter1.clock(clk1);
> counter1.load(d_load);
> counter1.reset(d_reset);
> counter1.data_in(d_out);
> counter1.Q(q_in);
>
> }
>
> //main.cpp
>
> #include "counter.h"
> #include "top.h"
At least here, you need the include guards in your headers.
> int sc_main(int argc, char* argv[])
> {
You most probably want to instantiate your top module here.
Otherwise, your simulation is quite boring... ;-)
top t( "top" );
> sc_start();
> return 0;
> }
>
> Error:
>
> 1>top.obj : error LNK2019: unresolved external symbol "public: void
> __thiscall counter<int,2>::prc_counter(void)"
> (?prc_counter@?$counter@H$01@@QAEXXZ) referenced in function "public:
> __thiscall counter<int,2>::counter<int,2>(class sc_core::sc_module_name)"
> (??0?$counter@H$01@@QAE@Vsc_module_name@sc_core@@@Z)
The linker error you see is related to the separate compilation of
counter.cpp. Inside counter.cpp you don't instantiate any instance of
the counter<T,N> template. In top.cpp you don't provide any
implementation of the template's member function 'prc_counter'. Thus,
the linker fails to find it. Put counter<T,N>::prc_counter into counter.h.
Greetings from Oldenburg,
Philipp
--
Philipp A. Hartmann
Hardware/Software Design Methodology Group
OFFIS Institute for Information Technology
R&D Division Transportation · FuE-Bereich Verkehr
Escherweg 2 · 26121 Oldenburg · Germany
Phone/Fax: +49-441-9722-420/282 · PGP: 0x9161A5C0 · http://www.offis.de/
Attachment:
signature.asc
Description: OpenPGP digital signature
|
|
By Date:
Previous |
Next
|
Current Thread
|
By Thread:
Previous |
Next
|
- Link Error, Shehzad Hussain 02:26 GMT
- Re: [systemc-forum] Link Error, Philipp A. Hartmann (you are here)
|
|