PDA

View Full Version : API: compiling a simple project in VC++ (32bit)


efecto
02-08-2011, 03:10 AM
Hi there.

I'm trying to compile a simple project for Maya 32bit. I can compile the project with no errors what so ever, and I can load the new plugin .mll fine.

But when trying to run a new function as described in the description I get nothing..

helloWorld;
// prints nothing..

I'm wondering if the warnings printed below may be causing it..

1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(C:\Program Files (x86)\Autodesk\Maya2011\devkit\plug-ins\Win32\Debug\helloWorldCmd.dll) does not match the Linker's OutputFile property value (C:\Program Files (x86)\Autodesk\Maya2011\devkit\plug-ins\helloWorldCmd.mll). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile). 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(991,5): warning MSB8012: TargetExt(.dll) does not match the Linker's OutputFile property value (.mll). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile). 1> Creating library .\Debug/helloWorldCmd.lib and object .\Debug/helloWorldCmd.exp 1> Creating library .\Debug/helloWorldCmd.lib and object .\Debug/helloWorldCmd.exp 1> helloWorldCmd.vcxproj -> C:\Program Files (x86)\Autodesk\Maya2011\devkit\plug-ins\Win32\Debug\helloWorldCmd.dll ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Could someone help me on this?

Thank you.

efecto
02-08-2011, 08:52 AM
here is the settings I have.

http://img146.imageshack.us/img146/1334/debugr.jpg

Robert Bateman
02-08-2011, 09:42 AM
If it compiles, you can load the plugin without errors, and you can run the command, it has worked fine. How are you printing text? Are you using MGobal::displayInformation or std::cout? The former will appear in the script editor, the latter will appear in the output window....

p.s. This warning can be safely ignored. It's just telling you that the output directory is set to some value (eg C:/foo) but your output dll is explicitly set to a different path (eg, C:/foo/bin/myPlugin.mll). It's just telling you that "C:/foo" and "C:/foo/bin" are different. Nothing to actually worry about in this case.....

efecto
02-08-2011, 03:21 PM
Thanks Rob.

Checked in the output window but nothing is displayed when I run a command.

helloWorld;

#include <maya/MIOStream.h>
#include <maya/MSimple.h>

// Use a Maya macro to setup a simple helloWorld class
// with methods for initialization, etc.
//
DeclareSimpleCommand( helloWorld, "TEST", "2011");

// All we need to do is supply the doIt method
// which in this case is only a Hello World example
//
MStatus helloWorld::doIt( const MArgList& )
{
cout<<"Hello World"<<endl;
return MS::kSuccess;
}

Robert Bateman
02-08-2011, 03:34 PM
Uh. Never ever ever ever ever use maya/MIostream.h !! I hope you have defined REQUIRE_IOSTREAM in there somewhere as well? (which might actually be your problem in this case). But anyhow, your best bet is to avoid all use of std::cout/std::cin/std::cerr in a plug-in in favour of MGlobal....

But yeah, it should be printing to the output window? Not sure why it isn't (Obviously I do *not* mean the script editor output!)

#include <maya/MGlobal.h>
#include <maya/MSimple.h>

// Use a Maya macro to setup a simple helloWorld class
// with methods for initialization, etc.
//
DeclareSimpleCommand( helloWorld, PLUGIN_COMPANY, "4.5");

// All we need to do is supply the doIt method
// which in this case is only a Hello World example
//
MStatus helloWorld::doIt( const MArgList& )
{
MGlobal::displayInfo("Hello");
return MS::kSuccess;
}

Should now be printing into the script editor output instead of the output window.

I must say though, stop writing commands and start writing nodes instead. As my sig says, if you are using MPxCommand, you are doing it wrong!

efecto
02-08-2011, 03:35 PM
okay so i tried MGlobal::displayInfo and it finally printed something.

//cout<<"Hello World"<<endl;
MGlobal::displayInfo("hi world!");

why is this not printing anything..?
cout<<"Hello World"<<endl;

Robert Bateman
02-08-2011, 03:36 PM
okay so i tried MGlobal::displayInfo and it finally printed something.

