systemC (Linker error - undefined reference)

Jan 22, 2010 at 2:58pm
This is is supposed to be an implimentation of a 4bit shift register (vhdl style coding I am afraid...).
The dff.h constracts a d-flipflop
The btrg.h links 4 dff's together to form a register.
The main.cpp calls and initiates the register ,constructs the clock and the signals and opens a file to write down the simulation results.

Systemc library and headers are declared but when build it gives [Linker error] undefined reference ... What I am doing wrong?

I have used Dev-C++ and Visual Studio 2008. Both end with the same problem

dff.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef DFF_H
#define DFF_H 
#include <systemc.h>

struct dff : sc_module
//SC_MODULE(dff)
{
	sc_in<bool>	datain;
	sc_in<bool>	clock;
	sc_out<bool>	dataout;

	void d1()
	{
		dataout.write(datain.read());
	};

	SC_CTOR(dff)
	{	
		SC_METHOD(d1);
		sensitive << clock.pos();
	}
};

#endif 


btrg.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef BTRG_H
#define BTRG_H
#include <systemc.h>

struct btrg : sc_module
//SC_MODULE(btrg)
{
	sc_signal<bool> do1, do2, do3;
	sc_in<bool> rgin;
	sc_in<bool> clk;
	sc_out<bool> rgout;
	
	dff *df1;
	dff *df2;
	dff *df3;
	dff *df4;
	

	SC_CTOR(btrg)
	{
		#include <dff.h>
		df1 = new dff ("df1");
		df1->datain(rgin);
		df1->clock(clk);
		df1->dataout(do1);

		df2 = new dff ("df2");
		df2->datain(do1);
		df2->clock(clk);
		df2->dataout(do2);

		df3 = new dff ("df3");
		df3->datain(do2);
		df3->clock(clk);
		df3->dataout(do3);

		df4 = new dff ("df4");
		df4->datain(do3);
		df4->clock(clk);
		df4->dataout(rgout);

	}
};

#endif 


main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <systemc.h>
#include <dff.h>
#include <btrg.h>


int main(int argc, char* argv[])
{
	sc_signal<bool> rgin, rgout;
	sc_clock clk("clock",10,SC_NS,0.5);
	
	
	btrg DUT("btrg");

	DUT.rgin(rgin);                       
    DUT.rgout(rgout);
    DUT.clk(clk);
	sc_trace_file *fp;                  
    fp=sc_create_vcd_trace_file("wave");
    fp->set_time_unit(100, SC_PS);      
    sc_trace(fp,clk,"clk");            
    sc_trace(fp,rgin,"din");
    sc_trace(fp,rgout,"dout");

    sc_start(31, SC_NS);                
    rgin=true;                           
    sc_start(31, SC_NS);                
    rgin=false;                          
    sc_start(31, SC_NS);                

    sc_close_vcd_trace_file(fp);


    return 0;
}


Error (partial)

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Myprojects\Makefile.win"
Executing  make clean
rm -f main.o  Project2.exe

g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"  -I"C:/MyDocumentsonC/OSCI/OSCI_gz/systemc-2.2.0/src"  -I"C:/Dev-Cpp/Myprojects"    -g3

g++.exe -D__DEBUG__ main.o  -o "Project2.exe" -L"C:/Dev-Cpp/lib" -L"C:/MyDocumentsonC/OSCI/OSCI_gz/systemc-2.2.0/msvc71/SystemC/Debug"  -g3 

