Undefined reference in gcc/linux

I'm trying to use OCCT 6.9.1 to import IGES files into our existing software package.  I'm on Debian linux using gcc.  I've built OCCT using Automake and added all of the libraries to the compiler command line.  However, I still get numerous undefined references, mostly for the IGES-specific functions.  Here's the tail end of our very lengthy gcc command line:

... -Lsrc/oc-691/lib -lTKBO -lTKBRep -lTKBool -lTKFeat -lTKFillet -lTKG2d -lTKG3d -lTKGeomAlgo -lTKGeomBase -lTKHLR -lTKMath -lTKMesh -lTKOffset -lTKPrim -lTKShHealing -lTKTopAlgo -lTKXMesh -lTKernel

That's all of the libraries in the oc-691/lib directory.  Here's the linker errors I'm getting:

src/lib/iges/import/iges_import.c:316: error: undefined reference to 'IGESControl_Reader::IGESControl_Reader()'
src/lib/iges/import/iges_import.c:317: error: undefined reference to 'XSControl_Reader::ReadFile(char const*)'
src/lib/iges/import/iges_import.c:333: error: undefined reference to 'XSControl_Reader::PrintCheckLoad(unsigned int, IFSelect_PrintCount) const'
src/lib/iges/import/iges_import.c:337: error: undefined reference to 'Interface_Static::SetCVal(char const*, char const*)'
src/lib/iges/import/iges_import.c:343: error: undefined reference to 'XSControl_Reader::TransferRoots()'
src/lib/iges/import/iges_import.c:352: error: undefined reference to 'IGESControl_Reader::PrintTransferInfo(IFSelect_PrintFail, IFSelect_PrintCount) const'
src/lib/iges/import/iges_import.c:355: error: undefined reference to 'XSControl_Reader::OneShape() const'
src/lib/iges/import/iges_import.c:488: error: undefined reference to 'IGESControl_Reader::IGESControl_Reader()'
src/lib/iges/import/iges_import.c:489: error: undefined reference to 'XSControl_Reader::ReadFile(char const*)'
src/lib/iges/import/iges_import.c:498: error: undefined reference to 'IGESControl_Reader::IGESModel() const'
src/lib/iges/import/iges_import.c:498: error: undefined reference to 'IGESData_IGESModel::GlobalSection() const'
src/lib/iges/import/iges_import.c:498: error: undefined reference to 'IGESData_GlobalSection::UnitName() const'
src/lib/iges/import/iges_import.c:516: error: undefined reference to 'IGESControl_Reader::IGESModel() const'
src/lib/iges/import/iges_import.c:516: error: undefined reference to 'IGESData_IGESModel::GlobalSection() const'
src/lib/iges/import/iges_import.c:516: error: undefined reference to 'IGESData_GlobalSection::CompanyName() const'
src/lib/iges/import/iges_import.c:518: error: undefined reference to 'IGESControl_Reader::IGESModel() const'
src/lib/iges/import/iges_import.c:518: error: undefined reference to 'IGESData_IGESModel::GlobalSection() const'
src/lib/iges/import/iges_import.c:518: error: undefined reference to 'IGESData_GlobalSection::AuthorName() const'
src/lib/iges/import/iges_import.c:520: error: undefined reference to 'IGESControl_Reader::IGESModel() const'
src/lib/iges/import/iges_import.c:520: error: undefined reference to 'IGESData_IGESModel::GlobalSection() const'
src/lib/iges/import/iges_import.c:520: error: undefined reference to 'IGESData_GlobalSection::CompanyName() const'
src/lib/iges/import/iges_import.c:522: error: undefined reference to 'IGESData_GlobalSection::IGESVersion() const'
src/lib/iges/import/iges_import.c:524: error: undefined reference to 'IGESData_GlobalSection::Date() const'
src/lib/iges/import/iges_import.c:526: error: undefined reference to 'IGESData_GlobalSection::SendName() const'
src/lib/iges/import/iges_import.c:528: error: undefined reference to 'IGESData_GlobalSection::SystemId() const'
src/oc-691/inc/XSControl_Reader.hxx:83: error: undefined reference to 'vtable for XSControl_Reader'
src/oc-691/inc/IGESControl_Reader.hxx:60: error: undefined reference to 'vtable for IGESControl_Reader'

 

I know it's finding some of the libraries, because there are many other calls to OCCT functions in my code which do not show up in the errors.

What am I overlooking?  I'd rather not have to link in any unnecessary libraries, but I can't find any info regarding which libraries are required for the IGES import routines.

Forum supervisor's picture

Hi Ben,

Here is a hint on finding the needed libraries:

1) Identify the name of the package a particular type is implemented in – it is the prefix in the type name that goes before ‘_’, like:

IGESControl_Reader => package IGESControl

XSControl_Reader => XSControl

2) Find this package in one of the files named ‘PACKAGES’ located in sub-folder of ‘src’ folder of OCCT installation.

