Help Getting Started

Hello everyone,

Could someone offer some words of advice in regard to getting started with OpenCASCADE? I looked through some of the sample source code, but I don't really know where to begin.

I will be writing a console application that needs to be able to create and take the union of hundreds of thousands of primitives (say cubes), and then output the result as an .STL file. Will OpenCASCADE be able to handle that? That is, taking one cube, and taking its union with the next, then taking the union of the result with another cube, and the union of THAT result with another cube, and so on...

Where should I look to begin, so that I can create a simple cube, and output it as an .STL file?

Thanks,
Mike

Michael Cook's picture

Ok, sorry to reply to my own message so fast, but I just found Francois Lauzon's simple program a few posts down, guess I missed it before, but I implemented it and am still getting some errors. First things first, I implemented the program as such in MSVC .NET as follows:

#include
#include

int
main(int argc, char *argv[])
{
BRepPrimAPI_MakeBox aBox(1,2,5);
aBox.Build();

BRepTools::Dump(aBox.Shape(),std::cout);

return 0;
}

From this code I get the following list of errors, sorry its so long. Some of them appear to be that istream wasn't included in one of the OpenCASCADE headers. Anyways, can someone help me out?

c:\Documents and Settings\Michael Cook\My Documents\Visual Studio Projects\stlconverterfinal\src\stlconverter.cpp(20): error C2065: 'cout' : undeclared identifier
c:\Documents and Settings\Michael Cook\My Documents\Visual Studio Projects\stlconverterfinal\src\stlconverter.cpp(20): error C2653: 'std' : is not a class or namespace name
c:\OpenCASCADE5.2\ros\inc\BRepTools.hxx(117): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\BRepTools.hxx(118): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\BRepTools.hxx(119): error C2061: syntax error : identifier 'istream'
c:\OpenCASCADE5.2\ros\inc\Handle_Standard_Transient.hxx(92): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Handle_Standard_Transient.hxx(96): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Handle_Standard_Transient.hxx(203): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard.hxx(94): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard.hxx(96): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard.lxx(30): warning C4311: 'type cast' : pointer truncation from 'const Standard_Address' to 'long'
c:\OpenCASCADE5.2\ros\inc\Standard.lxx(30): warning C4312: 'type cast' : conversion from 'long' to 'Standard_Integer *' of greater size
c:\OpenCASCADE5.2\ros\inc\Standard.lxx(53): warning C4311: 'type cast' : pointer truncation from 'Standard_Address' to 'long'
c:\OpenCASCADE5.2\ros\inc\Standard.lxx(53): warning C4312: 'type cast' : conversion from 'long' to 'Standard_Address * ' of greater size
c:\OpenCASCADE5.2\ros\inc\Standard.lxx(54): warning C4311: 'type cast' : pointer truncation from 'Standard_Address' to 'long'
c:\OpenCASCADE5.2\ros\inc\Standard.lxx(54): warning C4312: 'type cast' : conversion from 'long' to 'Standard_Address' of greater size
c:\OpenCASCADE5.2\ros\inc\Standard_Address.hxx(47): warning C4311: 'type cast' : pointer truncation from 'const Standard_Address' to 'long'
c:\OpenCASCADE5.2\ros\inc\Standard_Allocate.lxx(10): warning C4311: 'type cast' : pointer truncation from 'Standard_Address' to 'long'
c:\OpenCASCADE5.2\ros\inc\Standard_Allocate.lxx(10): warning C4312: 'type cast' : conversion from 'long' to 'Standard_Integer *' of greater size
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.hxx(68): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.hxx(69): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.hxx(70): error C2333: 'Standard_Failure::operator`<<'' : error in function declaration; skipping function body
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.hxx(70): error C2805: binary 'operator <<' has too few parameters
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.lxx(9): error C2086: 'int ostream' : redefinition
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.lxx(9): error C2143: syntax error : missing ';' before '&'
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.lxx(9): error C2433: 'ostream' : 'inline' not permitted on data declarations
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.lxx(9): error C2501: 'ostream' : missing storage-class or type specifiers
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.lxx(9): error C3861: 'AStream': identifier not found, even with argument-dependent lookup
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.lxx(10): error C2059: syntax error : 'const'
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.lxx(11): error C2143: syntax error : missing ';' before '{'
c:\OpenCASCADE5.2\ros\inc\Standard_Failure.lxx(11): error C2447: '{' : missing function header (old-style formal list?)
c:\OpenCASCADE5.2\ros\inc\Standard_Integer.hxx(129): error C2065: 'INT_MIN' : undeclared identifier
c:\OpenCASCADE5.2\ros\inc\Standard_Integer.hxx(135): error C2065: 'INT_MAX' : undeclared identifier
c:\OpenCASCADE5.2\ros\inc\Standard_Integer.hxx(141): error C2065: 'CHAR_BIT' : undeclared identifier
c:\OpenCASCADE5.2\ros\inc\Standard_Real.hxx(162): error C3861: 'CHAR_BIT': identifier not found, even with argument-dependent lookup
c:\OpenCASCADE5.2\ros\inc\Standard_Real.hxx(315): error C3861: 'asinh': identifier not found, even with argument-dependent lookup
c:\OpenCASCADE5.2\ros\inc\Standard_SStream.hxx(36): error C2504: 'strstream' : base class undefined
c:\OpenCASCADE5.2\ros\inc\Standard_SStream.hxx(40): error C2059: syntax error : ')'
c:\OpenCASCADE5.2\ros\inc\Standard_SStream.hxx(40): error C2059: syntax error : ';'
c:\OpenCASCADE5.2\ros\inc\Standard_SStream.hxx(40): error C2143: syntax error : missing ')' before '&'
c:\OpenCASCADE5.2\ros\inc\Standard_SStream.hxx(40): error C2143: syntax error : missing ';' before '&'
c:\OpenCASCADE5.2\ros\inc\Standard_SStream.hxx(40): error C2238: unexpected token(s) preceding ';'
c:\OpenCASCADE5.2\ros\inc\Standard_SStream.hxx(40): error C2460: 'Standard_SStream::ostream' : uses 'Standard_SStream', which is being defined
c:\OpenCASCADE5.2\ros\inc\Standard_Storable.hxx(76): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Storable.hxx(121): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Storable.hxx(122): error C2065: 'S' : undeclared identifier
c:\OpenCASCADE5.2\ros\inc\Standard_Transient_proto.hxx(52): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(85): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(101): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(101): error C2535: 'void Standard_Type::ShallowDump(void) const' : member function already defined or declared
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(102): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(103): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(103): error C2333: 'Standard_Type::operator`<<'' : error in function declaration; skipping function body
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(103): error C2805: binary 'operator <<' has too few parameters
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(157): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(157): error C2084: function 'void ShallowDump(const Handle_Standard_Type &)' already has a body
c:\OpenCASCADE5.2\ros\inc\Standard_Type.hxx(158): error C3861: 'S': identifier not found, even with argument-dependent lookup
c:\OpenCASCADE5.2\ros\inc\Standard_Type.lxx(13): error C2143: syntax error : missing ';' before '&'
c:\OpenCASCADE5.2\ros\inc\Standard_Type.lxx(13): error C2501: 'ostream' : missing storage-class or type specifiers
c:\OpenCASCADE5.2\ros\inc\Standard_Type.lxx(14): error C2059: syntax error : 'const'
c:\OpenCASCADE5.2\ros\inc\Standard_Type.lxx(14): error C2065: 'AStream' : undeclared identifier
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(67): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(67): error C2143: syntax error : missing ';' before '&'
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(67): error C2501: 'TopAbs::Print' : missing storage-class or type specifiers
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(67): warning C4183: 'Print': missing return type; assumed to be a member function returning 'int'
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(68): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(68): error C2086: 'int TopAbs::ostream' : redefinition
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(68): error C2143: syntax error : missing ';' before '&'
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(68): error C2501: 'TopAbs::Print' : missing storage-class or type specifiers
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(68): warning C4183: 'Print': missing return type; assumed to be a member function returning 'int'
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(69): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(69): error C2086: 'int TopAbs::ostream' : redefinition
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(69): error C2143: syntax error : missing ';' before '&'
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(69): error C2501: 'TopAbs::Print' : missing storage-class or type specifiers
c:\OpenCASCADE5.2\ros\inc\TopAbs.hxx(69): warning C4183: 'Print': missing return type; assumed to be a member function returning 'int'
c:\OpenCASCADE5.2\ros\inc\TopLoc_Location.hxx(109): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\TopLoc_Location.hxx(149): error C2061: syntax error : identifier 'ostream'
c:\OpenCASCADE5.2\ros\inc\TopLoc_Location.hxx(150): error C3861: 'S': identifier not found, even with argument-dependent lookup