main.o(.text+0x1d3): In function `main':
C:/Dev-Cpp/Myprojects/main.cpp:9: undefined reference to `sc_core::sc_clock::sc_clock(char const*, double, sc_core::sc_time_unit, double)'
main.o(.text+0x1f3):C:/Dev-Cpp/Myprojects/main.cpp:12: undefined reference to `sc_core::sc_module_name::sc_module_name(char const*)'
main.o(.text+0x23b):C:/Dev-Cpp/Myprojects/main.cpp:12: undefined reference to `sc_core::sc_module_name::~sc_module_name()'
main.o(.text+0x264):C:/Dev-Cpp/Myprojects/main.cpp:12: undefined reference to `sc_core::sc_module_name::~sc_module_name()'
main.o(.text+0x2ce):C:/Dev-Cpp/Myprojects/main.cpp:18: undefined reference to `sc_core::sc_create_vcd_trace_file(char const*)'
main.o(.text+0x3e3):C:/Dev-Cpp/Myprojects/main.cpp:30: undefined reference to `sc_core::sc_close_vcd_trace_file(sc_core::sc_trace_file*)'
main.o(.text+0x413):C:/Dev-Cpp/Myprojects/main.cpp:33: undefined reference to `sc_core::sc_clock::~sc_clock()'
main.o(.text+0x42b):C:/Dev-Cpp/Myprojects/main.cpp:33: undefined reference to `sc_core::sc_signal<bool>::~sc_signal()'
main.o(.text+0x440):C:/Dev-Cpp/Myprojects/main.cpp:33: undefined reference to `sc_core::sc_signal<bool>::~sc_signal()'
main.o(.text+0x4ea):C:/Dev-Cpp/Myprojects/main.cpp:33: undefined reference to `sc_core::sc_clock::~sc_clock()'
main.o(.text+0x51a):C:/Dev-Cpp/Myprojects/main.cpp:33: undefined reference to `sc_core::sc_signal<bool>::~sc_signal()'
main.o(.text+0x547):C:/Dev-Cpp/Myprojects/main.cpp:33: undefined reference to `sc_core::sc_signal<bool>::~sc_signal()'
Jan 22, 2010 at 5:22pm
g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"  -I"C:/MyDocumentsonC/OSCI/OSCI_gz/systemc-2.2.0/src"  -I"C:/Dev-Cpp/Myprojects"    -g3

g++.exe -D__DEBUG__ main.o  -o "Project2.exe" -L"C:/Dev-Cpp/lib" -L"C:/MyDocumentsonC/OSCI/OSCI_gz/systemc-2.2.0/msvc71/SystemC/Debug"  -g3 


Do you have to link to the library? I don't see any -l parameters. With GCC, -I specifies a path to look for headers, -L specifies a library path, and -l adds a library.
Last edited on Jan 22, 2010 at 5:23pm
Jan 22, 2010 at 5:23pm
try switching from
#include <btrg.h>
to
#include "btrg.h"
Jan 22, 2010 at 5:52pm
I think the linker needs the library.

"-l" command
Jan 25, 2010 at 11:21am
I have tried all the above solutions but the linker error persists. Any other ideas?
Jan 25, 2010 at 3:29pm
please post your command line used to compile with the "-l<LIBRARY>" command. Its a linker error so its just a matter of finding the right command, and possibly ordering of the libraries.
Jan 30, 2010 at 11:02pm
snpl,

I'm interested in setting up SystemC on DevC++. How did you do it?
Jan 30, 2010 at 11:23pm
It looks like your makefile is not linking with your code modules.

Make sure in the VC project options you have every one of your cpp files listed, and every one of the external library files listed. If they are not listed as part of the project, the compiler won't compile and link them with your application.

Good luck!
Jan 31, 2010 at 9:52pm
I was able to simulate the posted design and obtained a VCD waveform.

F:/Dev-Cpp/bin/g++ -Wall -I"F:/projects" -I"F:/Dev-Cpp/systemc-220-5jun2006-forMinGW~/systemc22.20060605/src" -L"F:/Dev-Cpp/systemc-220-5jun2006-forMinGW~/systemc22.20060605/msvc71/SystemC" main.cpp -lSystemC -o "Project2.exe"

Note: VCD trace timescale unit is set by user to 1.000000e-010 sec.

I installed MinGW distribution of SystemC and converted the .sln/.vcproj in the distribution to .dsw/.dsp using this tool: http://www.codeproject.com/KB/applications/prjconverter.aspx?fid=10069&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=101&select=844614

Then I compiled SystemC after a couple of hiccups on DevC++ with MinGW port.

It has been a good exercise.

Cheers!

AMS (analog and mixed signal)

Feb 20, 2010 at 7:47am
Today I register here to THANK U all. I was about to pull my hairs out .. The following line make my life out of hell.

F:/Dev-Cpp/bin/g++ -Wall -I"F:/projects" -I"F:/Dev-Cpp/systemc-220-5jun2006-forMinGW~/systemc22.20060605/src" -L"F:/Dev-Cpp/systemc-220-5jun2006-forMinGW~/systemc22.20060605/msvc71/SystemC" main.cpp -lSystemC -o "Project2.exe"

Again thanking U all. Love U all
Regards,
Prady
Topic archived. No new replies allowed.