Jump to content

How to fix 'undefined reference to ... SC_DISABLE_VIRTUAL_BIND_UNDEFINED_'?


Recommended Posts

Hi,

I am building a SystemC application on Centos 7 using gcc 7.3.1 (devtoolset-7).

Linkage of my application fails with error:

main.cpp:(.text.startup+0x2e): undefined reference to `sc_core::sc_api_version_2_3_3_cxx201402L<&sc_core::SC_DISABLE_VIRTUAL_BIND_UNDEFINED_>
::sc_api_version_2_3_3_cxx201402L(sc_core::sc_writer_policy)'

I can see that this error has been discussed in other forum topics and is caused by a mismatch of the C++ Standard. Therefore, I have checked that I am building both SystemC and the application using C++14. But I still see the error.

I build SystemC 2.3.3 as follows:

$ cmake -DCMAKE_CXX_STANDARD=14 -DBUILD_SHARED_LIBS=OFF ..

and the link command for the application is:

$ /opt/rh/devtoolset-7/root/usr/bin/g++ -O3 -DNDEBUG -Wl,--export-dynamic -rdynamic CMakeFiles/zodiac.
dir/Kernel/main.cpp.o -o zodiac -Wl,-whole-archive /data/daldrich/systemc-2.3.3/systemc-2.3.3/build/systemc-2.3.3-install/lib64/libsystemc
.a -Wl,--no-whole-archive,--as-needed -Wl,--whole-archive,--export-dynamic Kernel/libKernel.a -Wl,--no-whole-archive -ldl -pthread

Here is the full error message:

CMakeFiles/zodiac.dir/Kernel/main.cpp.o: In function `_GLOBAL__sub_I_sc_main':
main.cpp:(.text.startup+0x2e): undefined reference to `sc_core::sc_api_version_2_3_3_cxx201402L<&sc_core::SC_DISABLE_VIRTUAL_BIND_UNDEFINED_>
::sc_api_version_2_3_3_cxx201402L(sc_core::sc_writer_policy)'
collect2: error: ld returned 1 exit status


What am I doing wrong?

Best regards, David

Link to post
Share on other sites

Sorry, I didn't show the application compile command:

/opt/rh/devtoolset-7/root/usr/bin/g++ -DSYSTEMC -Dzodiac_EXPORTS -I../../Kernel -I/data/daldrich/systemc-2.3.3/systemc-2.3.3/src -O3 -
DNDEBUG -Wall -pedantic -pthread -std=c++14 -MD -MT CMakeFiles/zodiac.dir/Kernel/main.cpp.o -MF CMakeFiles/zodiac.dir/Kernel/main.cpp.o.d -
o CMakeFiles/zodiac.dir/Kernel/main.cpp.o -c ../../Kernel/main.cpp

So I do specify "-std=c++14" there.

And the link command repeated from original post:

/opt/rh/devtoolset-7/root/usr/bin/g++ -O3 -DNDEBUG -Wl,--export-dynamic -rdynamic CMakeFiles/zodiac.dir/Kernel/main.cpp.o -o zo
diac -Wl,-whole-archive,-export-dynamic,-no-as-needed /data/daldrich/systemc-2.3.3/systemc-2.3.3/build/systemc-2.3.3-install/lib64/libsyste
mc.a -Wl,--no-whole-archive,--as-needed -Wl,--whole-archive,--export-dynamic Kernel/libKernel.a -Wl,--no-whole-archive -ldl -pthread

(I am assuming that "-std=c++14" isn't needed in the link command).

Link to post
Share on other sites

I am using a static library. Here is the output:

$ nm -C /data/daldrich/systemc-2.3.3/systemc-2.3.3/build/systemc-2.3.3-install/lib64/libsystemc.a | grep
sc_api_version
0000000000000690 T sc_core::
sc_api_version_2_3_3_cxx201103L<&sc_core::SC_DISABLE_VIRTUAL_BIND_UNDEFINED_>::sc_api_version_2_3_3_cxx201103L(sc
_core::sc_writer_policy)
0000000000000690 T sc_core::
sc_api_version_2_3_3_cxx201103L<&sc_core::SC_DISABLE_VIRTUAL_BIND_UNDEFINED_>::sc_api_version_2_3_3_cxx201103L(sc
_core::sc_writer_policy)
0000000000000030 b sc_core::
sc_api_version_2_3_3_cxx201103L<&sc_core::SC_DISABLE_VIRTUAL_BIND_UNDEFINED_>::sc_api_version_2_3_3_cxx201103L(sc
_core::sc_writer_policy)::default_writer_policy_config
0000000000000040 b sc_core::
sc_api_version_2_3_3_cxx201103L<&sc_core::SC_DISABLE_VIRTUAL_BIND_UNDEFINED_>::sc_api_version_2_3_3_cxx201103L(sc
_core::sc_writer_policy)::default_writer_policy_config_seen

Link to post
Share on other sites

Hi @AmeyaVS

Thanks for helping me. I rebuilt my application using C++11 and no error occured. So the question seems to be: why is my SystemC library built using C++11 standard, when I specified:

$ cmake -DCMAKE_CXX_STANDARD=14 -DBUILD_SHARED_LIBS=OFF ..

Best regards

David

Link to post
Share on other sites

I fixed this by specifying the devtoolset-7 g++ compiler to CMake:
 

$ cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_STANDARD=14 -DCMAKE_CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/g++ ..

The problem was caused by CMake using the default Centos 7 g++ compiler (v.4.8.5) which presumably doesn't support C++14.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...