sas's picture

Hi Cook!
Just add WNT in preprocesser directory. Go into project settings and add there.By adding this all ur error will be gone.
let me know if u can get the output.

regards
Sas

Michael Cook's picture

Hi Sas,
I wasn't quite sure what you meant when you said to "add WNT in preprocessor directory". I am using Microsoft Visual C++ .NET on Windows XP SP2 to compile. I clicked on Project->(project name) properties->Configuration Properties->C/C++->Preprocessor, and in Preprocessor Definitions I added "WNT" as you suggested. After I added WNT, my Preprocessor Definitions look as follows:

WIN32;_DEBUG;_CONSOLE;WNT

I also tried just replacing WIN32 with WNT instead of adding on the end, but it didn't seem to change my results. When I did this the resulting Preprocessor Definitions looked like this:

WNT;_DEBUG;_CONSOLE

When I tried compiling with either of those, I was still met with many warnings. I won't post them all just yet since there were so many. But now I am having Linker problems. The linker errors are as follows:

stlconverterfinal fatal error LNK1120: 22 unresolved externals
stlconverterfinal error LNK2019: unresolved external symbol "public: void __thiscall TopTools_ListOfShape::Clear(void)" (?Clear@TopTools_ListOfShape@@QAEXXZ) referenced in function "public: __thiscall TopTools_ListOfShape::~TopTools_ListOfShape(void)" (??1TopTools_ListOfShape@@QAE@XZ)
stlconverterfinal error LNK2019: unresolved external symbol "public: void __thiscall TopLoc_SListOfItemLocation::Clear(void)" (?Clear@TopLoc_SListOfItemLocation@@QAEXXZ) referenced in function "public: __thiscall TopLoc_SListOfItemLocation::~TopLoc_SListOfItemLocation(void)" (??1TopLoc_SListOfItemLocation@@QAE@XZ)
stlconverterfinal error LNK2019: unresolved external symbol "public: void __thiscall Standard_Type::Print(class std::basic_ostream > &)const " (?Print@Standard_Type@@QBEXAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z) referenced in function "public: void __thiscall Standard_Type::operator<<(class std::basic_ostream > &)const " (??6Standard_Type@@QBEXAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z)
stlconverterfinal error LNK2019: unresolved external symbol "public: virtual void __thiscall Standard_Storable::Delete(void)" (?Delete@Standard_Storable@@UAEXXZ) referenced in function "public: virtual __thiscall Standard_Storable::~Standard_Storable(void)" (??1Standard_Storable@@UAE@XZ)
stlconverterfinal error LNK2019: unresolved external symbol "public: virtual void __thiscall BRepBuilderAPI_MakeShape::Delete(void)" (?Delete@BRepBuilderAPI_MakeShape@@UAEXXZ) referenced in function "public: virtual __thiscall BRepBuilderAPI_MakeShape::~BRepBuilderAPI_MakeShape(void)" (??1BRepBuilderAPI_MakeShape@@UAE@XZ)
stlconverterfinal error LNK2019: unresolved external symbol "public: virtual void __thiscall BRepBuilderAPI_Command::Delete(void)" (?Delete@BRepBuilderAPI_Command@@UAEXXZ) referenced in function "public: virtual __thiscall BRepBuilderAPI_Command::~BRepBuilderAPI_Command(void)" (??1BRepBuilderAPI_Command@@UAE@XZ)
stlconverterfinal error LNK2019: unresolved external symbol "public: static void __cdecl Standard::MFree(void * &)" (?MFree@Standard@@SAXAAPAX@Z) referenced in function "public: static void __cdecl Standard::Free(void * &)" (?Free@Standard@@SAXAAPAX@Z)
stlconverterfinal error LNK2019: unresolved external symbol "public: static void * __cdecl Standard::RReallocate(void * &,int,int)" (?RReallocate@Standard@@SAPAXAAPAXHH@Z) referenced in function "public: static void * __cdecl Standard::Reallocate(void * &,int)" (?Reallocate@Standard@@SAPAXAAPAXH@Z)
stlconverterfinal error LNK2019: unresolved external symbol "public: static void * __cdecl Standard::MReallocate(void * &,int)" (?MReallocate@Standard@@SAPAXAAPAXH@Z) referenced in function "public: static void * __cdecl Standard::Reallocate(void * &,int)" (?Reallocate@Standard@@SAPAXAAPAXH@Z)
stlconverterfinal error LNK2019: unresolved external symbol "public: static void * __cdecl Standard::MAllocate(int)" (?MAllocate@Standard@@SAPAXH@Z) referenced in function "public: static void * __cdecl Standard::Allocate(int)" (?Allocate@Standard@@SAPAXH@Z)
stlconverterfinal error LNK2019: unresolved external symbol "public: __thiscall Handle_TopoDS_TShape::~Handle_TopoDS_TShape(void)" (??1Handle_TopoDS_TShape@@QAE@XZ) referenced in function "public: __thiscall TopoDS_Shape::~TopoDS_Shape(void)" (??1TopoDS_Shape@@QAE@XZ)
stlconverterfinal error LNK2019: unresolved external symbol "public: __thiscall Handle_TopLoc_SListNodeOfSListOfItemLocation::~Handle_TopLoc_SListNodeOfSListOfItemLocation(void)" (??1Handle_TopLoc_SListNodeOfSListOfItemLocation@@QAE@XZ) referenced in function "public: __thiscall TopLoc_SListOfItemLocation::~TopLoc_SListOfItemLocation(void)" (??1TopLoc_SListOfItemLocation@@QAE@XZ)
stlconverterfinal error LNK2001: unresolved external symbol "public: virtual void __thiscall Standard_Storable::ShallowDump(class std::basic_ostream > &)const " (?ShallowDump@Standard_Storable@@UBEXAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@Z)
stlconverterfinal error LNK2001: unresolved external symbol "public: virtual void __thiscall BRepBuilderAPI_MakeShape::Build(void)" (?Build@BRepBuilderAPI_MakeShape@@UAEXXZ)
stlconverterfinal error LNK2001: unresolved external symbol "public: virtual unsigned int __thiscall BRepBuilderAPI_MakeShape::IsDeleted(class TopoDS_Shape const &)" (?IsDeleted@BRepBuilderAPI_MakeShape@@UAEIABVTopoDS_Shape@@@Z)
stlconverterfinal error LNK2001: unresolved external symbol "public: virtual unsigned int __thiscall BRepBuilderAPI_Command::IsDone(void)const " (?IsDone@BRepBuilderAPI_Command@@UBEIXZ)
stlconverterfinal error LNK2001: unresolved external symbol "public: virtual int __thiscall Standard_Storable::HashCode(int)const " (?HashCode@Standard_Storable@@UBEHH@Z)
stlconverterfinal error LNK2001: unresolved external symbol "public: virtual class TopTools_ListOfShape const & __thiscall BRepBuilderAPI_MakeShape::Modified(class TopoDS_Shape const &)" (?Modified@BRepBuilderAPI_MakeShape@@UAEABVTopTools_ListOfShape@@ABVTopoDS_Shape@@@Z)
stlconverterfinal error LNK2001: unresolved external symbol "public: virtual class TopTools_ListOfShape const & __thiscall BRepBuilderAPI_MakeShape::Generated(class TopoDS_Shape const &)" (?Generated@BRepBuilderAPI_MakeShape@@UAEABVTopTools_ListOfShape@@ABVTopoDS_Shape@@@Z)
stlconverterfinal error LNK2001: unresolved external symbol "__declspec(dllimport) void * * theFreeList" (__imp_?theFreeList@@3PAPAXA)
stlconverterfinal error LNK2001: unresolved external symbol "__declspec(dllimport) unsigned int MMgt_Opt" (__imp_?MMgt_Opt@@3IA)
stlconverterfinal error LNK2001: unresolved external symbol "__declspec(dllimport) int theFreeListSize" (__imp_?theFreeListSize@@3HA)