To find the needed file, use standard ‘Find In Files’ dialog of MS Visual Studio, for example.

3) The name of the folder that contains the found file ‘PACKAGES’ gives you the name of the library to add.

In your case, you need to add: TKIGES, TKXSBase.

Best regards,

Forum supervisor

Ben Hollingsworth's picture

Thanks for the tip.  Unfortunately, there are lots of those packages (including TKIGES & TKXSBase) that did not create any libraries when I built using Automake.  What did I need to do differently during the build process to get those to build?  I ran:

./build_configure 

./configure --with-tcl=/usr/lib/sds2/tcltk85-for-sds2-2016/linux64-gcc46/lib --with-tk=/usr/lib/sds2/tcltk85-for-sds2-2016/linux32-gcc46/lib --with-freetype=/usr/lib/sds2/OpenDesign-for-sds2-2015/linux64-gcc46/lib --prefix=/home/bvh/src/oc-691

make

make install

And I ended up with only those libraries that are listed in my gcc command in my original post.

Ben Hollingsworth's picture

In my build directory, the directory 'adm/lin/amk/TKIGES' contains only .deps/ and a few Makefiles, but no *.lo files.  However, when I cd into that directory and run 'make', it builds the .lo files just fine.  Why weren't those built automatically like some of the other libraries were?

Forum supervisor's picture

Dear Ben,

I would like to inform you that after 'configure' with the specified arguments you must get the message like following:

3rdparty mandatory products      

---------------------------------

freetype      : yes

tcltk         : yes

3rdparty optional products      

---------------------------------

gl2ps         : no

freeimage     : no

tbb includes  : no

tbb libraries : no

opencl        : no

qt            : no (--with-qt=DIR option was not defined)

vtk           : no

Component                   Build

--------------------------  -----

FoundationClasses           yes

ModelingData                yes

ModelingAlgorithms          yes

Visualization               yes

ApplicationFramework        yes

DataExchange                yes

Draw                        yes

I.e. the configure step came to the end incorrectly. Something was not found. And part of libraries were  not built.

http://dev.opencascade.org/doc/overview/html/occt_dev_guides__building_automake.html

Libraries must be created in defined by --prefix folder after command: make install

Best regards

FSR

Ben Hollingsworth's picture

My configure command gives the following output near the middle, preceded by several hundred lines of "checking for" and followed by about 70 lines of creating Makefiles.  The Makefiles for all my missing libraries are generated.  However, when I run make, nothing is built in the 'adm/lin/amk/TKIGES' directory.  The TKIGES library will build just fine if I cd into 'adm/lin/amk/TKIGES' and run 'make' manually.  It just isn't getting built or installed by the top-level Makefile for some reason.

CC       = gcc
CXX      = g++
CFLAGS   =  -DCSFDB -DOCC_CONVERT_SIGNALS -DLIN -DLININTEL -fexceptions -mmmx -msse -msse2 -mfpmath=sse -Wall -O2
CXXFLAGS =  -DCSFDB -DOCC_CONVERT_SIGNALS -DLIN -DLININTEL -D_GNU_SOURCE=1 -mmmx -msse -msse2 -mfpmath=sse -Wall -O2
CPPFLAGS =  -DNDEBUG  -DNo_Exception
LDFLAGS  =  -lstdc++ -lrt

3rdparty mandatory products       
---------------------------------
freetype      : yes 
tcltk         : yes 

3rdparty optional products       
---------------------------------
gl2ps         : no (--with-gl2ps=DIR option was not defined)
freeimage     : no (--with-freeimage=DIR option was not defined)
tbb includes  : no (--with-tbb-include=DIR option was not defined)
tbb libraries : no (--with-tbb-library=DIR option was not defined)
opencl        : no 
qt            : no (--with-qt=DIR option was not defined)
vtk           : no 

Component                   Build
--------------------------  -----
FoundationClasses           yes 
ModelingData                yes 
ModelingAlgorithms          yes 
Visualization               no (VTK not found)
ApplicationFramework        no (Visualization component disabled)
DataExchange                no (ApplicationFramework component disabled)
Draw                        no (DataExchange component disabled)

Ben Hollingsworth's picture

Oh, I see what's happening.  Looking at the adm/lin/amk/Makfile.in file, I see that the TKIGES package is part of the DataExchange component, which is (indirectly) conditional on the VTK package, which is not installed.  I wasn't worried about it because it was listed as optional.  I guess I need to go get the VTK package.  It's curious that TKIGES was able to build just fine when I ran it manually.  I wonder if the Makefile requirements are more stringent than they really need to be.

jmieloszyk's picture

Use linker flags: -Wl,--start-group ... libraries ... -Wl,--end-group (linker will find dependencies between the libraries in the group, order of the libraries in that case is not important, linker processing takes longer but it works). I've put simple code in other post: https://www.opencascade.com/content/need-short-c-opencascade-example#comment-21565