Daiz
Daiz

Reputation: 367

Setting up SystemC-AMS with Eclipse and Cygwin - Undefined Reference Error

I installed SystemC (2.3.2) and SystemC-AMS (2.1) under Windows 7 in Cygwin without issues as follows:

./configure --with-systemc=/home/user/Workspace/systemc-2.3.2
make
make install

I then went into Eclipse (Photon - 4.8.0) and created a new C/C++ Project. For the Toolchain I chose Cygwin GCC. Furthermore, I applied the following settings to the project:

Include Paths:

"C:\cygwin64\home\user\Workspace\systemc-2.3.2\include"    
"C:\cygwin64\home\user\Workspace\systemc-ams-2.1\include"

Library Search Paths:

"C:\cygwin64\home\user\Workspace\systemc-2.3.2\lib-cygwin64"
"C:\cygwin64\home\user\Workspace\systemc-ams-2.1\lib-cygwin64"

Library:

systemc
systemc-ams

Now I try to execute the following code:

#include <iostream>
#include "systemc.h"
#include "systemc-ams.h"

int sc_main (int argc, char* argv[])
{
    std::cout << "Hello World" << std::endl;
    sca_tdf::sca_signal <double> out1;
    return 0;
}

I get an Undefined Reference error:

11:36:35 **** Incremental Build of configuration Debug for project SystemC-AMS-Test ****
make all 
Building file: ../TestSCAMS.cpp
Invoking: Cygwin C++ Compiler
g++ -I"C:\cygwin64\home\user\Workspace\systemc-2.3.2\include" -I"C:\cygwin64\home\user\Workspace\systemc-ams-2.1\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"TestSCAMS.d" -MT"TestSCAMS.o" -o "TestSCAMS.o" "../TestSCAMS.cpp"
Finished building: ../TestSCAMS.cpp

Building target: SystemC-AMS-Test.exe
Invoking: Cygwin C++ Linker
g++ -L"C:\cygwin64\home\user\Workspace\systemc-2.3.2\lib-cygwin64" -L"C:\cygwin64\home\user\Workspace\systemc-ams-2.1\lib-cygwin64" -o "SystemC-AMS-Test.exe"  ./TestSCAMS.o   -lsystemc -lsystemc-ams
C:\cygwin64\home\user\Workspace\systemc-ams-2.1\lib-cygwin64/libsystemc-ams.a(convert_from_string.o):convert_from_string.cpp:(.text$_ZN8sca_util18sca_implementation18convert_by_istreamIN5sc_dt8sc_logicEEEbRT_RKSs[_ZN8sca_util18sca_implementation18convert_by_istreamIN5sc_dt8sc_logicEEEbRT_RKSs]+0x18f): undefined reference to `sc_dt::sc_logic::scan(std::istream&)'
C:\cygwin64\home\user\Workspace\systemc-ams-2.1\lib-cygwin64/libsystemc-ams.a(convert_from_string.o):convert_from_string.cpp:(.text$_ZN8sca_util18sca_implementation18convert_by_istreamIN5sc_dt8sc_logicEEEbRT_RKSs[_ZN8sca_util18sca_implementation18convert_by_istreamIN5sc_dt8sc_logicEEEbRT_RKSs]+0x18f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `sc_dt::sc_logic::scan(std::istream&)'
collect2: error: ld returned 1 exit status
make: *** [makefile:46: SystemC-AMS-Test.exe] Error 1

11:36:38 Build Failed. 1 errors, 0 warnings. (took 3s.199ms)

What could be the issue here?

Upvotes: 0

Views: 315

Answers (1)

matzeri
matzeri

Reputation: 8486

On some platforms like windows, cygwin and others undefined symbols are not allowed at link stage.
The link order matters

"-lsystemc -lsystemc-ams" is not the same of " -lsystemc-ams -lsystemc"

as systemc-ams is using symbols of systemc the second version guarantees that all symbols are resolved at link stage. It is also the reason why compiling any program the libraries invocation are at the end of the command.

gcc dummy.c -lsystemc works while gcc -lsystemc dummy.c fails with undefined symbols error

Upvotes: 1

Related Questions