Have any ideas? Thanks for helping,
Mike

Patrik Mueller's picture

Hi Mike,

you have to link the needed OCC libs.

Greets,

Patrik

Michael Cook's picture

Hey Patrik,

I had already added the win32\lib directory to my VC++ Libraries directories, but I am not sure which libs to add. There are a LOT of .lib files in the lib directory. Is there some way to reference which libraries to link using the documentation?

I'm currently including two header files, BRepTools.hxx and BRepPrimAPI_MakeBox.hxx. I tried pulling up the techinical documentation and search for each header. I found them, but there weren't any notes in regard to which libraries I need to include.

I would like to get better working with the technical documentation so that I don't need to ask the community for simple problems like this.

Thanks,
Mike

Michael Cook's picture

Hey I ended up just linking all of the libraries from one of the examples, even though there we like 20. But Sas, I noticed earlier that you said you were getting the error where it would print "Shape:" and then just crash. I am having that exact same problem now, and I was wondering if you had resolved it yet?

sas's picture

Sorry, i am still working on that. no clues. if u find any solution, let me know

cale zeune's picture

How do you link in the libraries? is it an explicit, programmatic command? which example file did you use?

Any progress on the :shape -> crash! issue? i guess it is pretty much a show stopper then?

thanks,
cale

Michael Cook's picture

