How to compile OCC test example by cmake and gcc

Hello, everyone,
I have installed Opencascads 6.5.0 on my Ubuntu 12.04 LTS 64 bit system. My gcc version is 4.6.3. The opencascade header file is in /usr/include/opencascade/, and the libs is in /usr/lib/opencas/. I have the following test example, and I want to write a CMakeLists.txt file and use cmake tool to manage and compile it. But I am a new user of Opencascade and I am also not familiar with cmake tool. I am very appreciate for that someone can offer me such a CMakeLists.txt file as an example. Thanks very much!

Best

Huayi

#include
#include
#include
Standard_Integer main()
{
IGESControl_Reader myIgesReader;
Standard_Integer nIgesFaces,nTransFaces;
myIgesReader.ReadFile ("MyFile.igs");
//loads file MyFile.igs
Handle(TColStd_HSequenceOfTransient) myList =
myIgesReader.GiveList("iges-faces");
//selects all IGES faces in the file and puts them into a listcalled
//MyList,
nIgesFaces = myList->Length();
nTransFaces = myIgesReader.TransferList(myList);
//translates MyList,
cout TopoDS_Shape sh = myIgesReader.OneShape();
//and obtains the results in an Open CASCADE shape.
}

why's picture

In fact, I write a CMakeLists.txt by myself. But when I make it, it appear the following error:

/////////////////////////////

Linking CXX executable iges_reader
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `main':
iges_reader.cpp:(.text+0x17): undefined reference to `IGESControl_Reader::IGESControl_Reader()'
iges_reader.cpp:(.text+0x2b): undefined reference to `XSControl_Reader::ReadFile(char const*)'
iges_reader.cpp:(.text+0x48): undefined reference to `XSControl_Reader::GiveList(char const*, char const*)'
iges_reader.cpp:(.text+0x75): undefined reference to `XSControl_Reader::TransferList(Handle_TColStd_HSequenceOfTransient const&)'
iges_reader.cpp:(.text+0xd1): undefined reference to `XSControl_Reader::OneShape() const'
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `Handle_Standard_Transient::~Handle_Standard_Transient()':
iges_reader.cpp:(.text._ZN25Handle_Standard_TransientD2Ev[_ZN25Handle_Standard_TransientD5Ev]+0x14): undefined reference to `Handle_Standard_Transient::EndScope()'
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `TColStd_SequenceOfTransient::~TColStd_SequenceOfTransient()':
iges_reader.cpp:(.text._ZN27TColStd_SequenceOfTransientD2Ev[_ZN27TColStd_SequenceOfTransientD5Ev]+0x14): undefined reference to `TColStd_SequenceOfTransient::Clear()'
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `TopTools_SequenceOfShape::~TopTools_SequenceOfShape()':
iges_reader.cpp:(.text._ZN24TopTools_SequenceOfShapeD2Ev[_ZN24TopTools_SequenceOfShapeD5Ev]+0x14): undefined reference to `TopTools_SequenceOfShape::Clear()'
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `XSControl_Reader::operator delete(void*)':
iges_reader.cpp:(.text._ZN16XSControl_ReaderdlEPv[XSControl_Reader::operator delete(void*)]+0x1d): undefined reference to `Standard::Free(void*&)'
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `XSControl_Reader::~XSControl_Reader()':
iges_reader.cpp:(.text._ZN16XSControl_ReaderD2Ev[_ZN16XSControl_ReaderD5Ev]+0x14): undefined reference to `vtable for XSControl_Reader'
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `IGESControl_Reader::operator delete(void*)':
iges_reader.cpp:(.text._ZN18IGESControl_ReaderdlEPv[IGESControl_Reader::operator delete(void*)]+0x1d): undefined reference to `Standard::Free(void*&)'
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `TopLoc_SListOfItemLocation::~TopLoc_SListOfItemLocation()':
iges_reader.cpp:(.text._ZN26TopLoc_SListOfItemLocationD2Ev[_ZN26TopLoc_SListOfItemLocationD5Ev]+0x15): undefined reference to `TopLoc_SListOfItemLocation::Clear()'
CMakeFiles/iges_reader.dir/iges_reader.cpp.o: In function `IGESControl_Reader::~IGESControl_Reader()':
iges_reader.cpp:(.text._ZN18IGESControl_ReaderD2Ev[_ZN18IGESControl_ReaderD5Ev]+0x13): undefined reference to `vtable for IGESControl_Reader'
collect2: ld returned 1 exit status
make[2]: *** [iges_reader] Error 1
make[1]: *** [CMakeFiles/iges_reader.dir/all] Error 2
make: *** [all] Error 2
////////////////////////////////////

why's picture

Here is the cpp file.

Benjamin Bihler's picture

Hi,

the "undefined reference" error messages mean that you have to add some libraries to the link process. I wonder for example if you don't need the library libTKIGES.so which seems not to be included in your make file.

Probably you should start from a working sample that can read IGES files (like "tutorial" in the OCC samples folder) and then pick the code (and the libraries!) that you need.

Bye,
Benjamin