undefined reference to `STEPControl_Reader::STEPControl_Reader()

Hello,

I started working with OpenCascade just this days! I just tried simple program using eclipse compiler on Linux (Ubuntu).
Here is the program! I got an error undefined reference to 'STEPControl_reader::STEPControl_Reader()' Didn't understand the reason behind, Does any one have any solution or ideas! Any information helps!

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

int main () {

STEPControl_Reader reader;

IFSelect_ReturnStatus stat = reader.ReadFile("screw.stp");

}

Any will be appreciated here is the full error message:

*** Build of configuration Debug for project trial-2 ****

make all
Building file: ../src/trial-2.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/include/opencascade -I/usr/lib -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/trial-2.d" -MT"src/trial-2.d" -o"src/trial-2.o" "../src/trial-2.cpp"
../src/trial-2.cpp: In function ‘int main()’:
../src/trial-2.cpp:26: warning: unused variable ‘stat’
Finished building: ../src/trial-2.cpp

Building target: trial-2
Invoking: GCC C++ Linker
g++ -o"trial-2" ./src/trial-2.o
./src/trial-2.o: In function `main':
/home/de052/workspace/example/trial-2/Debug/../src/trial-2.cpp:24: undefined reference to `STEPControl_Reader::STEPControl_Reader()'
/home/de052/workspace/example/trial-2/Debug/../src/trial-2.cpp:26: undefined reference to `XSControl_Reader::ReadFile(char const*)'
./src/trial-2.o: In function `~Handle_Standard_Transient':
/usr/include/opencascade/Handle_Standard_Transient.hxx:71: undefined reference to `Handle_Standard_Transient::EndScope()'
./src/trial-2.o: In function `~TColStd_SequenceOfTransient':
/usr/include/opencascade/TColStd_SequenceOfTransient.hxx:76: undefined reference to `TColStd_SequenceOfTransient::Clear()'
./src/trial-2.o: In function `~TopTools_SequenceOfShape':
/usr/include/opencascade/TopTools_SequenceOfShape.hxx:73: undefined reference to `TopTools_SequenceOfShape::Clear()'
./src/trial-2.o: In function `XSControl_Reader::operator delete(void*)':
/usr/include/opencascade/XSControl_Reader.hxx:119: undefined reference to `Standard::Free(void*&)'
./src/trial-2.o: In function `~XSControl_Reader':
/usr/include/opencascade/XSControl_Reader.hxx:135: undefined reference to `vtable for XSControl_Reader'
./src/trial-2.o: In function `STEPControl_Reader::operator delete(void*)':
/usr/include/opencascade/STEPControl_Reader.hxx:100: undefined reference to `Standard::Free(void*&)'
./src/trial-2.o: In function `~STEPControl_Reader':
/usr/include/opencascade/STEPControl_Reader.hxx:86: undefined reference to `vtable for STEPControl_Reader'
collect2: ld returned 1 exit status
make: *** [trial-2] Error 1

Nicholas Fette's picture

> g++ -o"trial-2" ./src/trial-2.o
Looks like you didn't link to the OCCT libraries. Look at the samples provided with the OCCT source distribution; there should be arguments to the linker like:
-lTKStep (etc.)
May need to add environment variables like LD_LIBRARY_PATH as well.

Baba Ali's picture

You need to define OCC libraries to Eclipse. I mean shared object libraries (.so) or dylib (for mac) or dll (for windows).
To achieve that: You should find OCCT *.so files. It is usually under /usr/local/lib directory for linux. If there is not any so file related to OCC, you should compile OCCT again with this option " --enable-shared=yes ".
If you have .so files open eclipse project properties window, go to the GCC C++ Linker section and click on the Libraries tab. At the right-up of the window you should add the so file names without lib and .so extensions. (I mean instead of libTKXCAF.so, just type TKXCAF.)
At the right-bottom give the library path (usually /usr/local/lib/). If you want, you can copy the libraries in to your workspace and give the path in workspace.
As a last step, you should set the environment from properties window, Run Debug Settings. Select your executable click edit and go to environment tab. Click on new tab and give the LD_LIBRARY_PATH to your so files.
This is the same thing what Nicholas mentioned, just in Eclipse way.