Hey Cale,

What program are you coding in?

Mike

cale zeune's picture

I have been using the compiler from the Microsoft Visual C Toolkit 2003 that is freely download-able. For i while I was just using it from the command line. I thought i had properly associated the required directories (lib and bin and include) in the INCLUDE and LIB path; is this all you need to do, or do you need to specify the actual .lib files ? (i'm relatively new to C++ and hope i haven't overlooked something that is very basic.)

Recently, I've moved to using the Code::Blocks IDE (www.codeblocks.org) with the MSVCToolkit compiler. I've used the GUI to set the include and lib and bin directories, but still am having linking problems. apparently you can use MS visual studio project and workspace files inside of Code::Blocks; i have yet to try the project files included in the OCC tutorial and samples directory. maybe that will work; i'll try it on monday.

any ideas would be appreciated. thanks a lot for the reply.

cale

Michael Cook's picture

Cale,

You do need to specify the actual .lib files. To get my projects working I usually need to include between 15 and 25 .lib files. I haven't really come up with a good way to know which .lib files need to be included yet as I am not a very experienced programmer either.

I usually just find one of the MFC examples included in the OCC download and copy this list of .lib files that they linked. Once I've copied them over I try and compile, if it works then I usually go back through and remove libraries that the source will compile without. Unfortunately I do this in a very trial and error manner. If someone else has a better suggestion or could offer up some coding wisdom it would probably be very helpful for both Cale and I.