//cout<<"Hello World"<<endl;
MGlobal::displayInfo("hi world!");

why is this not printing anything..?
cout<<"Hello World"<<endl;

It does. It prints to the output window (or command line if you started maya from the shell)

i.e.

mental ray for Maya 2010
mental ray: version 3.7.53.5, Jun 17 2009, revision 88216
hi world!

Although if you haven't defined REQUIRE_IOSTREAM MIOstream will fall back to <iostream.h> instead of <iostream>, which may be the reason?

efecto
02-08-2011, 03:55 PM
mental ray for Maya 2010
mental ray: version 3.7.53.5, Jun 17 2009, revision 88216
hi world!


Interesting. I never saw output like you are seeing. I only see below whenever i run the command.
mental ray for Maya 2011
mental ray: version 3.7.53.5, Jun 17 2009, revision 88216


Although if you haven't defined REQUIRE_IOSTREAM MIOstream will fall back to <iostream.h> instead of <iostream>, which may be the reason?

May I take a look at your code? I would like to listen to you regarding using MPxCommand but I really want to get this helloWorld thing to work as it should.

efecto
02-08-2011, 03:57 PM
here is what I have, which doesn't print in output.

using namespace std;
#define REQUIRE_IOSTREAM
#include <maya/MSimple.h>
//#include <maya/MGlobal.h>

DeclareSimpleCommand( helloWorld, "TEST", "2011");

MStatus helloWorld::doIt( const MArgList& )
{
cout<<"Hello World"<<endl;
//MGlobal::displayInfo("hi world!");
return MS::kSuccess;
}

Robert Bateman
02-08-2011, 04:09 PM
C++ Rule #1: Never put "using namespace std" in a header file!
C++ Rule #2: If you use "using namespace" (which is always a bad idea), ensure you only ever do so in a *.cpp file AFTER all of the include directives. NEVER before the includes!


#define REQUIRE_IOSTREAM
#include <iostream>
#include <maya/MSimple.h>

// Use a Maya macro to setup a simple helloWorld class
// with methods for initialization, etc.
//
DeclareSimpleCommand( helloWorld, PLUGIN_COMPANY, "4.5");

// All we need to do is supply the doIt method
// which in this case is only a Hello World example
//
MStatus helloWorld::doIt( const MArgList& )
{
std::cout << "Hello" << std::endl;
return MS::kSuccess;
}


That code does print to the output window I can assure you.

efecto
02-08-2011, 04:19 PM
thanks for all these tips Rob. they are very gd to know :)

With your source code, I'm still not seeing output in the output window.. I'm starting to think it may be because im using windows 7..?

Robert Bateman
02-08-2011, 04:32 PM
With your source code, I'm still not seeing output in the output window.. I'm starting to think it may be because im using windows 7..?

When you start maya there should be two windows that appear. The first is maya. The second is the output window. This only ever appears when you direct output to std::cout or std::cerr (i.e. when you start maya, mental ray dumps some crap into std::cout, hence the window appears with the mental ray text in).

If this isn't happening I can only guess as to why. It certainly used to work on Maya 7 back in the day. It might have something to do with you using a newer version of Visual C++ maybe, or possibly a windows7 thing? It certainly isn't anything to do with the code or the output window in maya 7.

efecto
02-08-2011, 07:48 PM
Rob, thanks for all your help.

In this thread, I have been compiling in 32bit for maya 32bit. The reason is that I have been trying to compile in 64bit, and tried everything many people suggestedb ut couldn't get it to work.

Going to 32bit is easier indeed to get compiling going :)

efecto
02-08-2011, 07:56 PM
I have another question.

Do I need to be using VC++ express 2010 to compile for maya 2011 or can I use VC++ 2005 as well? or VC++ 2008??

cheers

Robert Bateman
02-09-2011, 10:37 AM
Do I need to be using VC++ express 2010 to compile for maya 2011 or can I use VC++ 2005 as well? or VC++ 2008??


You should be able to use any of them without any problems.

efecto
02-09-2011, 06:26 PM
Great to know thanks!

CGTalk Moderation
02-09-2011, 06:26 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.