Smile in Visual C++ Windows Forms Application

The engine.
Kasiak
Posts: 13
Joined: Tue Jul 28, 2009 8:43 am

Smile in Visual C++ Windows Forms Application

Post by Kasiak »

I work with Microsoft Visual C++ 2005 with Service Pack 1. I created two projects:
1.Console Application
2.Windows Forms Application
I downloaded SMILE C++ for VC 8.0 SP1. In both projects I included “smile.h” and changed the projects properties: additional linker input ( I did not add smile.lib) and preprocessor definition. I also set "Multi-threaded Debug DLL" in "Runtime Library" under "C/C++ / Code Generation”.

I tested the code from SMILE tutorials. In the Console Application it works. but in the Windows Forms Application it doesn't - 291 errors, for example: error LNK2028: unresolved token, error LNK2019: unresolved external symbol.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Smile in Visual C++ Windows Forms Application

Post by shooltz[BayesFusion] »

Windows Forms is .NET; the library you've downloaded is for native C++. If you can stick with WinForms, then Smile.NET is the way to go.
Kasiak
Posts: 13
Joined: Tue Jul 28, 2009 8:43 am

Post by Kasiak »

Thanks, but now I don't now how to use SMILENET.

I downloaded smilenet.dll and added reference to the smilenet.dll file in my project (Project ->Properties->Add New Reference->Browse...).
Still program doesn't work - it doesn't see any of smile objects, for example:
error C2065: 'DSL_network' : undeclared identifier

Do I need the source code? How to use it? Please give me more details.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

DSL_network is the name of native C++ class, from our core C++ library. Smile.NET is a.NET wrapper and has different semantics - see the docs here:

http://genie.sis.pitt.edu/wiki/JSMILE_and_Smile.NET
Kasiak
Posts: 13
Joined: Tue Jul 28, 2009 8:43 am

Post by Kasiak »

I worked with Builder C++ before so I don't know Visual well. I implemented the version of tic-tac-toe game. All my algorithms are in C++ and they work properly in Visual C++ Windows Form Application . I have to use the Bayesian network during the game (I have to ask the net about the strategy). All examples in the tutorial are in C# or Java or VB.NET. I don't know what to do...
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

Kasiak wrote:I have to use the Bayesian network during the game (I have to ask the net about the strategy). All examples in the tutorial are in C# or Java or VB.NET. I don't know what to do...
You have three options at this point:

1) go with native C++ code; no Windows Forms for GUI development - use MFC or Win32 API instead

2) continue with .NET: use Smile.NET with C++/CLI, C# or VB.NET

3) create mixed-mode program with C++/CLI and C++ SMILE. This approach requires some workarounds, as described here: http://bytes.com/groups/net-vc/642179-c ... letons-cra

You'll need to change some project config settings if you want to continue with option 3 above:
a) at 'General' property page: change the 'Common Language Runtime support' from /clr:pure to /clr
b) at 'Linker/Advanced': change the 'Entry point' option to

Code: Select all

?mainCRTStartupStrArray@@$$FYMHP$01AP$AAVString@System@@@Z
Note that these are per-configuration settings, so you have to do that twice - for Debug and Release builds.
Kasiak
Posts: 13
Joined: Tue Jul 28, 2009 8:43 am

Post by Kasiak »

I prefer option 3, but when I change the project properties (without using smile for now):

DEBUG:
1>------ Build started: Project: TTT, Configuration: Debug Win32 ------
1>Linking...
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ) already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: virtual char const * __thiscall std::exception::what(void)const " (?what@exception@std@@UBEPBDXZ) already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : error LNK2001: unresolved external symbol "?mainCRTStartupStrArray@@$$FYMHP$01AP$AAVString@S ystem@@@Z" (?mainCRTStartupStrArray@@$$FYMHP$01AP$AAVString@S ystem@@@Z)
1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\nuk\Moje dokumenty\Visual Studio 2005\Projects\TTT\Debug\TTT.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\nuk\Moje dokumenty\Visual Studio 2005\Projects\TTT\TTT\Debug\BuildLog.htm"
1>TTT - 13 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

RELEASE:
1>------ Build started: Project: TTT, Configuration: Release Win32 ------
1>Compiling...
1>cl : Command line error D8016 : '/MTd' and '/clr' command-line options are incompatible
1>Build log was saved at "file://c:\Documents and Settings\nuk\Moje dokumenty\Visual Studio 2005\Projects\TTT\TTT\Release\BuildLog.htm"
1>TTT - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

Kasiak wrote:I prefer option 3, but when I change the project properties (without using smile for now):
You need to select 'Multithread Debug DLL" as "Runtime Library" in C++/Code Generation settings.
Kasiak
Posts: 13
Joined: Tue Jul 28, 2009 8:43 am

Post by Kasiak »

Almost all of these errors appeared after I changed /cls:pure to /clr.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

Kasiak wrote:Almost all of these errors appeared after I changed /cls:pure to /clr.
/clr (without :pure or :safe) is required if you want to mix native code into your .NET app; as described in step 3a in my post above.
Kasiak
Posts: 13
Joined: Tue Jul 28, 2009 8:43 am

Post by Kasiak »

I have "Multi-threaded Debug DLL (/MDd)" in Code Generation.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

Kasiak wrote:I have "Multi-threaded Debug DLL (/MDd)" in Code Generation.
The compiler clearly thinks otherwise - /MTd is Multithreaded Debug (static, non-DLL version).
1>cl : Command line error D8016 : '/MTd' and '/clr' command-line options are incompatible
Do you have any libraries specified as 'Additional dependencies' at Linker/Input?
Kasiak
Posts: 13
Joined: Tue Jul 28, 2009 8:43 am

Post by Kasiak »

I realized that I didn't changed Code Generation in release build before.
It is strange, now the "release" works properly, but "debug" still has the same errors.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

Kasiak wrote:I realized that I didn't changed Code Generation in release build before.
It is strange, now the "release" works properly, but "debug" still has the same errors.
Both debug and release should have /clr without 'pure' or 'safe' and appropriate dynamic C++ runtime. It's 'Multithreaded DLL (/MD)' for release build and 'Multithreaded Debug DLL (/MDd)' for debug configuration. Don't forget to set the entrypoint at Linker/Advanced for both builds.
Kasiak
Posts: 13
Joined: Tue Jul 28, 2009 8:43 am

Post by Kasiak »

Thank you very much :)
I had some smile libraries in Additional dependencies in debug build (I forget about it), when I remove them it works.
But now can I use smile without libraries?
Post Reply