So that is my advice, just try and mimic the examples included with the OCC download. Things should work once you get the right .lib files included. If you're still having problems after messing with the .lib files again let me know and I'll try and help some more.

Mike

cale zeune's picture

I finally did get it to work, once i learned how to properly engage the linker from the command line. it ended up being very simple, but it took me a while to hunt down the documentation from the msdn library. and i ended up just including all of the lib files instead of picking through them. it's kind of annoying having to do that. anyway, thanks for all of your help.

cale

taxidriver's picture

Hello Cale !

how you do it, can you explain it in detail?, plz...

taxi

taxidriver's picture

Hello Cale !

how you do it, can you explain it in detail?, plz...

taxi

cale zeune's picture

make sure you have all of the appropriate .h files included in the top of the .cpp file you're working on. (you might have to add to the INCLUDE environmental variable on your machine). getting it to compile is the first step. make sure you have a main() function in the test file you are compiling. then run the command (in the microsoft toolkit compiler):
C:\...>cl /DWNT /EHsc /c MakeBottle.cxx

you have to DEFINE WNT to get OCC to compile properly. the /EHsc disables warnings and the /c compiles it without linking. if it compiles properly you should get a MakeBottle.obj file. from there, try linking, using the following command:
C:\...>link *.obj "C:\Program Files\OpenCASCADE\OCC5.2\ros\win32\lib\*.lib"
this links the makebottle.obj file with the other libs needed, which reside in the OCC provided directory.

hope that helps,
cale

Farsbarn's picture

Im no programmer but C2061: syntax error : identifier 'ostream'
seems repeating. try to see if there is a spelling error in #include

Prakash Manandhar's picture

adding
#include

in StandardReal.hxx

worked for me.